You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ho...@apache.org on 2019/04/26 03:38:23 UTC

[calcite] branch master updated: [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new eed664d  [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei)
eed664d is described below

commit eed664de8c45af1423d692af88cc98395adcb072
Author: pengzhiwei <pe...@icloud.com>
AuthorDate: Mon Apr 8 15:35:10 2019 +0800

    [CALCITE-2982] SqlItemOperator should throw understandable exception message for incorrect operand type (pengzhiwei)
    
    Close apache/calcite#1149
---
 .../src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java | 8 ++++----
 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java  | 7 +++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
index b9f029f..1fcc1cf 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
@@ -87,13 +87,13 @@ class SqlItemOperator extends SqlSpecialOperator {
         throwOnFailure)) {
       return false;
     }
-    final RelDataType operandType = callBinding.getOperandType(0);
-    final SqlSingleOperandTypeChecker checker = getChecker(operandType);
+    final SqlSingleOperandTypeChecker checker = getChecker(callBinding);
     return checker.checkSingleOperandType(callBinding, right, 0,
         throwOnFailure);
   }
 
-  private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) {
+  private SqlSingleOperandTypeChecker getChecker(SqlCallBinding callBinding) {
+    final RelDataType operandType = callBinding.getOperandType(0);
     switch (operandType.getSqlTypeName()) {
     case ARRAY:
       return OperandTypes.family(SqlTypeFamily.INTEGER);
@@ -106,7 +106,7 @@ class SqlItemOperator extends SqlSpecialOperator {
           OperandTypes.family(SqlTypeFamily.INTEGER),
           OperandTypes.family(SqlTypeFamily.CHARACTER));
     default:
-      throw new AssertionError(operandType.getSqlTypeName());
+      throw callBinding.newValidationSignatureError();
     }
   }
 
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index a70664c..de5c333 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -8127,6 +8127,13 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
         .type("RecordType(VARCHAR(10) OA) NOT NULL");
   }
 
+  @Test public void testItemOperatorException() {
+    sql("select ^name[0]^ from dept")
+        .fails("Cannot apply 'ITEM' to arguments of type 'ITEM\\(<VARCHAR\\(10\\)>, "
+          +  "<INTEGER>\\)'\\. Supported form\\(s\\): <ARRAY>\\[<INTEGER>\\]\n"
+          + "<MAP>\\[<VALUE>\\].*");
+  }
+
   /** Test case for
    * <a href="https://issues.apache.org/jira/browse/CALCITE-497">[CALCITE-497]
    * Support optional qualifier for column name references</a>. */