You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/09/26 14:22:30 UTC

[GitHub] [pinot] walterddr commented on a diff in pull request #9456: [multistage][hotfix] fix type cast handling and value literal gen

walterddr commented on code in PR #9456:
URL: https://github.com/apache/pinot/pull/9456#discussion_r980099554


##########
pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/NumericalFilterOptimizer.java:
##########
@@ -448,21 +449,30 @@ private static void rewriteRangeOperator(Expression range, FilterKind kind, int
     }
   }
 
-  /** @return true if expression is a column of numeric type */
-  private static boolean isNumericColumn(Expression expression, Schema schema) {
-    if (expression.getType() != ExpressionType.IDENTIFIER) {
-      // Expression can not be a column.
-      return false;
-    }
-
-    String column = expression.getIdentifier().getName();
-    FieldSpec fieldSpec = schema.getFieldSpecFor(column);
-    if (fieldSpec == null || !fieldSpec.isSingleValueField()) {
-      // Expression can not be a column name.
-      return false;
+  /** @return field data type extracted from the expression. null if we can't determine the type. */
+  private static @Nullable FieldSpec.DataType getDataType(Expression expression, Schema schema) {
+    if (expression.getType() == ExpressionType.IDENTIFIER) {
+      String column = expression.getIdentifier().getName();
+      FieldSpec fieldSpec = schema.getFieldSpecFor(column);
+      if (fieldSpec != null && fieldSpec.isSingleValueField()) {
+        return fieldSpec.getDataType();
+      }
+    } else if (expression.getType() == ExpressionType.FUNCTION
+        && "cast".equalsIgnoreCase(expression.getFunctionCall().getOperator())) {
+      // expression is not identifier but we can also determine the data type.
+      String targetTypeLiteral = expression.getFunctionCall().getOperands().get(1).getLiteral().getStringValue()
+          .toUpperCase();
+      FieldSpec.DataType dataType;
+      if ("INTEGER".equals(targetTypeLiteral)) {
+        dataType = FieldSpec.DataType.INT;
+      } else if ("VARCHAR".equals(targetTypeLiteral)) {
+        dataType = FieldSpec.DataType.STRING;
+      } else {
+        dataType = FieldSpec.DataType.valueOf(targetTypeLiteral);
+      }

Review Comment:
   they are not equivalent. conversion function operates `@ScalarFunction` which runs on `PinotDataType` (physical data type) and here it runs on `FieldSpec.DataType`. 



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org