Skip to content

fix: Rebuilt SExI after Tim's mince pie incident — tables, queries & tests included#81

Open
ranjithharidas1 wants to merge 14 commits into
sbms4d:mainfrom
ranjithharidas1:solution_ranjith
Open

fix: Rebuilt SExI after Tim's mince pie incident — tables, queries & tests included#81
ranjithharidas1 wants to merge 14 commits into
sbms4d:mainfrom
ranjithharidas1:solution_ranjith

Conversation

@ranjithharidas1

@ranjithharidas1 ranjithharidas1 commented Jun 22, 2026

Copy link
Copy Markdown

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

  1. create_employees.sql
  2. create_expenses.sql
  3. create_invoices.sql
  4. find_manager_cycles.sql
  5. calculate_largest_expensors.sql
  6. generate_supplier_payment_plans.sql
  7. data_tests.sql (validation)

@ranjithharidas1 ranjithharidas1 changed the title feat: Rebuild SExI database — tables, analytics, payment plans fix: Rebuilt SExI after Tim's mince pie incident — tables, queries & tests included Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant