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



##########
File path: core/src/test/java/org/apache/calcite/sql/type/SqlTypeUtilTest.java
##########
@@ -117,6 +120,47 @@
     SqlTypeCoercionRule.THREAD_PROVIDERS.set(defaultRules);
   }
 
+  @Test void testEqualAsCollectionSansNullability() {
+    final SqlTypeFactoryImpl factory =
+        new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RelDataType bigint = factory.createSqlType(SqlTypeName.BIGINT);
+
+    // case array
+    final RelDataType arrayNullable =
+        new ArraySqlType(factory.createTypeWithNullability(bigint, true), 
false);
+    final RelDataType arrayNotNull =
+        new ArraySqlType(factory.createTypeWithNullability(bigint, false), 
false);
+    assertThat(equalAsCollectionSansNullability(factory, arrayNullable, 
arrayNotNull),
+        is(true));
+
+    // case multiset
+    final RelDataType setNullable =
+        new MultisetSqlType(factory.createTypeWithNullability(bigint, true), 
false);
+    final RelDataType setNotNull =
+        new MultisetSqlType(factory.createTypeWithNullability(bigint, false), 
false);
+    assertThat(equalAsCollectionSansNullability(factory, setNullable, 
setNotNull),
+        is(true));
+
+    // multiset and array are not equal.
+    assertThat(equalAsCollectionSansNullability(factory, arrayNotNull, 
setNotNull),
+        is(false));
+  }
+
+  @Test void testEqualAsMapSansNullability() {
+    final SqlTypeFactoryImpl factory =
+        new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RelDataType bigint = factory.createSqlType(SqlTypeName.BIGINT);

Review comment:
       > Use type from `SqlTypeFixture` if possible.
   
   ok

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1160,6 +1161,49 @@ 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) {
+    Preconditions.checkArgument(isCollection(type1));
+    Preconditions.checkArgument(isCollection(type2));
+    return type1.getSqlTypeName() == type2.getSqlTypeName()
+        && equalSansNullability(factory, type1.getComponentType(), 
type2.getComponentType());
+  }
+
+  /**
+   * 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) {
+    Preconditions.checkArgument(isMap(type1));

Review comment:
       > Add `type1 == type2` check to see if they are equals for fast check.
   
   ok




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