clintropolis commented on code in PR #14619:
URL: https://github.com/apache/druid/pull/14619#discussion_r1268551260
##########
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:
i wonder if we might want to check for ARRAY or COMPLEX types, since
stringifying them and putting them in the filter isn't probably the right thing
(it previously was impossible here because of the check for RexLiteral), could
move
```
final ColumnType matchValueType =
Calcites.getColumnTypeForRelDataType(rhs.getType());
```
outside of the range filter case and check `matchValueType.isPrimitive()` to
be safe.
--
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]