liuyongvs commented on code in PR #3320:
URL: https://github.com/apache/calcite/pull/3320#discussion_r1294117217


##########
core/src/main/java/org/apache/calcite/sql/type/ArrayInsertOperandTypeChecker.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlUtil;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type checking strategy, where the operand size is 3, and the 
first type is array,
+ * the second type is integer, and the third type is the component type of the 
first array (
+ * strictly matched without leastRestrictive conversion).
+ */
+public class ArrayInsertOperandTypeChecker extends SameOperandTypeChecker {
+
+  public ArrayInsertOperandTypeChecker() {
+    super(3);
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override public boolean checkOperandTypes(
+      SqlCallBinding callBinding,
+      boolean throwOnFailure) {
+    // all operands can't be null (without cast)
+    for (SqlNode node : callBinding.operands()) {
+      if (SqlUtil.isNullLiteral(node, false)) {
+        if (throwOnFailure) {
+          throw callBinding.getValidator().newValidationError(node,
+              
RESOURCE.argumentMustNotBeNull(callBinding.getOperator().getName()));
+        } else {
+          return false;
+        }
+      }
+    }
+
+    // op0 is an array type
+    final SqlNode op0 = callBinding.operand(0);
+    if (!OperandTypes.ARRAY.checkSingleOperandType(
+        callBinding,
+        op0,
+        0,
+        throwOnFailure)) {
+      return false;
+    }
+
+    // op1 is an Integer type
+    final SqlNode op1 = callBinding.operand(1);
+    RelDataType op1Type = SqlTypeUtil.deriveType(callBinding, op1);
+    SqlTypeName op1TypeName = op1Type.getSqlTypeName();
+    if (op1TypeName != SqlTypeName.INTEGER) {
+      if (throwOnFailure) {
+        throw callBinding.newError(
+            RESOURCE.typeNotComparable(
+                op1TypeName.getName(), SqlTypeName.INTEGER.getName()));
+      }
+      return false;
+    }
+
+    // op2 must has same type with op0 component type strictly
+    final RelDataType op0ComponentType =
+        getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+    SqlNode op2 = callBinding.operand(2);
+    RelDataType op2Type = SqlTypeUtil.deriveType(callBinding, op2);
+    if (op2Type.getSqlTypeName() != op0ComponentType.getSqlTypeName()) {
+      if (throwOnFailure) {

Review Comment:
   op2Type.getSqlTypeName() != op0ComponentType.getSqlTypeName())
   it may not enougn, when the type is also complex type, like array/row/spark. 
for example row(int) and row(int , bigint)



##########
core/src/main/java/org/apache/calcite/sql/type/ArrayInsertOperandTypeChecker.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlUtil;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type checking strategy, where the operand size is 3, and the 
first type is array,
+ * the second type is integer, and the third type is the component type of the 
first array (
+ * strictly matched without leastRestrictive conversion).
+ */
+public class ArrayInsertOperandTypeChecker extends SameOperandTypeChecker {
+
+  public ArrayInsertOperandTypeChecker() {
+    super(3);
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override public boolean checkOperandTypes(
+      SqlCallBinding callBinding,
+      boolean throwOnFailure) {
+    // all operands can't be null (without cast)
+    for (SqlNode node : callBinding.operands()) {
+      if (SqlUtil.isNullLiteral(node, false)) {
+        if (throwOnFailure) {
+          throw callBinding.getValidator().newValidationError(node,
+              
RESOURCE.argumentMustNotBeNull(callBinding.getOperator().getName()));
+        } else {
+          return false;
+        }
+      }
+    }
+
+    // op0 is an array type
+    final SqlNode op0 = callBinding.operand(0);
+    if (!OperandTypes.ARRAY.checkSingleOperandType(
+        callBinding,
+        op0,
+        0,
+        throwOnFailure)) {
+      return false;
+    }
+
+    // op1 is an Integer type
+    final SqlNode op1 = callBinding.operand(1);

Review Comment:
   op1 is an Integer type  +1 great, which aligns with spark



##########
core/src/main/java/org/apache/calcite/sql/type/ArrayInsertOperandTypeChecker.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlUtil;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type checking strategy, where the operand size is 3, and the 
first type is array,
+ * the second type is integer, and the third type is the component type of the 
first array (
+ * strictly matched without leastRestrictive conversion).
+ */
+public class ArrayInsertOperandTypeChecker extends SameOperandTypeChecker {
+
+  public ArrayInsertOperandTypeChecker() {
+    super(3);
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override public boolean checkOperandTypes(
+      SqlCallBinding callBinding,
+      boolean throwOnFailure) {
+    // all operands can't be null (without cast)
+    for (SqlNode node : callBinding.operands()) {
+      if (SqlUtil.isNullLiteral(node, false)) {
+        if (throwOnFailure) {
+          throw callBinding.getValidator().newValidationError(node,
+              
RESOURCE.argumentMustNotBeNull(callBinding.getOperator().getName()));
+        } else {
+          return false;
+        }
+      }
+    }
+
+    // op0 is an array type
+    final SqlNode op0 = callBinding.operand(0);
+    if (!OperandTypes.ARRAY.checkSingleOperandType(
+        callBinding,
+        op0,
+        0,
+        throwOnFailure)) {
+      return false;
+    }
+
+    // op1 is an Integer type
+    final SqlNode op1 = callBinding.operand(1);
+    RelDataType op1Type = SqlTypeUtil.deriveType(callBinding, op1);
+    SqlTypeName op1TypeName = op1Type.getSqlTypeName();
+    if (op1TypeName != SqlTypeName.INTEGER) {
+      if (throwOnFailure) {
+        throw callBinding.newError(
+            RESOURCE.typeNotComparable(
+                op1TypeName.getName(), SqlTypeName.INTEGER.getName()));
+      }
+      return false;
+    }
+
+    // op2 must has same type with op0 component type strictly
+    final RelDataType op0ComponentType =
+        getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+    SqlNode op2 = callBinding.operand(2);
+    RelDataType op2Type = SqlTypeUtil.deriveType(callBinding, op2);
+    if (op2Type.getSqlTypeName() != op0ComponentType.getSqlTypeName()) {
+      if (throwOnFailure) {

Review Comment:
   op2Type.getSqlTypeName() != op0ComponentType.getSqlTypeName())
   it may not enougn, when the type is also complex type, like array/row/spark. 
for example row(int) and row(int , bigint)



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

Reply via email to