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



##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1160,6 +1160,59 @@ public static boolean equalSansNullability(
         factory.createTypeWithNullability(type2, type1.isNullable()));
   }
 
+  /**
+   * Returns whether two array types are equal, ignoring nullability.
+   *

Review comment:
       `array/multiset` -> `collection`

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1160,6 +1160,64 @@ public static boolean equalSansNullability(
         factory.createTypeWithNullability(type2, type1.isNullable()));
   }
 
+  /**
+   * Returns whether two array/multiset types are equal, ignoring nullability.
+   *
+   * <p>They need not come from the same factory.
+   *
+   * @param factory       Type factory
+   * @param type1         First type
+   * @param type2         Second type
+   * @return Whether types are equal, ignoring nullability
+   */
+  public static boolean equalAsCollectionSansNullability(
+      RelDataTypeFactory factory,
+      RelDataType type1,
+      RelDataType type2) {
+    assert isCollection(type1) && isCollection(type2);
+
+    if (type1.equals(type2)) {
+      return true;
+    }
+
+    if (type1.getSqlTypeName() == type2.getSqlTypeName()
+        && isCollection(type1) && isCollection(type2)) {
+      return equalSansNullability(factory, type1.getComponentType(), 
type2.getComponentType());
+    } else {
+      return false;
+    }
+  }
+
+  /**
+   * Returns whether two map types are equal, ignoring nullability.
+   *
+   * <p>They need not come from the same factory.
+   *
+   * @param factory       Type factory
+   * @param type1         First type
+   * @param type2         Second type
+   * @return Whether types are equal, ignoring nullability
+   */
+  public static boolean equalAsMapSansNullability(
+      RelDataTypeFactory factory,
+      RelDataType type1,
+      RelDataType type2) {
+    assert isMap(type1) && isMap(type2);
+
+    if (type1.equals(type2)) {
+      return true;
+    }
+
+    if (isMap(type1) && isMap(type2)) {
+      MapSqlType mType1 = (MapSqlType) type1;
+      MapSqlType mType2 = (MapSqlType) type2;
+      return equalSansNullability(factory, mType1.getKeyType(), 
mType2.getKeyType())
+          && equalSansNullability(factory, mType1.getValueType(), 
mType2.getValueType());
+    } else {
+      return false;

Review comment:
       `return equalSansNullability(factory, mType1.getKeyType(), 
mType2.getKeyType())
             && equalSansNullability(factory, mType1.getValueType(), 
mType2.getValueType());` is enough.

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1160,6 +1160,59 @@ public static boolean equalSansNullability(
         factory.createTypeWithNullability(type2, type1.isNullable()));
   }
 
+  /**
+   * Returns whether two array types are equal, ignoring nullability.
+   *
+   * <p>They need not come from the same factory.
+   *
+   * @param factory       Type factory
+   * @param type1         First type
+   * @param type2         Second type
+   * @return Whether types are equal, ignoring nullability
+   */
+  public static boolean equalAsCollectionSansNullability(
+      RelDataTypeFactory factory,
+      RelDataType type1,
+      RelDataType type2) {
+    if (type1.equals(type2)) {
+      return true;
+    }
+
+    if (isCollection(type1) && isCollection(type2)) {
+      return equalSansNullability(factory, type1.getComponentType(), 
type2.getComponentType());

Review comment:
       No need to have `isCollection(type1) && isCollection(type2)` which is 
already in the assertion.

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1160,6 +1160,64 @@ public static boolean equalSansNullability(
         factory.createTypeWithNullability(type2, type1.isNullable()));
   }
 
+  /**
+   * Returns whether two array/multiset types are equal, ignoring nullability.
+   *
+   * <p>They need not come from the same factory.
+   *
+   * @param factory       Type factory
+   * @param type1         First type
+   * @param type2         Second type
+   * @return Whether types are equal, ignoring nullability
+   */
+  public static boolean equalAsCollectionSansNullability(
+      RelDataTypeFactory factory,
+      RelDataType type1,
+      RelDataType type2) {
+    assert isCollection(type1) && isCollection(type2);
+
+    if (type1.equals(type2)) {
+      return true;
+    }
+
+    if (type1.getSqlTypeName() == type2.getSqlTypeName()
+        && isCollection(type1) && isCollection(type2)) {
+      return equalSansNullability(factory, type1.getComponentType(), 
type2.getComponentType());
+    } else {
+      return false;
+    }
+  }
+
+  /**
+   * Returns whether two map types are equal, ignoring nullability.
+   *
+   * <p>They need not come from the same factory.
+   *
+   * @param factory       Type factory
+   * @param type1         First type
+   * @param type2         Second type
+   * @return Whether types are equal, ignoring nullability
+   */
+  public static boolean equalAsMapSansNullability(
+      RelDataTypeFactory factory,
+      RelDataType type1,
+      RelDataType type2) {
+    assert isMap(type1) && isMap(type2);
+
+    if (type1.equals(type2)) {
+      return true;
+    }

Review comment:
       Remove it.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to