abhishekagarwal87 commented on code in PR #14890:
URL: https://github.com/apache/druid/pull/14890#discussion_r1400344977


##########
sql/src/main/java/org/apache/druid/sql/calcite/run/NativeQueryMaker.java:
##########
@@ -155,12 +163,47 @@ public QueryResponse<Object[]> runQuery(final DruidQuery 
druidQuery)
     );
   }
 
-  private List<Interval> findBaseDataSourceIntervals(Query<?> query)
+  private List<Interval> findMaxBaseDataSourceIntervals(DataSource dataSource, 
DataSourceAnalysis dsAnalysis, List<Interval> defaults)
   {
-    return query.getDataSource().getAnalysis()
-                .getBaseQuerySegmentSpec()
-                .map(QuerySegmentSpec::getIntervals)
-                .orElseGet(query::getIntervals);
+    Optional<List<Interval>> intervals = 
dsAnalysis.getBaseQuerySegmentSpec().map(QuerySegmentSpec::getIntervals);
+    if (intervals.isPresent()) {
+      return intervals.get();
+    }
+
+    // If dataSource is a instance of JoinDataSource, find the base intervals 
of left and right data sources
+    if (dataSource instanceof JoinDataSource) {
+      JoinDataSource joinDataSource = (JoinDataSource) dataSource;
+      DataSource right = joinDataSource.getRight();
+      DataSource left = joinDataSource.getLeft();
+
+      // right data source has a subquery
+      if (right instanceof QueryDataSource) {
+        DataSource rightInner = ((QueryDataSource) 
right).getQuery().getDataSource();
+        DataSourceAnalysis rightAnlaysisInner = rightInner.getAnalysis();
+        if (rightInner instanceof JoinDataSource) {
+          return findMaxBaseDataSourceIntervals(rightInner, 
rightAnlaysisInner, defaults);

Review Comment:
   The right thing is to ensure that both left and right have time filters. 
Since this method is used only to check the eternity interval, it could be 
refactored to checkThatDataSourceHaveFiniteInterval and then the method throws 
an exception wherever there is an eternity interval list. and that check should 
be performed on children.  
   what do you think? 



-- 
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]

Reply via email to