You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2020/06/12 21:05:27 UTC
[incubator-pinot] branch master updated: Add SCALAR type into
TransformFunctionType (#5544)
This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new fcc3144 Add SCALAR type into TransformFunctionType (#5544)
fcc3144 is described below
commit fcc314407acab3fbf9f2ba15b4469ebd7cb41731
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Fri Jun 12 14:05:15 2020 -0700
Add SCALAR type into TransformFunctionType (#5544)
Inside query engine, scalar function is modeled as TransformFunction (ScalarTransformFunctionWrapper)
Add SCALAR type into TransformFunctionType so that FunctionDefinitionRegistry can identify scalar function as transform function
---
.../pinot/common/function/FunctionRegistry.java | 3 +-
.../common/function/TransformFunctionType.java | 8 ++++-
.../function/FunctionDefinitionRegistryTest.java | 34 ++++++++++++++++++++++
.../common/function/TransformFunctionTypeTest.java | 32 ++++++++++++++++++++
4 files changed, 75 insertions(+), 2 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 c8b26cf..712414e 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
@@ -34,7 +34,8 @@ import org.slf4j.LoggerFactory;
/**
- * Registry for in-built Pinot functions
+ * Registry for scalar functions.
+ * <p>TODO: Merge FunctionRegistry and FunctionDefinitionRegistry to provide one single registry for all functions.
*/
public class FunctionRegistry {
private FunctionRegistry() {
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java b/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
index 86d5c8d..879cd43 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
@@ -54,7 +54,10 @@ public enum TransformFunctionType {
DATETRUNC("dateTrunc"),
ARRAYLENGTH("arrayLength"),
VALUEIN("valueIn"),
- MAPVALUE("mapValue");
+ MAPVALUE("mapValue"),
+
+ // Special type for annotation based scalar functions
+ SCALAR("scalar");
private final String _name;
@@ -70,6 +73,9 @@ public enum TransformFunctionType {
try {
return TransformFunctionType.valueOf(upperCaseFunctionName);
} catch (Exception e) {
+ if (FunctionRegistry.getFunctionByName(functionName) != null) {
+ return SCALAR;
+ }
// Support function name of both jsonExtractScalar and json_extract_scalar
if (upperCaseFunctionName.contains("_")) {
return getTransformFunctionType(upperCaseFunctionName.replace("_", ""));
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
new file mode 100644
index 0000000..d81be19
--- /dev/null
+++ b/pinot-common/src/test/java/org/apache/pinot/common/function/FunctionDefinitionRegistryTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.common.function;
+
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+
+public class FunctionDefinitionRegistryTest {
+
+ @Test
+ public void testScalarFunction() {
+ assertFalse(FunctionDefinitionRegistry.isAggFunc("toEpochSeconds"));
+ assertTrue(FunctionDefinitionRegistry.isTransformFunc("toEpochSeconds"));
+ }
+}
diff --git a/pinot-common/src/test/java/org/apache/pinot/common/function/TransformFunctionTypeTest.java b/pinot-common/src/test/java/org/apache/pinot/common/function/TransformFunctionTypeTest.java
new file mode 100644
index 0000000..64fe7e3
--- /dev/null
+++ b/pinot-common/src/test/java/org/apache/pinot/common/function/TransformFunctionTypeTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.common.function;
+
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+public class TransformFunctionTypeTest {
+
+ @Test
+ public void testScalarFunction() {
+ assertEquals(TransformFunctionType.getTransformFunctionType("toEpochSeconds"), TransformFunctionType.SCALAR);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org