somu-imply commented on code in PR #15075:
URL: https://github.com/apache/druid/pull/15075#discussion_r1348995898
##########
processing/src/main/java/org/apache/druid/query/JoinDataSource.java:
##########
@@ -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) {
+ 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) {
Review Comment:
I'll add comments. The `getAnalysis()` of an Unnest or a filteredDS always
delegates to its base. So flattening through a Join->Unnest->Join kind of
scenario to get the base data source makes sense as it goes down to find the
base concrete data source. In this PR, the filters on the filteredDataSource
and unnestDataSource are not pushed down to the left of the join, the unnest
filter and the filter on the filteredDataSource remain on the data source. I
have added an unit test of Join->Unnest->Join will add another UT of
Join->Unnest->Filter->Join
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]