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/04/17 00:30:33 UTC

[GitHub] [druid] clintropolis commented on a change in pull request #11104: expression aggregator

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



##########
File path: core/src/main/java/org/apache/druid/math/expr/Function.java
##########
@@ -460,6 +474,118 @@ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
     abstract ExprEval doApply(ExprEval lhsExpr, ExprEval rhsExpr);
   }
 
+  /**
+   * Scaffolding for a 2 argument {@link Function} which accepts one array and one scalar input and adds the scalar
+   * input to the array in some way.
+   */
+  abstract class ArrayAddElementFunction extends ArrayScalarFunction
+  {
+    @Override
+    public boolean hasArrayOutput()
+    {
+      return true;
+    }
+
+    @Nullable
+    @Override
+    public ExprType getOutputType(Expr.InputBindingInspector inspector, List<Expr> args)
+    {
+      ExprType arrayType = getArrayArgument(args).getOutputType(inspector);
+      return Optional.ofNullable(ExprType.asArrayType(arrayType)).orElse(arrayType);
+    }
+
+    @Override
+    ExprEval doApply(ExprEval arrayExpr, ExprEval scalarExpr)
+    {
+      switch (arrayExpr.type()) {
+        case STRING:
+        case STRING_ARRAY:
+          return ExprEval.ofStringArray(add(arrayExpr.asStringArray(), scalarExpr.asString()).toArray(String[]::new));

Review comment:
       Ah this behavior of array functions making new arrays isn't really new, I just refactored some things to better re-use code. But yeah efficiency is not great. I don't really have any concrete solutions yet of how to make it better, at least for non-vectorized expressions, but I will think about it and try to leave a comment.




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



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