clintropolis commented on code in PR #14619:
URL: https://github.com/apache/druid/pull/14619#discussion_r1268561070


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java:
##########
@@ -651,43 +648,30 @@ private static DimFilter toSimpleLeafFilter(
 
         final Granularity granularity = 
ExtractionFns.toQueryGranularity(extractionFn);
         if (granularity != null) {
-          // lhs is FLOOR(__time TO granularity); rhs must be a timestamp
+          // lhs is FLOOR(__time TO granularity); rhs must be a timestamp.
           final long rhsMillis = Calcites.calciteDateTimeLiteralToJoda(rhs, 
plannerContext.getTimeZone()).getMillis();
-          final Interval rhsInterval = 
granularity.bucket(DateTimes.utc(rhsMillis));
-
-          // Is rhs aligned on granularity boundaries?
-          final boolean rhsAligned = rhsInterval.getStartMillis() == rhsMillis;
-
-          if (plannerContext.isUseBoundsAndSelectors()) {
-            // Create a BoundRefKey that strips the extractionFn and compares 
__time as a number.
-            final BoundRefKey boundRefKey = new BoundRefKey(column, null, 
StringComparators.NUMERIC);
-
-            return getBoundTimeDimFilter(flippedKind, boundRefKey, 
rhsInterval, rhsAligned);
-          } else {
-            final RangeRefKey rangeRefKey = new RangeRefKey(column, 
ColumnType.LONG);
-            return getRangeTimeDimFilter(flippedKind, rangeRefKey, 
rhsInterval, rhsAligned);
-          }
+          return buildTimeFloorFilter(column, granularity, flippedKind, 
rhsMillis, plannerContext);
         }
       }
 
-      if (plannerContext.isUseBoundsAndSelectors() && rhs instanceof 
RexLiteral) {
-        final String val;
-        final RexLiteral rhsLiteral = (RexLiteral) rhs;
-        if (SqlTypeName.NUMERIC_TYPES.contains(rhsLiteral.getTypeName())) {
-          val = String.valueOf(RexLiteral.value(rhsLiteral));
-        } else if (SqlTypeName.CHAR_TYPES.contains(rhsLiteral.getTypeName())) {
-          val = String.valueOf(RexLiteral.stringValue(rhsLiteral));
-        } else if (SqlTypeName.TIMESTAMP == rhsLiteral.getTypeName() || 
SqlTypeName.DATE == rhsLiteral.getTypeName()) {
-          val = String.valueOf(
-              Calcites.calciteDateTimeLiteralToJoda(
-                  rhsLiteral,
-                  plannerContext.getTimeZone()
-              ).getMillis()
-          );
+      if (plannerContext.isUseBoundsAndSelectors()) {
+        final String stringVal;
+
+        if (rhsParsed.getLiteralValue() == null) {
+          stringVal = NullHandling.defaultStringValue();
+        } else if (RexUtil.isLiteral(rhs, true) && 
SqlTypeName.NUMERIC_TYPES.contains(rhs.getType().getSqlTypeName())) {
+          // Peek inside the original rhs for numerics, rather than using the 
parsed version, for highest fidelity
+          // to what the query originally contained. (It may be a BigDecimal.)
+          stringVal = String.valueOf(RexLiteral.value(rhs));
         } else {
-          // Don't know how to filter on this kind of literal.
+          stringVal = String.valueOf(rhsParsed.getLiteralValue());

Review Comment:
   totally cool for the `range` case since they include the `ColumnType` for 
the match value and know how to handle stuff, so just the bounds path needs 
guarded to not do weird stuff



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