You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:58:13 UTC

[GitHub] [calcite] danny0405 commented on a change in pull request #2088: [CALCITE-4145] Exception when query from UDF field with structured type

danny0405 commented on a change in pull request #2088:
URL: https://github.com/apache/calcite/pull/2088#discussion_r461515305



##########
File path: core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java
##########
@@ -57,14 +59,23 @@
   RexFieldAccess(
       RexNode expr,
       RelDataTypeField field) {
+    checkValid(expr, field);
     this.expr = expr;
     this.field = field;
     this.digest = expr + "." + field.getName();
-    assert expr.getType().getFieldList().get(field.getIndex()) == field;
   }
 
   //~ Methods ----------------------------------------------------------------
 
+  private static void checkValid(RexNode expr, RelDataTypeField field) {
+    RelDataType exprType = expr.getType();
+    int fieldsNum = exprType.getFieldList().size();
+    int fieldIdx = field.getIndex();
+    final String errMsg = "Field " + field + " does not exist for expression " + expr;
+    Preconditions.checkArgument(fieldIdx < fieldsNum, errMsg);
+    Preconditions.checkArgument(exprType.getFieldList().get(fieldIdx).equals(field), errMsg);
+  }

Review comment:
       I made this change because there are some problem with the new added test case in test env with concurrency, the `==` check is invalid.

##########
File path: core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java
##########
@@ -57,14 +59,23 @@
   RexFieldAccess(
       RexNode expr,
       RelDataTypeField field) {
+    checkValid(expr, field);
     this.expr = expr;
     this.field = field;
     this.digest = expr + "." + field.getName();
-    assert expr.getType().getFieldList().get(field.getIndex()) == field;
   }
 
   //~ Methods ----------------------------------------------------------------
 
+  private static void checkValid(RexNode expr, RelDataTypeField field) {
+    RelDataType exprType = expr.getType();
+    int fieldsNum = exprType.getFieldList().size();
+    int fieldIdx = field.getIndex();
+    final String errMsg = "Field " + field + " does not exist for expression " + expr;
+    Preconditions.checkArgument(fieldIdx < fieldsNum, errMsg);
+    Preconditions.checkArgument(exprType.getFieldList().get(fieldIdx).equals(field), errMsg);
+  }

Review comment:
       I made this change because there are some problem with the new added test case in test env with concurrency, the `==` check not works anymore.




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

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