[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-29 Thread GitBox


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



##
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 fieldNames = rowSpec.getFieldNames()
+.stream()
+.map(SqlIdentifier::getSimple)
+.collect(Collectors.toList());
+List fieldTypeNames = rowSpec.getFieldTypes()
+.stream()
+.map(f -> f.getTypeName().getSimple())
+.collect(Collectors.toList());
+assertThat(rowSpec.getTypeName().getSimple(), is("ROW"));
+assertThat(fieldNames, is(Arrays.asList("i", "j")));
+assertThat(fieldTypeNames, is(Arrays.asList("INTEGER", "INTEGER")));
+System.out.println();
+  }

Review comment:
   > Remove `System.out.println();`.
   
   Ok, updated, sorry for the legacy code.





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




[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-29 Thread GitBox


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



##
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 fieldNames = rowSpec.getFieldNames()
+.stream()
+.map(SqlIdentifier::getSimple)
+.collect(Collectors.toList());
+List fieldTypeNames = rowSpec.getFieldTypes()
+.stream()
+.map(f -> f.getTypeName().getSimple())
+.collect(Collectors.toList());
+assertThat(rowSpec.getTypeName().getSimple(), is("ROW"));
+assertThat(fieldNames, is(Arrays.asList("i", "j")));
+assertThat(fieldTypeNames, is(Arrays.asList("INTEGER", "INTEGER")));
+System.out.println();
+  }

Review comment:
   > Remove `System.out.println();`.
   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




[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-22 Thread GitBox


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



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





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




[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-21 Thread GitBox


Aaron 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 fieldNames = rowSpec.getFieldNames()
+.stream()
+.map(SqlIdentifier::getSimple)
+.collect(Collectors.toList());
+List 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:
us...@infra.apache.org




[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-19 Thread GitBox


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



##
File path: core/src/test/java/org/apache/calcite/sql/type/SqlTypeUtilTest.java
##
@@ -117,6 +131,57 @@
 SqlTypeCoercionRule.THREAD_PROVIDERS.set(defaultRules);
   }
 
+  @Test void testConvertTypeToSpec() {
+final SqlTypeFactoryImpl factory =
+new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+final RelDataType bigint = factory.createSqlType(SqlTypeName.BIGINT);

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





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




[GitHub] [calcite] Aaaaaaron commented on a change in pull request #2029: [CALCITE-4066] SqlTypeUtil#convertTypeToSpec cover Array/Multiset/Row types.

2020-06-19 Thread GitBox


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



##
File path: core/src/test/java/org/apache/calcite/sql/type/SqlTypeUtilTest.java
##
@@ -117,6 +131,57 @@
 SqlTypeCoercionRule.THREAD_PROVIDERS.set(defaultRules);
   }
 
+  @Test void testConvertTypeToSpec() {
+final SqlTypeFactoryImpl factory =
+new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+final RelDataType bigint = factory.createSqlType(SqlTypeName.BIGINT);

Review comment:
   Thanks for your advice.





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