Repository navigation
Fix WITH using an async source like CSV() to close #1276 - #2571
Merged
Merged
Conversation
Member
|
Thank you! |
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.
Problem
A CTE that reads from an asynchronous source fails:
throws
Error: Data source number 0 in undefined(uncaught, even when a callback oralasql.promiseis used), while the same query written as a subselect works.Cause
WithSelect.prototype.executefilled each temporary CTE table withtb.data = w.select.execute(databaseid, params), i.e. without a callback.CSV()(and other file sources) load the data asynchronously, so that call returnsundefinedand the main select then reads a table without data.Fix
The CTEs are now executed one after another, each with a completion callback. The temporary table is filled once its select has finished, and only then is the next CTE (or the main select) run. Errors from a CTE are passed to the callback and the temporary tables are restored.
For synchronous sources the callbacks still run immediately, so
alasql('WITH ... SELECT ...')keeps returning its result directly (the statement returns its own result rather than the callback's, so the result of the rest of the chain is kept and returned). Recursive CTEs are unchanged.Tests
test/test1276.js: CSV source in a CTE with a callback and withalasql.promise, a CTE that uses a previous CSV-backed CTE, cleanup of the temporary table, and a synchronous multi-CTE query that still returns directly. The 4 async cases fail ondevelopand pass with this change.yarn test-only(full suite): 2251 pass, 213 skip, 0 fail.yarn test-formatpasses.Note: while testing I noticed that a non-recursive CTE with a column list (
WITH c(x) AS (...)) fails withrenameColumns is not defined. That happens ondeveloptoo and isn't touched here.Fixes #1276