You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ro...@apache.org on 2022/11/14 20:28:58 UTC

[pinot] branch master updated: [multistage][hotfix] fix typo in cast (#9795)

This is an automated email from the ASF dual-hosted git repository.

rongr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new e13ba3e2a8 [multistage][hotfix] fix typo in cast  (#9795)
e13ba3e2a8 is described below

commit e13ba3e2a80257ad93a962dca312465e185dece1
Author: Rong Rong <ro...@apache.org>
AuthorDate: Mon Nov 14 12:28:53 2022 -0800

    [multistage][hotfix] fix typo in cast  (#9795)
    
    * fix typo in cast using source type not target type
    * adding tests
    
    Co-authored-by: Rong Rong <ro...@startree.ai>
---
 .../apache/pinot/query/planner/logical/RelToStageConverter.java  | 3 ++-
 .../org/apache/pinot/query/planner/logical/RexExpression.java    | 5 +++--
 .../apache/pinot/query/planner/logical/RexExpressionUtils.java   | 6 ++----
 .../java/org/apache/pinot/query/runtime/QueryRunnerTest.java     | 9 ++++++---
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RelToStageConverter.java b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RelToStageConverter.java
index 97df437222..b54b26a168 100644
--- a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RelToStageConverter.java
+++ b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RelToStageConverter.java
@@ -167,7 +167,8 @@ public final class RelToStageConverter {
       case VARBINARY:
         return DataSchema.ColumnDataType.BYTES;
       default:
-        throw new IllegalStateException("Unexpected RelDataTypeField: " + relDataTypeField.getType());
+        throw new IllegalStateException("Unexpected RelDataTypeField: " + relDataTypeField.getType() + " for column: "
+            + relDataTypeField.getName());
     }
   }
 }
diff --git a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpression.java b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpression.java
index a6fe9ee6f9..3e964e77d0 100644
--- a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpression.java
+++ b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpression.java
@@ -83,6 +83,8 @@ public interface RexExpression {
         return PinotDataType.LONG;
       case FLOAT:
         return PinotDataType.FLOAT;
+      // TODO: support DECIMAL properly.
+      case DECIMAL:
       case DOUBLE:
         return PinotDataType.DOUBLE;
       case CHAR:
@@ -91,8 +93,7 @@ public interface RexExpression {
       case BOOLEAN:
         return PinotDataType.BOOLEAN;
       default:
-        // TODO: do not assume byte type.
-        return PinotDataType.BYTES;
+        throw new IllegalArgumentException("Unsupported data type: " + type);
     }
   }
 
diff --git a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpressionUtils.java b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpressionUtils.java
index de1ab668f8..cc66047651 100644
--- a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpressionUtils.java
+++ b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/RexExpressionUtils.java
@@ -54,10 +54,8 @@ public class RexExpressionUtils {
         rexCall.getOperands().stream().map(RexExpression::toRexExpression).collect(Collectors.toList());
     Preconditions.checkState(operands.size() == 1, "CAST takes exactly 2 arguments");
     RelDataType castType = rexCall.getType();
-    // add the 2nd argument as the source type info.
-    operands.add(new RexExpression.Literal(FieldSpec.DataType.STRING,
-        RexExpression.toPinotDataType(rexCall.getOperands().get(0).getType()).name()));
-    return new RexExpression.FunctionCall(rexCall.getKind(), RexExpression.toDataType(rexCall.getType()), "CAST",
+    operands.add(new RexExpression.Literal(FieldSpec.DataType.STRING, RexExpression.toPinotDataType(castType).name()));
+    return new RexExpression.FunctionCall(rexCall.getKind(), RexExpression.toDataType(castType), "CAST",
         operands);
   }
 
diff --git a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
index eb234a2d4e..b5c707cb59 100644
--- a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
+++ b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
@@ -200,7 +200,8 @@ public class QueryRunnerTest extends QueryRunnerTestBase {
       QueryDispatcher.reduceMailboxReceive(mailboxReceiveOperator);
     } catch (RuntimeException rte) {
       Assert.assertTrue(rte.getMessage().contains("Received error query execution result block"));
-      Assert.assertTrue(rte.getMessage().contains(exceptionMsg));
+      Assert.assertTrue(rte.getMessage().contains(exceptionMsg), "Exception should contain: " + exceptionMsg
+          + "! but found: " + rte.getMessage());
     }
   }
 
@@ -216,9 +217,11 @@ public class QueryRunnerTest extends QueryRunnerTestBase {
         // test dateTrunc
         //   - on leaf stage
         new Object[]{"SELECT dateTrunc('DAY', ts) FROM a LIMIT 10", 10},
+        new Object[]{"SELECT dateTrunc('DAY', CAST(col3 AS BIGINT)) FROM a LIMIT 10", 10},
         //   - on intermediate stage
         new Object[]{"SELECT dateTrunc('DAY', round(a.ts, b.ts)) FROM a JOIN b "
             + "ON a.col1 = b.col1 AND a.col2 = b.col2", 15},
+        new Object[]{"SELECT dateTrunc('DAY', CAST(MAX(a.col3) AS BIGINT)) FROM a", 1},
 
         // test regexpLike
         new Object[]{"SELECT a.col1, b.col1 FROM a JOIN b ON a.col3 = b.col3 WHERE regexpLike(a.col2, b.col1)", 9},
@@ -229,9 +232,9 @@ public class QueryRunnerTest extends QueryRunnerTestBase {
   @DataProvider(name = "testDataWithSqlExecutionExceptions")
   private Object[][] provideTestSqlWithExecutionException() {
     return new Object[][] {
-        // Function with incorrect argument signature should throw runtime exception
+        // Function with incorrect argument signature should throw runtime exception when casting string to numeric
         new Object[]{"SELECT least(a.col2, b.col3) FROM a JOIN b ON a.col1 = b.col1",
-            "ArithmeticFunctions.least(double,double) with arguments"},
+            "For input string:"},
         // TODO: this error is thrown but not returned through mailbox. need another test for asserting failure
         // during stage runtime init.
         // standard SqlOpTable function that runs out of signature list in actual impl throws not found exception


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