This is an automated email from the ASF dual-hosted git repository. xiangfu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push: new d999aec update ScalarFunction annotation from name to names to support function alias. (#8252) d999aec is described below commit d999aeca31ade1fa4f917ef9f5544ee13261ab7c Author: Xiang Fu <xiangfu.1...@gmail.com> AuthorDate: Sat Feb 26 03:01:11 2022 -0800 update ScalarFunction annotation from name to names to support function alias. (#8252) --- .../apache/pinot/common/function/FunctionRegistry.java | 8 ++++++-- .../common/function/FunctionDefinitionRegistryTest.java | 17 +++++++++++++++++ .../apache/pinot/spi/annotations/ScalarFunction.java | 4 +++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/FunctionRegistry.java b/pinot-common/src/main/java/org/apache/pinot/common/function/FunctionRegistry.java index 2d71654..831ece4 100644 --- a/pinot-common/src/main/java/org/apache/pinot/common/function/FunctionRegistry.java +++ b/pinot-common/src/main/java/org/apache/pinot/common/function/FunctionRegistry.java @@ -61,8 +61,12 @@ public class FunctionRegistry { for (Method method : methodSet) { ScalarFunction scalarFunction = method.getAnnotation(ScalarFunction.class); if (scalarFunction.enabled()) { - if (!scalarFunction.name().isEmpty()) { - FunctionRegistry.registerFunction(scalarFunction.name(), method); + // Annotated function names + String[] scalarFunctionNames = scalarFunction.names(); + if (scalarFunctionNames.length > 0) { + for (String name : scalarFunctionNames) { + FunctionRegistry.registerFunction(name, method); + } } else { FunctionRegistry.registerFunction(method); } diff --git a/pinot-common/src/test/java/org/apache/pinot/common/function/FunctionDefinitionRegistryTest.java b/pinot-common/src/test/java/org/apache/pinot/common/function/FunctionDefinitionRegistryTest.java index fd435d8..70a029e 100644 --- a/pinot-common/src/test/java/org/apache/pinot/common/function/FunctionDefinitionRegistryTest.java +++ b/pinot-common/src/test/java/org/apache/pinot/common/function/FunctionDefinitionRegistryTest.java @@ -19,9 +19,12 @@ package org.apache.pinot.common.function; import org.apache.pinot.segment.spi.AggregationFunctionType; +import org.apache.pinot.spi.annotations.ScalarFunction; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -55,4 +58,18 @@ public class FunctionDefinitionRegistryTest { assertTrue(TransformFunctionType.isTransformFunction("STASTEXT")); assertFalse(TransformFunctionType.isTransformFunction("foo_bar")); } + + @ScalarFunction(names = {"testFunc1", "testFunc2"}) + public static String testScalarFunction(long randomArg1, String randomArg2) { + return null; + } + + @Test + public void testScalarFunctionNames() { + assertNotNull(FunctionRegistry.getFunctionInfo("testFunc1", 2)); + assertNotNull(FunctionRegistry.getFunctionInfo("testFunc2", 2)); + assertNull(FunctionRegistry.getFunctionInfo("testScalarFunction", 2)); + assertNull(FunctionRegistry.getFunctionInfo("testFunc1", 1)); + assertNull(FunctionRegistry.getFunctionInfo("testFunc2", 1)); + } } diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java b/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java index 0479c37..8cc1e71 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java @@ -46,5 +46,7 @@ public @interface ScalarFunction { boolean enabled() default true; - String name() default ""; + // If empty, FunctionsRegistry registers the method name as function name; + // If not empty, FunctionsRegistry only registers the function names specified here, the method name is ignored. + String[] names() default {}; } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org