You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2019/05/07 11:11:49 UTC

[GitHub] [drill] KazydubB commented on a change in pull request #1782: DRILL-7237: Fix single_value aggregate function for variable length types

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_r281573912
 
 

 ##########
 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," +
 
 Review comment:
   ```suggestion
       String query = "select single_value(a) as any_a, single_value(f) as any_f, single_value(m) as any_m," +
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services