zabetak commented on code in PR #4591:
URL: https://github.com/apache/calcite/pull/4591#discussion_r2468783069


##########
druid/src/test/java/org/apache/calcite/test/DruidAdapter2IT.java:
##########
@@ -3054,7 +3054,8 @@ private void testCountWithApproxDistinct(boolean approx, 
String sql,
             + " CAST('1997-01-01' as DATE) GROUP BY  floor(\"timestamp\" to 
DAY) order by d limit 3";
     final String plan = "PLAN=EnumerableInterpreter\n"
         + "  DruidQuery(table=[[foodmart, foodmart]], "
-        + "intervals=[[1997-01-01T00:00:00.000Z/1997-02-01T00:00:00.000Z]], "
+        + "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "

Review Comment:
   The interval 1900 to 2992 is the maximum timestamp range that you can have 
in Druid adapter and usually appears when there is: 
   * a full table scan
   * no filter on the declared timestamp column.
   
   The reason for this change is that previously the expression
   `SEARCH(CAST($0):DATE NOT NULL, Sarg[[1997-01-01..1997-02-01)])` was pushed 
down as an interval to Druid via the 
[DruidDateTimeUtils](https://github.com/apache/calcite/blob/4f79aa875c4ccf6e50bbd6475b716ce9cd529251/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java#L239)
 unconditionally.
   
   However, the `leafToRanges` method should only handle operators that are 
composed from a `RexInputRef` + `RexLiteral` combination. These checks are in 
place for traditional comparisons (<,<=,=,>=,>) but they were not present for 
SEARCH. To prevent failures and potentially wrong results I added 
`DruidDateTimeUtils.canTransformSearchToRange` that verifies the arguments 
before doing the interval conversion. In other words, the new check that I 
introduced explicitly prevents the conversion to interval when the first 
argument of SEARCH is not a plain `RexInputRef`.
   
   Although the previous plan was more efficient, the improvement was rather a 
side-effect from fixing CALCITE-1974 that is not guaranteed to produce correct 
results since the entire `DruidDateTimeUtils.createInterval` was not meant to 
handle complex expressions.



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

Reply via email to