Jackie-Jiang commented on a change in pull request #5440:
URL: https://github.com/apache/incubator-pinot/pull/5440#discussion_r432782384



##########
File path: pinot-common/pom.xml
##########
@@ -33,6 +33,7 @@
   <url>https://pinot.apache.org/</url>
   <properties>
     <pinot.root>${basedir}/..</pinot.root>
+    <reflections.version>0.9.11</reflections.version>

Review comment:
       Move the version info into the root pom file

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
##########
@@ -112,13 +115,24 @@ public static TransformFunction 
get(TransformExpressionTree expression, Map<Stri
     switch (expression.getExpressionType()) {
       case FUNCTION:
         String functionName = expression.getValue();
-        Class<? extends TransformFunction> transformFunctionClass = 
TRANSFORM_FUNCTION_MAP.get(functionName);
+        Class<? extends TransformFunction> transformFunctionClass;
+        FunctionInfo functionInfo = null;
+        if (FunctionRegistry.containsFunctionByName(functionName)) {
+          transformFunctionClass = ScalarTransformFunctionWrapper.class;
+          functionInfo = FunctionRegistry.getFunctionByName(functionName);
+        } else {
+          transformFunctionClass = TRANSFORM_FUNCTION_MAP.get(functionName);
+        }
+
         if (transformFunctionClass == null) {
           throw new BadQueryRequestException("Unsupported transform function: 
" + functionName);
         }
         try {
           transformFunction = transformFunctionClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+          if (functionInfo != null) {
+            ((ScalarTransformFunctionWrapper) 
transformFunction).setFunction(functionName, functionInfo);

Review comment:
       Suggest using a constructor with `functionName` and `functionInfo` 
instead of using `newInstance()`

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;
+  String _name;
+  Object[] _args;
+  List<Integer> _nonLiteralArgIndices;
+  List<FieldSpec.DataType> _nonLiteralArgType;
+  List<TransformFunction> _nonLiteralTransformFunction;
+  TransformResultMetadata _transformResultMetadata;
+  String[] _stringResult;
+  int[] _integerResult;
+  float[] _floatResult;
+  double[] _doubleResult;
+  long[] _longResult;
+
+  public ScalarTransformFunctionWrapper() {
+    _nonLiteralArgIndices = new ArrayList<>();
+    _nonLiteralArgType = new ArrayList<>();
+    _nonLiteralTransformFunction = new ArrayList<>();
+  }
+
+  @Override
+  public String getName() {
+    return _name;
+  }
+
+  public void setFunction(String functionName, FunctionInfo info)
+      throws Exception {
+    _name = functionName;
+    _functionInvoker = new FunctionInvoker(info);
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    Preconditions.checkArgument(arguments.size() == 
_functionInvoker.getParameterTypes().length,
+        "The number of arguments are not same for scalar function and 
transform function: %s", getName());
+
+    _args = new Object[arguments.size()];
+    for (int i = 0; i < arguments.size(); i++) {
+      TransformFunction function = arguments.get(i);
+      if (function instanceof LiteralTransformFunction) {
+        String literal = ((LiteralTransformFunction) function).getLiteral();
+        Class paramType = _functionInvoker.getParameterTypes()[i];
+        switch (paramType.getTypeName()) {

Review comment:
       For readability, can we always order them as INT, LONG, FLOAT, DOUBLE, 
STRING? Same for other places

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/FunctionRegistry.java
##########
@@ -53,8 +61,12 @@ public static FunctionInfo 
getFunctionByNameWithApplicableArgumentTypes(String f
   }
 
   public static void registerFunction(Method method) {
+    registerFunction(method, method.getName().toLowerCase());
+  }
+
+  public static void registerFunction(Method method, String name) {

Review comment:
       (nit) Suggest putting `name` in front of `method`

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;
+  String _name;
+  Object[] _args;
+  List<Integer> _nonLiteralArgIndices;
+  List<FieldSpec.DataType> _nonLiteralArgType;
+  List<TransformFunction> _nonLiteralTransformFunction;
+  TransformResultMetadata _transformResultMetadata;
+  String[] _stringResult;
+  int[] _integerResult;
+  float[] _floatResult;
+  double[] _doubleResult;
+  long[] _longResult;
+
+  public ScalarTransformFunctionWrapper() {
+    _nonLiteralArgIndices = new ArrayList<>();
+    _nonLiteralArgType = new ArrayList<>();
+    _nonLiteralTransformFunction = new ArrayList<>();
+  }
+
+  @Override
+  public String getName() {
+    return _name;
+  }
+
+  public void setFunction(String functionName, FunctionInfo info)
+      throws Exception {
+    _name = functionName;
+    _functionInvoker = new FunctionInvoker(info);
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    Preconditions.checkArgument(arguments.size() == 
_functionInvoker.getParameterTypes().length,
+        "The number of arguments are not same for scalar function and 
transform function: %s", getName());
+
+    _args = new Object[arguments.size()];

Review comment:
       (nit) Use a local variable `int numArguments = arguments.size()`

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;
+  String _name;
+  Object[] _args;
+  List<Integer> _nonLiteralArgIndices;
+  List<FieldSpec.DataType> _nonLiteralArgType;
+  List<TransformFunction> _nonLiteralTransformFunction;
+  TransformResultMetadata _transformResultMetadata;
+  String[] _stringResult;
+  int[] _integerResult;
+  float[] _floatResult;
+  double[] _doubleResult;
+  long[] _longResult;
+
+  public ScalarTransformFunctionWrapper() {
+    _nonLiteralArgIndices = new ArrayList<>();
+    _nonLiteralArgType = new ArrayList<>();
+    _nonLiteralTransformFunction = new ArrayList<>();
+  }
+
+  @Override
+  public String getName() {
+    return _name;
+  }
+
+  public void setFunction(String functionName, FunctionInfo info)
+      throws Exception {
+    _name = functionName;
+    _functionInvoker = new FunctionInvoker(info);
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    Preconditions.checkArgument(arguments.size() == 
_functionInvoker.getParameterTypes().length,
+        "The number of arguments are not same for scalar function and 
transform function: %s", getName());
+
+    _args = new Object[arguments.size()];
+    for (int i = 0; i < arguments.size(); i++) {
+      TransformFunction function = arguments.get(i);
+      if (function instanceof LiteralTransformFunction) {
+        String literal = ((LiteralTransformFunction) function).getLiteral();
+        Class paramType = _functionInvoker.getParameterTypes()[i];

Review comment:
       Suggest directly comparing class instead of String comparison for both 
performance and readability:
   ```
   if (paramType == Integer.class) {
     ...
   } else if (paramType == Long.class) {
    ...
   ```

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;

Review comment:
       Add `private` or `private final` for these member variables

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
##########
@@ -112,13 +115,24 @@ public static TransformFunction 
get(TransformExpressionTree expression, Map<Stri
     switch (expression.getExpressionType()) {
       case FUNCTION:
         String functionName = expression.getValue();
-        Class<? extends TransformFunction> transformFunctionClass = 
TRANSFORM_FUNCTION_MAP.get(functionName);
+        Class<? extends TransformFunction> transformFunctionClass;
+        FunctionInfo functionInfo = null;
+        if (FunctionRegistry.containsFunctionByName(functionName)) {
+          transformFunctionClass = ScalarTransformFunctionWrapper.class;
+          functionInfo = FunctionRegistry.getFunctionByName(functionName);
+        } else {
+          transformFunctionClass = TRANSFORM_FUNCTION_MAP.get(functionName);
+        }
+
         if (transformFunctionClass == null) {
           throw new BadQueryRequestException("Unsupported transform function: 
" + functionName);
         }
         try {
           transformFunction = transformFunctionClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+          if (functionInfo != null) {
+            ((ScalarTransformFunctionWrapper) 
transformFunction).setFunction(functionName, functionInfo);
+          }
+        } catch (Exception e) {

Review comment:
       Don't catch all Exceptions because it will also catch the 
BadQueryRequestException. We treat BadQueryRequestException differently on the 
caller side

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {

Review comment:
       Rename it to `ScalarTransformFunction`?

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;
+  String _name;
+  Object[] _args;
+  List<Integer> _nonLiteralArgIndices;
+  List<FieldSpec.DataType> _nonLiteralArgType;
+  List<TransformFunction> _nonLiteralTransformFunction;
+  TransformResultMetadata _transformResultMetadata;
+  String[] _stringResult;
+  int[] _integerResult;
+  float[] _floatResult;
+  double[] _doubleResult;
+  long[] _longResult;
+
+  public ScalarTransformFunctionWrapper() {
+    _nonLiteralArgIndices = new ArrayList<>();
+    _nonLiteralArgType = new ArrayList<>();
+    _nonLiteralTransformFunction = new ArrayList<>();
+  }
+
+  @Override
+  public String getName() {
+    return _name;
+  }
+
+  public void setFunction(String functionName, FunctionInfo info)

Review comment:
       Suggest merging this into the constructor

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/ScalarTransformFunctionWrapper.java
##########
@@ -0,0 +1,301 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.FunctionInfo;
+import org.apache.pinot.common.function.FunctionInvoker;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class ScalarTransformFunctionWrapper extends BaseTransformFunction {
+
+  FunctionInvoker _functionInvoker;
+  String _name;
+  Object[] _args;
+  List<Integer> _nonLiteralArgIndices;
+  List<FieldSpec.DataType> _nonLiteralArgType;
+  List<TransformFunction> _nonLiteralTransformFunction;
+  TransformResultMetadata _transformResultMetadata;
+  String[] _stringResult;
+  int[] _integerResult;
+  float[] _floatResult;
+  double[] _doubleResult;
+  long[] _longResult;
+
+  public ScalarTransformFunctionWrapper() {
+    _nonLiteralArgIndices = new ArrayList<>();
+    _nonLiteralArgType = new ArrayList<>();
+    _nonLiteralTransformFunction = new ArrayList<>();
+  }
+
+  @Override
+  public String getName() {
+    return _name;
+  }
+
+  public void setFunction(String functionName, FunctionInfo info)
+      throws Exception {
+    _name = functionName;
+    _functionInvoker = new FunctionInvoker(info);
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    Preconditions.checkArgument(arguments.size() == 
_functionInvoker.getParameterTypes().length,
+        "The number of arguments are not same for scalar function and 
transform function: %s", getName());
+
+    _args = new Object[arguments.size()];
+    for (int i = 0; i < arguments.size(); i++) {
+      TransformFunction function = arguments.get(i);
+      if (function instanceof LiteralTransformFunction) {
+        String literal = ((LiteralTransformFunction) function).getLiteral();
+        Class paramType = _functionInvoker.getParameterTypes()[i];
+        switch (paramType.getTypeName()) {
+          case "java.lang.Integer":
+            _args[i] = Integer.parseInt(literal);
+            break;
+          case "java.lang.String":
+            _args[i] = literal;
+            break;
+          case "java.lang.Double":
+            _args[i] = Double.valueOf(literal);
+            break;
+          case "java.lang.Float":
+            _args[i] = Float.valueOf(literal);
+            break;
+          case "java.lang.Long":
+            _args[i] = Long.valueOf(literal);
+            break;
+          default:
+            throw new RuntimeException(
+                "Unsupported data type " + paramType.getTypeName() + "for 
transform function " + getName());
+        }
+      } else {
+        _nonLiteralArgIndices.add(i);
+        _nonLiteralTransformFunction.add(function);
+        Class paramType = _functionInvoker.getParameterTypes()[i];
+
+        switch (paramType.getTypeName()) {
+          case "java.lang.Integer":
+            _nonLiteralArgType.add(FieldSpec.DataType.INT);
+            break;
+          case "java.lang.String":
+            _nonLiteralArgType.add(FieldSpec.DataType.STRING);
+            break;
+          case "java.lang.Double":
+            _nonLiteralArgType.add(FieldSpec.DataType.DOUBLE);
+            break;
+          case "java.lang.Float":
+            _nonLiteralArgType.add(FieldSpec.DataType.FLOAT);
+            break;
+          case "java.lang.Long":
+            _nonLiteralArgType.add(FieldSpec.DataType.LONG);
+            break;
+          default:
+            throw new RuntimeException(
+                "Unsupported data type " + paramType.getTypeName() + "for 
transform function " + getName());
+        }
+      }
+    }
+
+    Class returnType = _functionInvoker.getReturnType();
+    switch(returnType.getTypeName()) {
+      case "java.lang.Integer":
+        _transformResultMetadata =  INT_SV_NO_DICTIONARY_METADATA;
+        break;
+      case "java.lang.Long":
+        _transformResultMetadata =  LONG_SV_NO_DICTIONARY_METADATA;
+        break;
+      case "java.lang.Float":
+      case "java.lang.Double":
+        _transformResultMetadata =  DOUBLE_SV_NO_DICTIONARY_METADATA;
+        break;
+      case "java.lang.Boolean":
+      case "java.lang.String":
+        _transformResultMetadata =  STRING_SV_NO_DICTIONARY_METADATA;
+        break;
+      default:
+        throw new RuntimeException("Unsupported data type " + 
returnType.getTypeName() + "for transform function " + getName());
+    }
+  }
+
+  @Override
+  public TransformResultMetadata getResultMetadata() {
+    return _transformResultMetadata;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public int[] transformToIntValuesSV(ProjectionBlock projectionBlock) {
+    if (_integerResult == null) {
+      _integerResult = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+    int length = projectionBlock.getNumDocs();
+    int numNonLiteralArgs = _nonLiteralArgIndices.size();
+    Object[][] nonLiteralBlockValues = new Object[numNonLiteralArgs][];
+
+    transformNonLiteralArgsToValues(projectionBlock, numNonLiteralArgs, 
nonLiteralBlockValues);
+
+    //now invoke the actual function
+    for (int i = 0; i < length; i++) {
+      for (int k = 0; k < numNonLiteralArgs; k++) {
+        _args[_nonLiteralArgIndices.get(k)] = nonLiteralBlockValues[k][i];
+      }
+      _integerResult[i] = (Integer) _functionInvoker.process(_args);
+    }
+    return _integerResult;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public long[] transformToLongValuesSV(ProjectionBlock projectionBlock) {
+    if (_longResult == null) {
+      _longResult = new long[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+    int length = projectionBlock.getNumDocs();
+    int numNonLiteralArgs = _nonLiteralArgIndices.size();
+    Object[][] nonLiteralBlockValues = new Object[numNonLiteralArgs][];
+
+    transformNonLiteralArgsToValues(projectionBlock, numNonLiteralArgs, 
nonLiteralBlockValues);
+
+    //now invoke the actual function
+    for (int i = 0; i < length; i++) {
+      for (int k = 0; k < numNonLiteralArgs; k++) {
+        _args[_nonLiteralArgIndices.get(k)] = nonLiteralBlockValues[k][i];
+      }
+      _longResult[i] = (Long) _functionInvoker.process(_args);
+    }
+    return _longResult;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public float[] transformToFloatValuesSV(ProjectionBlock projectionBlock) {
+    if (_floatResult == null) {
+      _floatResult = new float[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+    int length = projectionBlock.getNumDocs();
+    int numNonLiteralArgs = _nonLiteralArgIndices.size();
+    Object[][] nonLiteralBlockValues = new Object[numNonLiteralArgs][];
+
+    transformNonLiteralArgsToValues(projectionBlock, numNonLiteralArgs, 
nonLiteralBlockValues);
+
+    //now invoke the actual function
+    for (int i = 0; i < length; i++) {
+      for (int k = 0; k < numNonLiteralArgs; k++) {
+        _args[_nonLiteralArgIndices.get(k)] = nonLiteralBlockValues[k][i];
+      }
+      _floatResult[i] = (Float) _functionInvoker.process(_args);
+    }
+    return _floatResult;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public double[] transformToDoubleValuesSV(ProjectionBlock projectionBlock) {
+    if (_doubleResult == null) {
+      _doubleResult = new double[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+    int length = projectionBlock.getNumDocs();
+    int numNonLiteralArgs = _nonLiteralArgIndices.size();
+    Object[][] nonLiteralBlockValues = new Object[numNonLiteralArgs][];
+
+    transformNonLiteralArgsToValues(projectionBlock, numNonLiteralArgs, 
nonLiteralBlockValues);
+
+    //now invoke the actual function
+    for (int i = 0; i < length; i++) {
+      for (int k = 0; k < numNonLiteralArgs; k++) {
+        _args[_nonLiteralArgIndices.get(k)] = nonLiteralBlockValues[k][i];
+      }
+      _doubleResult[i] = (Double) _functionInvoker.process(_args);
+    }
+    return _doubleResult;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public String[] transformToStringValuesSV(ProjectionBlock projectionBlock) {
+    if (_stringResult == null) {
+      _stringResult = new String[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+
+    int length = projectionBlock.getNumDocs();
+    int numNonLiteralArgs = _nonLiteralArgIndices.size();
+    Object[][] nonLiteralBlockValues = new Object[numNonLiteralArgs][];
+
+    transformNonLiteralArgsToValues(projectionBlock, numNonLiteralArgs, 
nonLiteralBlockValues);
+
+    //now invoke the actual function
+    for (int i = 0; i < length; i++) {
+      for (int k = 0; k < numNonLiteralArgs; k++) {
+        _args[_nonLiteralArgIndices.get(k)] = nonLiteralBlockValues[k][i];
+      }
+      _stringResult[i] = (String) _functionInvoker.process(_args);
+    }
+
+    return _stringResult;
+  }
+
+  private void transformNonLiteralArgsToValues(ProjectionBlock 
projectionBlock, int numNonLiteralArgs,
+      Object[][] nonLiteralBlockValues) {
+    for (int i = 0; i < numNonLiteralArgs; i++) {
+      TransformFunction transformFunc = _nonLiteralTransformFunction.get(i);
+      FieldSpec.DataType returnType = _nonLiteralArgType.get(i);
+      switch (returnType) {
+        case STRING:
+          nonLiteralBlockValues[i] = 
transformFunc.transformToStringValuesSV(projectionBlock);
+          break;
+        case INT:
+          int[] values = transformFunc.transformToIntValuesSV(projectionBlock);
+          nonLiteralBlockValues[i] = 
Arrays.stream(values).boxed().toArray(Integer[]::new);
+          break;
+        case DOUBLE:
+          double[] doubleValues = 
transformFunc.transformToDoubleValuesSV(projectionBlock);
+          nonLiteralBlockValues[i] = 
Arrays.stream(doubleValues).boxed().toArray(Double[]::new);
+          break;
+        case FLOAT:
+          float[] floatValues = 
transformFunc.transformToFloatValuesSV(projectionBlock);

Review comment:
       Why using different way to box the values?
   I would suggest changing all types to be the same as FLOAT. From the past 
experience, seems the streaming fashion has worse performance.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to