KKcorps commented on a change in pull request #8304: URL: https://github.com/apache/pinot/pull/8304#discussion_r828766021
########## File path: pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java ########## @@ -57,12 +57,20 @@ public LiteralTransformFunction(String literal) { _literal = literal; _dataType = inferLiteralDataType(literal); + double mathLiteral; if (_dataType.isNumeric()) { BigDecimal bigDecimal = new BigDecimal(_literal); _intLiteral = bigDecimal.intValue(); _longLiteral = bigDecimal.longValue(); _floatLiteral = bigDecimal.floatValue(); _doubleLiteral = bigDecimal.doubleValue(); + } else if ((mathLiteral = getMathConstant(literal)) != 0) { Review comment: Ok. Yeah, I get for e.g. in a function like `startsWith(colA, 'E')` we should not be replacing `E` with Euler's constant. ########## File path: pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java ########## @@ -104,4 +111,30 @@ public static double ln(double a) { public static double sqrt(double a) { return Math.sqrt(a); } + + @ScalarFunction + public static double sign(double a) { + return Math.signum(a); + } + + @ScalarFunction + public static double pi() { return Math.PI; } + + @ScalarFunction + public static double e() { return Math.E; } + + @ScalarFunction + public static double power(double a, double b) { + return Math.pow(a, b); + } + + @ScalarFunction + public static double log(double a) { + return Math.log10(a); + } Review comment: @mneedham I had discussion with @Jackie-Jiang in which he confirmed that Pinot prioritises TransformFunctions first and if not found, it will use ScalarFunctions. Both can have the same name. The following piece of code in TransformFunctionFactory ensures this order. ``` TransformFunction transformFunction; Class<? extends TransformFunction> transformFunctionClass = TRANSFORM_FUNCTION_MAP.get(functionName); if (transformFunctionClass != null) { // Transform function try { transformFunction = transformFunctionClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Caught exception while constructing transform function: " + functionName, e); } } else { // Scalar function FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); if (functionInfo == null) { if (FunctionRegistry.containsFunction(functionName)) { throw new BadQueryRequestException( String.format("Unsupported function: %s with %d parameters", functionName, numArguments)); } else { throw new BadQueryRequestException( String.format("Unsupported function: %s not found", functionName)); } } transformFunction = new ScalarTransformFunctionWrapper(functionInfo); } ``` ########## File path: pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java ########## @@ -104,4 +111,30 @@ public static double ln(double a) { public static double sqrt(double a) { return Math.sqrt(a); } + + @ScalarFunction + public static double sign(double a) { + return Math.signum(a); + } + + @ScalarFunction + public static double pi() { return Math.PI; } + + @ScalarFunction + public static double e() { return Math.E; } + + @ScalarFunction + public static double power(double a, double b) { + return Math.pow(a, b); + } + + @ScalarFunction + public static double log(double a) { + return Math.log10(a); + } Review comment: @mneedham I had discussion with @Jackie-Jiang in which he confirmed that Pinot prioritises TransformFunctions first and if not found, it will use ScalarFunctions. Both can have the same name. The following piece of code in TransformFunctionFactory ensures this order. ```java TransformFunction transformFunction; Class<? extends TransformFunction> transformFunctionClass = TRANSFORM_FUNCTION_MAP.get(functionName); if (transformFunctionClass != null) { // Transform function try { transformFunction = transformFunctionClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Caught exception while constructing transform function: " + functionName, e); } } else { // Scalar function FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); if (functionInfo == null) { if (FunctionRegistry.containsFunction(functionName)) { throw new BadQueryRequestException( String.format("Unsupported function: %s with %d parameters", functionName, numArguments)); } else { throw new BadQueryRequestException( String.format("Unsupported function: %s not found", functionName)); } } transformFunction = new ScalarTransformFunctionWrapper(functionInfo); } ``` ########## File path: pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java ########## @@ -104,4 +111,30 @@ public static double ln(double a) { public static double sqrt(double a) { return Math.sqrt(a); } + + @ScalarFunction + public static double sign(double a) { + return Math.signum(a); + } + + @ScalarFunction + public static double pi() { return Math.PI; } + + @ScalarFunction + public static double e() { return Math.E; } + + @ScalarFunction + public static double power(double a, double b) { + return Math.pow(a, b); + } + + @ScalarFunction + public static double log(double a) { + return Math.log10(a); + } Review comment: @mneedham I had discussion with @Jackie-Jiang in which he confirmed that Pinot prioritises TransformFunctions first and if not found, it will use ScalarFunctions. Both can have the same name. The following piece of code in `TransformFunctionFactory` ensures this order. ```java TransformFunction transformFunction; Class<? extends TransformFunction> transformFunctionClass = TRANSFORM_FUNCTION_MAP.get(functionName); if (transformFunctionClass != null) { // Transform function try { transformFunction = transformFunctionClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Caught exception while constructing transform function: " + functionName, e); } } else { // Scalar function FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments); if (functionInfo == null) { if (FunctionRegistry.containsFunction(functionName)) { throw new BadQueryRequestException( String.format("Unsupported function: %s with %d parameters", functionName, numArguments)); } else { throw new BadQueryRequestException( String.format("Unsupported function: %s not found", functionName)); } } transformFunction = new ScalarTransformFunctionWrapper(functionInfo); } ``` -- 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-unsubscr...@pinot.apache.org 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