KazydubB commented on a change in pull request #1782: DRILL-7237: Fix 
single_value aggregate function for variable length types
URL: https://github.com/apache/drill/pull/1782#discussion_r281570250
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
 ##########
 @@ -640,11 +644,107 @@ public void testSingleValueFunction() throws Exception {
   }
 
   @Test
-  public void testSingleValueWithMultipleValuesInput() throws Exception {
+  public void testHashAggSingleValueFunction() throws Exception {
+    List<String> tableNames = Arrays.asList(
+        "cp.`parquet/alltypes_required.parquet`",
+        "cp.`parquet/alltypes_optional.parquet`");
+    for (String tableName : tableNames) {
+      QueryDataBatch result =
+          testSqlWithResults(String.format("select * from %s limit 1", 
tableName)).get(0);
+
+      Map<String, Object> resultingValues = new HashMap<>();
+
+      RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
+      loader.load(result.getHeader().getDef(), result.getData());
+
+      for (VectorWrapper<?> vectorWrapper : loader.getContainer()) {
+        final String fieldName = vectorWrapper.getField().getName();
+        Object object = 
vectorWrapper.getValueVector().getAccessor().getObject(0);
+        // VarCharVector returns Text instance, but baseline values should 
contain String value
+        if (object instanceof Text) {
+          object = object.toString();
+        }
+        resultingValues.put(fieldName, object);
+      }
+      loader.clear();
+      result.release();
+
+      List<Boolean> optionValues = Arrays.asList(true, false);
+
+      try {
+        for (Boolean optionValue : optionValues) {
+          for (Map.Entry<String, Object> entry : resultingValues.entrySet()) {
+            String columnName = String.format("`%s`", entry.getKey());
+
+            // disable interval types when stream agg is disabled due to 
DRILL-7241
+            if (optionValue || !columnName.startsWith("`col_intrvl")) {
+              setSessionOption(PlannerSettings.STREAMAGG.getOptionName(), 
optionValue);
+              testBuilder()
+                  .sqlQuery("select single_value(t.%1$s) as %1$s\n" +
+                      "from (select %1$s from %2$s limit 1) t group by 
t.%1$s", columnName, tableName)
+                  .ordered()
+                  
.baselineRecords(Collections.singletonList(ImmutableMap.of(columnName, 
entry.getValue())))
+                  .go();
+            }
+          }
+        }
+      } finally {
+        resetSessionOption(PlannerSettings.STREAMAGG.getOptionName());
+      }
+    }
+  }
+
+  @Test
+  public void testSingleValueWithComplexInput() throws Exception {
+    String query = "select single_value(t1.a) as any_a, single_value(f) as 
any_f, single_value(m) as any_m," +
+        "single_value(p) as any_p from (select * from 
cp.`store/json/test_anyvalue.json` limit 1) t1";
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("any_a", "any_f", "any_m", "any_p")
+        .baselineValues(TestBuilder.listOf(TestBuilder.mapOf("b", 10L, "c", 
15L),
+            TestBuilder.mapOf("b", 20L, "c", 45L)),
+            TestBuilder.listOf(TestBuilder.mapOf("g", TestBuilder.mapOf("h",
+                TestBuilder.listOf(TestBuilder.mapOf("k", 10L), 
TestBuilder.mapOf("k", 20L))))),
+            TestBuilder.listOf(TestBuilder.mapOf("n", TestBuilder.listOf(1L, 
2L, 3L))),
+            TestBuilder.mapOf("q", TestBuilder.listOf(27L, 28L, 29L)))
+        .go();
+  }
+
+  @Test
+  public void testSingleValueWithMultipleValuesInputsAllTypes() throws 
Exception {
+    List<String> tableNames = Arrays.asList(
+        "cp.`parquet/alltypes_required.parquet`",
+        "cp.`parquet/alltypes_optional.parquet`");
+    for (String tableName : tableNames) {
+      QueryDataBatch result =
+          testSqlWithResults(String.format("select * from %s limit 1", 
tableName)).get(0);
+
+      RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
+      loader.load(result.getHeader().getDef(), result.getData());
+
+      List<String> columns = 
StreamSupport.stream(loader.getContainer().spliterator(), false)
+          .map(vectorWrapper -> vectorWrapper.getField().getName())
+          .collect(Collectors.toList());
+      loader.clear();
+      result.release();
+      for (String columnName : columns) {
+        try {
+          test("select single_value(t.%1$s) as %1$s from %2$s t", columnName, 
tableName);
 
 Review comment:
   Why not use `thrown` field instead of try-catch as is done in method below 
(`testSingleValueWithMultipleComplexInputs`)?

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


With regards,
Apache Git Services

Reply via email to