vvysotskyi commented on a change in pull request #1614: DRILL-6962: Function 
coalesce returns an Error when none of the columns in coalesce exist in a 
parquet file
URL: https://github.com/apache/drill/pull/1614#discussion_r250128642
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
 ##########
 @@ -752,18 +770,59 @@ public void testCastTimeLiteralInFilter() throws 
Exception {
 
   @Test
   public void testCastUntypedNull() throws Exception {
-    String[] types = new String[] {
-        "BOOLEAN", "INT", "BIGINT", "FLOAT", "DOUBLE", "DATE", "TIME", 
"TIMESTAMP", "INTERVAL MONTH",
-        "INTERVAL YEAR", "VARBINARY", "VARCHAR", "DECIMAL(9)", "DECIMAL(18)", 
"DECIMAL(28)", "DECIMAL(38)"
-    };
     String query = "select cast(coalesce(unk1, unk2) as %s) as coal from 
cp.`tpch/nation.parquet` limit 1";
-    for (String type : types) {
+
+    Map<String, Triple<TypeProtos.MinorType, Integer, Integer>> typesMap = 
createCastTypeMap();
+    for (Map.Entry<String, Triple<TypeProtos.MinorType, Integer, Integer>> 
entry : typesMap.entrySet()) {
+      String q = String.format(query, entry.getKey());
+
+      TypeProtos.MinorType minorType = entry.getValue().getLeft();
+      int precision = entry.getValue().getMiddle();
+      int scale = entry.getValue().getRight();
+      MaterializedField field = new ColumnBuilder("coal", minorType)
+          .setMode(TypeProtos.DataMode.OPTIONAL)
+          .setPrecisionAndScale(precision, scale)
+          .build();
+      BatchSchema expectedSchema = new SchemaBuilder()
+          .add(field)
+          .build();
+
+      // Validate schema
+      testBuilder()
+          .sqlQuery(q)
+          .schemaBaseLine(expectedSchema)
+          .go();
+
+      // Validate result
       testBuilder()
-          .sqlQuery(String.format(query, type))
+          .sqlQuery(q)
           .unOrdered()
           .baselineColumns("coal")
           .baselineValues(new Object[] {null})
           .go();
     }
   }
+
+  private static Map<String, Triple<TypeProtos.MinorType, Integer, Integer>> 
createCastTypeMap() {
+    Map<String, Triple<TypeProtos.MinorType, Integer, Integer>> typesMap = new 
HashMap<>();
 
 Review comment:
   It would be better to pass `MaterializedField` instance instead of passing 
`TypeProtos.MinorType, Integer, Integer`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to