Skip to content

Fix WITH using a CSV source to close #1276 - #2557

Open
harsh-thakkar7 wants to merge 1 commit into
AlaSQL:developfrom
harsh-thakkar7:fix/1276-with-csv-source
Open

harsh-thakkar7 wants to merge 1 commit into
AlaSQL:developfrom
harsh-thakkar7:fix/1276-with-csv-source

Conversation

@harsh-thakkar7

Copy link
Copy Markdown

Fix WITH using a CSV source (#1276)

Problem

WITH ... SELECT * FROM CSV('<file>', {headers:true}) throws:

Error: Data source number 0 in undefined

The CSV source is loaded from file asynchronously (loadFile), but yy.WithSelect.prototype.execute called w.select.execute(databaseid, params) without a callback, so the temporary table's data was still undefined when the outer select joined/read it.

Fix

WithSelect.execute now executes each non-recursive CTE with a completion callback: the temporary table is populated once the subquery finishes, and the next CTE / outer select only runs afterwards. Synchronous CTE queries complete during the call, so the sync path is unchanged and existing WITH tests are unaffected (submitted tests + existing CTE tests pass).

Tests

Added test/test1276.js with 4 cases:

  • A) plain SELECT * FROM CSV("./test/test1276.csv", ...) baseline
  • B) WITH c AS (SELECT * FROM CSV(...)) SELECT * FROM c
  • C) B returns exactly what A returns
  • D) several CTEs over CSV sources
$ bun test --preload ./test/bun-setup.js ./test/test1276.js
 4 pass
 0 fail

Because the bug is triggered by the async path, the tests assert via alasql.promise (as the original repro used alasql with callbacks/then).

Closes #1276

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.

WITH using a CSV source throws Error: Data source number 0 in undefined

1 participant