Feature/using join#2822
Open
stefanoperenzoni wants to merge 2 commits into
Open
Conversation
Signed-off-by: stefanoperenzoni <stefano.perenzoni@gmail.com>
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.
Description
This PR implements the
USINGclause syntax for joins in Malloy. 90% agent generated.Previously, users were forced to use the
withoronkeywords to define join conditions (e.g.,join_one: aircraft_models on aircraft_model_code = aircraft_models.aircraft_model_code). With this change, users can succinctly join tables sharing the same column names using the SQL standardUSINGsyntax.Syntax supported:
```malloy
source: aircraft extend {
join_one: aircraft_models using (aircraft_model_code)
}
run: table1 extend {
join_one: table2 using (id, code)
} -> { select: id, code, val1, table2.val2 }
```
What this PR does
USINGrules toMalloyLexer.g4andMalloyParser.g4.UsingJoinnode (join.ts) which generates an internal equivalence relation so that Malloy's semantic engine understands the lineage of the fields.query_query.tsto output validUSING (col1, col2)SQL.where:conditions on the joined source) into a subquery, preventing invalid SQL sinceANDcannot be appended to aUSINGclause.field_instance.tsto automatically strip table aliases from columns involved in an activeUSINGjoin. Because dialects like BigQuery coalesceUSINGcolumns, fully qualifying them (e.g.base_table.id) results in query failures.join.spec.tsto cover single-column joins, multi-column joins, source-level refinements, and inline query joins.Related Issues
Resolves #2541
Checklist
npm run lint) passesnpm run test) pass