Repository navigation
Conversation
In edition 3 compiled streams, aliasing the synced table in a JOIN
query (e.g. `SELECT cm.* FROM chat_messages cm INNER JOIN ...`) caused
RowEvaluator.outputName to return the alias ("cm") as the output table
name. The client expects rows in "chat_messages", so all rows were
silently lost.
The alias-as-rename behavior is intentional for single-table queries
(e.g. `SELECT * FROM new_table AS old_name`), but in JOINs, aliases
serve SQL column disambiguation, not output renaming.
Add `hasJoinedTables` flag to RowEvaluator. When the query joins other
physical tables, outputName returns the real table name. Table-valued
function JOINs (e.g. json_each) are not affected — alias-as-rename is
preserved for those.
- Track hasExplicitJoins in StreamQueryParser based on whether the AST FROM list contains physical table entries with a .join clause. - Subqueries lowered into joins by the compiler don't set this flag, preserving alias-as-rename for subquery-backed streams. - Table-valued function JOINs (e.g. json_each) also don't set the flag, since only FROM entries with type 'table' count. - Fix wildcard edge case: aliased wildcards now always use the alias regardless of hasJoinedTables. - Add test verifying subquery alias-as-rename is preserved.
Covers the case where the source table is on the right side of a table-valued function join (e.g. `FROM json_each(...) j INNER JOIN users u ON ...`). The alias is correctly dropped since WAL events use the real table name.
🦋 Changeset detectedLatest commit: b9102e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
As discussed in #565, this is working as intended. So I'll close this, but we can keep the issue open until we've improved docs / a potential warning around this. |
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.
Summary
Fixes #565 — aliasing the synced table in an edition 3
INNER JOINquery causes 0 rows to sync.RowEvaluator.outputNamereturns the SQL alias (e.g."cm") as the output table name. WAL matching works fine (uses the real table name), but output rows are labeled with the alias. The client expectschat_messages, getscm, so nothing syncs.Approach
The alias-as-rename behavior is intentional for single-table queries (e.g.
SELECT * FROM new_table AS old_name). But in explicit JOINs, table aliases are for SQL column disambiguation, not output renaming. WAL events always use real table names, so alias-as-rename in any JOIN involving a physical table would cause silent data loss.The fix tracks
hasExplicitJoinsinStreamQueryParser, set when the ASTFROMlist contains a physical table entry (from.type == 'table') with a.joinclause. When true,RowEvaluator.outputNamereturns the real table name instead of the alias.Alias-as-rename still works for:
SELECT * FROM users u→table: 'u'SELECT * FROM comments c WHERE id IN (SELECT ...)→table: 'c'FROM stores s INNER JOIN json_each(s.tags)→table: 's'Alias dropped (real table name used) for:
INNER JOIN:SELECT cm.* FROM chat_messages cm INNER JOIN other ON ...→table: 'chat_messages'SELECT u.* FROM json_each(...) j INNER JOIN users u ON ...→table: 'users'Changed files
packages/sync-rules/src/compiler/parser.tshasExplicitJoinsfrom ASTFROMentriespackages/sync-rules/src/compiler/rows.tshasJoinedTablestoRowEvaluator;outputNamereturns real table name when set; wildcard aliases always preservedpackages/sync-rules/src/compiler/querier_graph.tshasExplicitJoinswhen constructingRowEvaluatorevaluator.test.tsTest plan