Fix lookup join returning 0 rows when a dimension primary-key component is a literal [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #19197
Open
waterWang wants to merge 1 commit into
Conversation
…nt is a literal When a lookup join condition includes a literal on a dimension table primary key column (e.g. dim_tbl.currency = 'gbp'), Calcite's analyzeCondition() classifies it as a non-equi condition rather than an equi-join key. The LookupJoinOperator builds the lookup key only from leftKeys (equi-join column-column pairs), so the literal component is missing from the key, making it shorter than the dimension table's primary key. The lookup always returns null, producing 0 result rows. Fix: Build the lookup key in the dimension table's primary key column order. For each primary key column, determine the value source: either the corresponding left column (equi-join via leftKeys/rightKeys) or a literal value extracted from the non-equi condition. Closes apache#19188
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
When a lookup join condition includes a literal on a dimension table primary key column (e.g.
dim_tbl.currency = 'gbp'), Calcite'sanalyzeCondition()classifies it as a non-equi condition rather than an equi-join key. TheLookupJoinOperatorbuilds the lookup key only fromleftKeys(equi-join column-column pairs), so the literal component is missing from the key. The key becomes shorter than the dimension table's primary key, causing the lookup to always return null — producing 0 result rows.Root Cause
The condition
dim_tbl.currency = 'gbp' AND dim_tbl.rate_start_date = fact_tbl.rate_start_dateis split by Calcite as:dim_tbl.rate_start_date = fact_tbl.rate_start_date→leftKeys/rightKeysdim_tbl.currency = 'gbp'(column vs literal)The operator builds the key from
leftKeysonly, producing a 1-component key. But the dimension table's primary key is[currency, rate_start_date](2 components), so the lookup always fails.Fix
Build the lookup key in the dimension table's primary key column order, filling each position from either:
leftKeys/rightKeysmapping)dim_col = literalTesting
Added
lookup_join_literal_keytest case toLookupJoin.jsonwith:[currency, rate_start_date]dim_tbl.currency = 'gbp' AND dim_tbl.rate_start_date = fact_tbl.rate_start_date['gbp', 125]Closes #19188