Skip to content

fix(workflow): correct Aggregate, Deduplicate, Redact and SQL values - #657

Open
huyplb wants to merge 1 commit into
mainfrom
fix/workflow-etl-correctness
Open

huyplb wants to merge 1 commit into
mainfrom
fix/workflow-etl-correctness

Conversation

@huyplb

@huyplb huyplb commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

I ran real ETL and migration workflows through the engine against the dev Postgres 16 and MySQL 8.4 containers: a 2,500-row table copied Postgres → MySQL → Postgres, then Aggregate, Deduplicate and Redact over it. Four problems changed or lost data while the run still reported succeeded:

Before After
Aggregate by region (3 regions, batch size 1,000) 9 partial rows; max(amount) = 997.4760 (true max 12345678901235.8023); sums like 461188.2134999999 3 rows, identical to Postgres's GROUP BY
Deduplicate on region 9 rows kept 3 rows
Postgres → MySQL → Postgres copy .123456 → .123; bigint 9007199254740995 → …996; 03:04 UTC stored as 20:04 (the engine host's local time) 0 of 2,500 rows differ on any column
Redact contact.email left unmasked masked

What changed

  • Whole-input transforms. TransformPipe gains an optional session(context) with push(batch) / end() (registry/pipes.ts).
    • The executor opens one session per pipe per pipeline execution and pushes every inbound batch through it. It calls end after the sources finish, in topological order, so a session's output reaches any session below it before that one ends.
    • A re-executed pipeline gets a fresh session.
    • transform() still answers a single batch, for previews.
    • The dry-run wrapper passes sessions through.
  • Aggregate keeps running totals only, so memory grows with the number of groups, not rows. Decimal sums are exact (exact-number.ts): a sum is a number when one holds it exactly, otherwise the exact digits. Min and max compare numbers numerically.
  • Deduplicate keep: first hands records on immediately. keep: last holds one record per key until the input ends; superseded records go to rejects right away.
  • SQL query / SQL write read through faithfulQuery, which sets driver options per query and never changes a driver's global parsers. Nothing changes in the db submodule.
    • Postgres (and Redshift, CockroachDB, YugabyteDB) dates and timestamps, and MySQL DATE / DATETIME / TIMESTAMP, become SqlTemporal values (temporal-values.ts). Each is still a Date to other drivers, templates and scripts, and also carries the exact text the database sent.
    • Postgres gets that text back unchanged.
    • MySQL gets instants in UTC, and dates and zoneless timestamps as their wall-clock text.
    • MySQL uses supportBigNumbers, so a BIGINT past 2^53 is read as a string.
    • A first attempt that passed Postgres's text straight through was rejected by MySQL ('…+00'). It would also have broken dates going into Oracle and SQL Server, hence the Date subclass.
  • Redact PII accepts dot paths (contact.email); a key that itself contains a dot wins over the path. Objects are hashed and masked from their JSON instead of from [object Object].
  • Docs: docs/guides/workflow.md (and its palette names, which didn't match), docs/releases/UNRELEASED.md.

Behaviour changes

  • Writing to SQL Server, Oracle and the other databases still gets millisecond precision, as before.
  • A zoneless MySQL timestamp written to a Postgres timestamptz is now read in Postgres's own session time zone, where before it used the engine host's.

Tests

  • New: whole-input-transforms.test.ts (runs through PipelineExecutor with a batched source) and sql-driver-values.test.ts.
  • 7 of the 10 transform tests fail on main; the other three cover the new number helpers and behaviour main already had.
  • npm run verify here: typecheck, unit, lint, build and deps-scan pass.
  • npm audit signatures fails locally on the known tinybench attestation registry error. CI's audit job passes on main, and both vulnerability audits found 0.
  • Gitleaks isn't installed locally.
  • The live round trip ran before a lint-driven rewrite of the timestamp parser (to avoid a regex lint flagged as slow); the unit tests cover the rewritten parser.

Not in this PR (found in the same review)

  • SQL write's "Create table if missing" checkbox is ignored by the engine.
  • On Postgres, SQL write adds created_at and missing columns to existing tables.
  • Upsert works on Postgres/SQLite only.
  • JSON and array columns fail on MySQL.
  • SQL query loads the whole result into memory before batching.

🤖 Generated with Claude Code


Note

High Risk
Touches core pipeline execution, cross-database SQL read/write semantics, and transform output timing—bugs could silently corrupt migrations/aggregations while runs still succeed.

Overview
Fixes workflow transforms and SQL pipes that reported succeeded but produced wrong data on batched ETL (e.g. 2,500-row Postgres ↔ MySQL migrations).

Whole-input transforms. TransformPipe gains optional TransformSession (push / end). The executor routes every inbound batch through one session per pipe, then calls end in pipeline order after sources finish; dry-run records session output the same way. Aggregate and Deduplicate use this so grouping and dedupe span all SQL batches (not per 1,000-row chunk). Aggregate keeps running totals per group with exact decimal sums and numeric min/max (exact-number.ts). Dedupe keep: first streams; keep: last emits at end.

SQL fidelity. SQL query/write paths use faithfulQuery with per-query Postgres/MySQL options (no global parser changes). Dates/timestamps become SqlTemporal (still a Date elsewhere) preserving DB text; MySQL gets UTC instants, supportBigNumbers for BIGINT past 2^53.

Redact PII. Dot paths (contact.email), literal keys with dots win, objects hashed via JSON not [object Object].

Docs updated in workflow.md and UNRELEASED.md; new integration tests (whole-input-transforms.test.ts, sql-driver-values.test.ts).

Reviewed by Cursor Bugbot for commit fb2efe5. Bugbot is set up for automated code reviews on this repo. Configure here.

Found running a 2,500-row PostgreSQL <-> MySQL migration through the
engine; each finished `succeeded` with wrong data.

- Aggregate and Deduplicate answered per batch, so 1,000-row batches
  gave three partial rows per group and kept duplicates across batches.
  Transforms can now opt in to a session the executor ends after the
  sources finish, in pipeline order (also wired through dry runs).
- Aggregate sums decimals exactly and compares min/max numerically;
  `numeric` arrives as text and was ranked and summed as text/floats.
- SQL query/write read with per-query driver options: dates and
  timestamps keep their exact text as SqlTemporal values (still a Date
  to other drivers), MySQL gets instants in UTC rather than host local
  time, and MySQL BIGINT past 2^53 is read as a string.
- Redact PII reaches dot paths and hashes objects by content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cursor

cursor Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 102a69c5-7461-4ee2-b308-80f0f43dfd01)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant