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



##########
File path: core/src/test/java/org/apache/calcite/sql/type/SqlTypeUtilTest.java
##########
@@ -117,6 +126,37 @@
     SqlTypeCoercionRule.THREAD_PROVIDERS.set(defaultRules);
   }
 
+  @Test void testConvertTypeToSpec() {
+    SqlBasicTypeNameSpec basicSpec =
+        (SqlBasicTypeNameSpec) 
convertTypeToSpec(f.sqlBigInt).getTypeNameSpec();
+    assertThat(basicSpec.getTypeName().getSimple(), is("BIGINT"));
+
+    SqlCollectionTypeNameSpec arraySpec =
+        (SqlCollectionTypeNameSpec) 
convertTypeToSpec(f.arrayBigInt).getTypeNameSpec();
+    assertThat(arraySpec.getTypeName().getSimple(), is("ARRAY"));
+    assertThat(arraySpec.getElementTypeName().getTypeName().getSimple(), 
is("BIGINT"));
+
+    SqlCollectionTypeNameSpec multisetSpec =
+        (SqlCollectionTypeNameSpec) 
convertTypeToSpec(f.multisetBigInt).getTypeNameSpec();
+    assertThat(multisetSpec.getTypeName().getSimple(), is("MULTISET"));
+    assertThat(multisetSpec.getElementTypeName().getTypeName().getSimple(), 
is("BIGINT"));
+
+    SqlRowTypeNameSpec rowSpec =
+        (SqlRowTypeNameSpec) 
convertTypeToSpec(f.structOfInt).getTypeNameSpec();
+    List<String> fieldNames = rowSpec.getFieldNames()
+        .stream()
+        .map(SqlIdentifier::getSimple)
+        .collect(Collectors.toList());
+    List<String> fieldTypeNames = rowSpec.getFieldTypes()
+        .stream()
+        .map(f -> f.getTypeName().getSimple())
+        .collect(Collectors.toList());
+    assertThat(rowSpec.getTypeName().getSimple(), is("ROW"));
+    assertThat(fieldNames, is(Lists.newArrayList("i", "j")));
+    assertThat(fieldTypeNames, is(Lists.newArrayList("INTEGER", "INTEGER")));

Review comment:
       Thanks for your advice, I've changed my PR.
   
   

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1038,19 +1043,40 @@ public static SqlDataTypeSpec 
convertTypeToSpec(RelDataType type,
     // interval types, multiset types, etc
     assert typeName != null;
 
-    int precision = typeName.allowsPrec() ? type.getPrecision() : -1;
-    // fix up the precision.
-    if (maxPrecision > 0 && precision > maxPrecision) {
-      precision = maxPrecision;
+    SqlTypeNameSpec typeNameSpec;
+    if (isAtomic(type)) {

Review comment:
       Thanks for your advice, I've changed my PR.

##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1038,19 +1043,40 @@ public static SqlDataTypeSpec 
convertTypeToSpec(RelDataType type,
     // interval types, multiset types, etc
     assert typeName != null;
 
-    int precision = typeName.allowsPrec() ? type.getPrecision() : -1;
-    // fix up the precision.
-    if (maxPrecision > 0 && precision > maxPrecision) {
-      precision = maxPrecision;
+    SqlTypeNameSpec typeNameSpec;
+    if (isAtomic(type)) {

Review comment:
       `typeNameSpec` will be assigned latter.




----------------------------------------------------------------
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:
[email protected]


Reply via email to