This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 3e686f4306 [feature](javaudf)support no input java udf (#24457)
3e686f4306 is described below
commit 3e686f43067a2f0e3b11b7de6a3342b3a0ac703c
Author: lsy3993 <[email protected]>
AuthorDate: Mon Sep 25 18:56:44 2023 +0800
[feature](javaudf)support no input java udf (#24457)
* support no input java udf
* add license
---
fe/fe-core/src/main/cup/sql_parser.cup | 5 +-
.../data/javaudf_p0/test_javaudf_no_input.out | 23 +++++++
.../java/org/apache/doris/udf/NoInputTest.java | 24 +++++++
.../suites/javaudf_p0/test_javaudf_no_input.groovy | 75 ++++++++++++++++++++++
4 files changed, 123 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index 15626ed00e..72c99d3fbb 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -6450,10 +6450,7 @@ type_def_nullable_list ::=
func_args_def ::=
- /* empty */
- {:
- RESULT = new FunctionArgsDef(Lists.newArrayList(), false);
- :}
+ {: RESULT = new FunctionArgsDef(Lists.newArrayList(), false); :}
| type_def_list:argTypes
{:
RESULT = new FunctionArgsDef(argTypes, false);
diff --git a/regression-test/data/javaudf_p0/test_javaudf_no_input.out
b/regression-test/data/javaudf_p0/test_javaudf_no_input.out
new file mode 100644
index 0000000000..f6fcfc54da
--- /dev/null
+++ b/regression-test/data/javaudf_p0/test_javaudf_no_input.out
@@ -0,0 +1,23 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_default --
+1 1 abcdefg1 poiuytre1abcdefg
+2 2 abcdefg2 poiuytre2abcdefg
+0 3 abcdefg3 poiuytre3abcdefg
+1 4 abcdefg4 poiuytre4abcdefg
+2 5 abcdefg5 poiuytre5abcdefg
+0 6 abcdefg6 poiuytre6abcdefg
+1 7 abcdefg7 poiuytre7abcdefg
+2 8 abcdefg8 poiuytre8abcdefg
+9 9 abcdefg9 poiuytre9abcdefg
+
+-- !select1 --
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+no input
+
diff --git
a/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NoInputTest.java
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NoInputTest.java
new file mode 100644
index 0000000000..d374e37252
--- /dev/null
+++
b/regression-test/java-udf-src/src/main/java/org/apache/doris/udf/NoInputTest.java
@@ -0,0 +1,24 @@
+// 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.doris.udf;
+
+public class NoInputTest {
+ public String evaluate() {
+ return "no input";
+ }
+}
+
diff --git a/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
b/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
new file mode 100644
index 0000000000..fd3e74e213
--- /dev/null
+++ b/regression-test/suites/javaudf_p0/test_javaudf_no_input.groovy
@@ -0,0 +1,75 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.Files
+import java.nio.file.Paths
+
+suite("test_javaudf_no_input") {
+ def tableName = "test_javaudf_no_input"
+ def jarPath =
"""${context.file.parent}/jars/java-udf-case-jar-with-dependencies.jar"""
+
+
+ log.info("Jar path: ${jarPath}".toString())
+ try {
+ sql """ DROP TABLE IF EXISTS ${tableName} """
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ `user_id` INT NOT NULL COMMENT "用户id",
+ `char_col` CHAR NOT NULL COMMENT "",
+ `varchar_col` VARCHAR(10) NOT NULL COMMENT "",
+ `string_col` STRING NOT NULL COMMENT ""
+ )
+ DISTRIBUTED BY HASH(user_id) PROPERTIES("replication_num" = "1");
+ """
+ StringBuilder sb = new StringBuilder()
+ int i = 1
+ for (; i < 9; i ++) {
+ sb.append("""
+ (${i % 3}, '${i}','abcdefg${i}','poiuytre${i}abcdefg'),
+ """)
+ }
+ sb.append("""
+ (${i}, '${i}','abcdefg${i}','poiuytre${i}abcdefg')
+ """)
+ sql """ INSERT INTO ${tableName} VALUES
+ ${sb.toString()}
+ """
+ qt_select_default """ SELECT * FROM ${tableName} t ORDER BY char_col;
"""
+
+ File path = new File(jarPath)
+ if (!path.exists()) {
+ throw new IllegalStateException("""${jarPath} doesn't exist! """)
+ }
+
+ sql """ CREATE FUNCTION no_input_udf() RETURNS String PROPERTIES (
+ "file"="file://${jarPath}",
+ "symbol"="org.apache.doris.udf.NoInputTest",
+ "always_nullable"="true",
+ "type"="JAVA_UDF"
+ ); """
+
+ qt_select1 """ SELECT no_input_udf() FROM ${tableName}; """
+
+ } finally {
+ try_sql("DROP FUNCTION IF EXISTS no_input_udf();")
+ try_sql("DROP TABLE IF EXISTS ${tableName}")
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]