-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating plans when using joins with unnest on the left #15075
Changes from 5 commits
52fb78d
e2b1329
7a06d1b
0a4892d
a71d4f1
78f0090
589ed89
31153f7
518c1ba
b6c2e03
8a0f9a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,10 +476,18 @@ private Function<SegmentReference, SegmentReference> createSegmentMapFunctionInt | |
.orElse(null) | ||
) | ||
); | ||
|
||
final Function<SegmentReference, SegmentReference> baseMapFn; | ||
if (left instanceof JoinDataSource) { | ||
baseMapFn = Function.identity(); | ||
} else { | ||
baseMapFn = left.createSegmentMapFunction( | ||
query, | ||
cpuTimeAccumulator | ||
); | ||
} | ||
return baseSegment -> | ||
new HashJoinSegment( | ||
baseSegment, | ||
baseMapFn.apply(baseSegment), | ||
baseFilterToUse, | ||
GuavaUtils.firstNonNull(clausesToUse, ImmutableList.of()), | ||
joinFilterPreAnalysis | ||
|
@@ -501,20 +509,37 @@ private static Triple<DataSource, DimFilter, List<PreJoinableClause>> flattenJoi | |
DimFilter currentDimFilter = null; | ||
final List<PreJoinableClause> preJoinableClauses = new ArrayList<>(); | ||
|
||
while (current instanceof JoinDataSource) { | ||
final JoinDataSource joinDataSource = (JoinDataSource) current; | ||
current = joinDataSource.getLeft(); | ||
currentDimFilter = validateLeftFilter(current, joinDataSource.getLeftFilter()); | ||
preJoinableClauses.add( | ||
new PreJoinableClause( | ||
joinDataSource.getRightPrefix(), | ||
joinDataSource.getRight(), | ||
joinDataSource.getJoinType(), | ||
joinDataSource.getConditionAnalysis() | ||
) | ||
); | ||
// There can be queries like | ||
// Join of Unnest of Join of Unnest of Filter | ||
// so these checks are needed to be ORed | ||
// to get the base | ||
// This also means that an addition of a new datasource | ||
// Will need an instanceof check here | ||
// A future work should look into if the flattenJoin | ||
// can be refactored to omit these instanceof checks | ||
while (current instanceof JoinDataSource || current instanceof UnnestDataSource || current instanceof FilteredDataSource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add test cases for self join with unnest datasource if we do not have already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, added a test with self join on an unnest data source |
||
if (current instanceof JoinDataSource) { | ||
final JoinDataSource joinDataSource = (JoinDataSource) current; | ||
current = joinDataSource.getLeft(); | ||
currentDimFilter = validateLeftFilter(current, joinDataSource.getLeftFilter()); | ||
preJoinableClauses.add( | ||
new PreJoinableClause( | ||
joinDataSource.getRightPrefix(), | ||
joinDataSource.getRight(), | ||
joinDataSource.getJoinType(), | ||
joinDataSource.getConditionAnalysis() | ||
) | ||
); | ||
} else if (current instanceof UnnestDataSource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't seem intuitive to me that we can flatten away unnest and filtered datasources, could we add comments explaining why its ok? is it still ok if the unnest datasource is wrapping a join datasource? like does it flatten through it? where does the unnest and filters go in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add comments. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment and unit test added |
||
final UnnestDataSource unnestDataSource = (UnnestDataSource) current; | ||
current = unnestDataSource.getBase(); | ||
} else { | ||
final FilteredDataSource filteredDataSource = (FilteredDataSource) current; | ||
current = filteredDataSource.getBase(); | ||
} | ||
} | ||
|
||
|
||
// Join clauses were added in the order we saw them while traversing down, but we need to apply them in the | ||
// going-up order. So reverse them. | ||
Collections.reverse(preJoinableClauses); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems worth a comment on what is going on. Is it still ok to do if left is not concrete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment as into why we are not using the isConcrete() check and instead using the instanceof check here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is added