kgyrtkirk commented on code in PR #15095:
URL: https://github.com/apache/druid/pull/15095#discussion_r1347231825
##########
sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java:
##########
@@ -340,5 +345,47 @@ private static class EarliestLatestSqlAggFunction extends
SqlAggFunction
Optionality.FORBIDDEN
);
}
+
+ @Override
+ public SqlNode rewriteCall(
Review Comment:
I wonder if after this patch constructors of classes like
`LongLastAggregatorFactory` should still accept `timeColumn` as `null` or not
##########
sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java:
##########
@@ -340,5 +345,47 @@ private static class EarliestLatestSqlAggFunction extends
SqlAggFunction
Optionality.FORBIDDEN
);
}
+
+ @Override
+ public SqlNode rewriteCall(
+ SqlValidator validator,
+ SqlCall call
+ )
+ {
+ // Rewrite EARLIEST to EARLIEST_BY and LATEST to LATEST_BY to make
+ // reference to __time column explicit so that Calcite tracks it
+
+ List<SqlNode> operands = call.getOperandList();
+
+ SqlParserPos pos = call.getParserPosition();
+
+ SqlAggFunction aggFunction;
+
+ switch (getName()) {
+ case "EARLIEST":
+ aggFunction =
EarliestLatestBySqlAggregator.EARLIEST_BY.calciteFunction();
+ break;
+ case "LATEST":
+ aggFunction =
EarliestLatestBySqlAggregator.LATEST_BY.calciteFunction();
+ break;
+ default:
+ return call;
+ }
+
+ switch (operands.size()) {
+ case 1:
+ return aggFunction.createCall(pos, operands.get(0), new
SqlIdentifier(
Review Comment:
note:
you could probably use the list constructor of the call; so there is less
duplication
```
List<SqlNode> newOperands = new ArrayList<SqlNode>();
newOperands.add(operands.get(0));
newOperands.add(new SqlIdentifier("__time", pos));
if (operands.size() == 2)
newOperands.add(operands.get(1));
return aggFunction.createCall(pos, newOperands);
```
##########
sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java:
##########
@@ -340,5 +345,47 @@ private static class EarliestLatestSqlAggFunction extends
SqlAggFunction
Optionality.FORBIDDEN
);
}
+
+ @Override
+ public SqlNode rewriteCall(
+ SqlValidator validator,
+ SqlCall call
+ )
+ {
+ // Rewrite EARLIEST to EARLIEST_BY and LATEST to LATEST_BY to make
+ // reference to __time column explicit so that Calcite tracks it
+
+ List<SqlNode> operands = call.getOperandList();
+
+ SqlParserPos pos = call.getParserPosition();
+
+ SqlAggFunction aggFunction;
+
+ switch (getName()) {
Review Comment:
I wonder if this switch is really needed:
* `AggregatorType` is an enum; you could probably save it in the constructor
- so that no string based switch is necessary
* and probably the enum could have a method or something which returns
the other
* or you may also accept a second `AggregatorType` in the constructor ( what
should it be rewritten to) so there will be no question what the "other" should
be....
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]