fix: Rebuilt SExI after Tim's mince pie incident — tables, queries & tests included#81
Open
ranjithharidas1 wants to merge 14 commits into
Open
fix: Rebuilt SExI after Tim's mince pie incident — tables, queries & tests included#81ranjithharidas1 wants to merge 14 commits into
ranjithharidas1 wants to merge 14 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Complete rebuild of the SExI (Silverbullet Expenses and Invoices) system using Trino-compatible SQL against the memory.default catalogue.
What's included
Data loading scripts (idempotent — safe to re-run via DROP TABLE IF EXISTS):
create_employees.sql — 9 employees from hr/employee_index.csv
create_expenses.sql — 7 expense items from finance/receipts_from_last_night/
create_invoices.sql — SUPPLIER (5 rows, alphabetically assigned IDs) + INVOICE (6 rows, dynamic due dates)
Analytical queries:
find_manager_cycles.sql — Recursive CTE detecting the approval cycle: 1 → 4 → 2 → 1. Outputs both employee_id and the full cycle path as specified.
calculate_largest_expensors.sql — Identifies Alex Jacobson (1,682.00) as the only employee exceeding the 1,000 threshold.
generate_supplier_payment_plans.sql — Monthly payment schedule with uniform instalments per invoice, rounding adjustment on final payment, and running balance calculation via window functions. Verified against the Catering Plus example in the README.
Data validation tests (bonus task):
data_tests.sql — 17 test queries covering row counts, referential integrity, data quality (positive amounts, last-day-of-month validation), and correctness of analytical outputs.
Design decisions
Idempotent scripts: All CREATE scripts use DROP TABLE IF EXISTS so they can be re-run without restarting the Trino container.
Dynamic dates: Invoice due dates and payment schedules are computed relative to current_date, not hardcoded.
Rounding: Final payment instalment absorbs any rounding remainder to ensure balances close to exactly 0.00.
Intentional typo preserved: invoice_ammount matches the column name in the task specification.
Comments throughout: Every file includes header documentation, source data mappings, and inline explanations for non-obvious logic.
Execution order