You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/11/19 04:35:24 UTC

[GitHub] [druid] clintropolis commented on a change in pull request #11949: Specify time column for first/last aggregators

clintropolis commented on a change in pull request #11949:
URL: https://github.com/apache/druid/pull/11949#discussion_r752856348



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
##########
@@ -262,6 +306,17 @@ public RelDataType inferReturnType(SqlOperatorBinding sqlOperatorBinding)
                   "'" + aggregatorType.name() + "(expr, maxBytesPerString)'\n",
                   OperandTypes.ANY,
                   OperandTypes.and(OperandTypes.NUMERIC, OperandTypes.LITERAL)
+              ),
+              OperandTypes.sequence(
+                  "'" + aggregatorType.name() + "(expr, timeColumn)'\n",
+                  OperandTypes.ANY,
+                  OperandTypes.ANY

Review comment:
       any seems a bit permissive, since i think this probably needs to be a long?

##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java
##########
@@ -206,19 +195,74 @@ public Aggregation toDruidAggregation(
       );
     }
 
+    final String fieldName = getColumnName(plannerContext, virtualColumnRegistry, args.get(0), rexNodes.get(0));
+
+    final AggregatorFactory theAggFactory;
+    switch (args.size()) {
+      case 1:
+        theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, -1);
+        break;
+      case 2:
+        if (outputType.anyOf(ValueType.STRING, ValueType.COMPLEX)) {

Review comment:
       nit: might be worth a comment that this is to handle 2nd argument as either byte size or time column, depending on the input type to make it a bit easier to make sense of what's going on here.
   
   I think you could also potentially just make this check be `!outputType.isNumeric()` since those are fixed width and don't have a size limit

##########
File path: processing/src/main/java/org/apache/druid/query/aggregation/first/DoubleFirstAggregatorFactory.java
##########
@@ -256,20 +259,28 @@ public String getFieldName()
     return fieldName;
   }
 
+  @JsonProperty
+  public String getTimeColumn()
+  {
+    return timeColumn;
+  }
+
   @Override
   public List<String> requiredFields()
   {
-    return Arrays.asList(ColumnHolder.TIME_COLUMN_NAME, fieldName);
+    return Arrays.asList(timeColumn, fieldName);
   }
 
   @Override
   public byte[] getCacheKey()
   {
     byte[] fieldNameBytes = StringUtils.toUtf8(fieldName);
+    byte[] timeColumnBytes = StringUtils.toUtf8(timeColumn);

Review comment:
       nit: maybe a good opportunity to switch to `CacheKeyBuilder`? (same comment for all other aggs)




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

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org