This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f5a674c68d8 fix:Support Hive CREATE FUNCTION statement parse (#36193)
f5a674c68d8 is described below
commit f5a674c68d81e3ff411180bc7b96143e899d8ef0
Author: Claire <[email protected]>
AuthorDate: Wed Aug 6 13:01:19 2025 +0800
fix:Support Hive CREATE FUNCTION statement parse (#36193)
* support hive create function statement
* update RELEASE-NOTES
---
RELEASE-NOTES.md | 1 +
.../src/main/antlr4/imports/hive/DDLStatement.g4 | 27 ++++++++++++++++++++++
.../src/main/antlr4/imports/hive/HiveKeyword.g4 | 4 ++++
.../sql/parser/autogen/HiveStatement.g4 | 1 +
.../statement/type/HiveDDLStatementVisitor.java | 7 ++++++
.../main/resources/case/ddl/create-function.xml | 9 ++++++++
.../sql/supported/ddl/create-function.xml | 9 ++++++++
7 files changed, 58 insertions(+)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index f1057a0114f..f29fb87ac67 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -71,6 +71,7 @@
1. SQL Parser: Support Hive ALTER INDEX statement parse -
[#36167](https://github.com/apache/shardingsphere/pull/36167)
1. SQL Parser: Support Hive CREATE MACRO statement parse -
[#36181](https://github.com/apache/shardingsphere/pull/36181)
1. SQL Parser: Support Hive DROP MACRO statement parse -
[#36187](https://github.com/apache/shardingsphere/pull/36187)
+1. SQL Parser: Support Hive CREATE FUNCTION statement parse -
[#36193](https://github.com/apache/shardingsphere/pull/36193)
1. SQL Parser: Support SQL Server xml methods parse -
[#35911](https://github.com/apache/shardingsphere/pull/35911)
1. SQL Parser: Support SQL Server CHANGETABLE function parse -
[#35920](https://github.com/apache/shardingsphere/pull/35920)
1. SQL Parser: Support SQL Server AI_GENERATE_EMBEDDINGS function parse -
[#35922](https://github.com/apache/shardingsphere/pull/35922)
diff --git
a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
index 313b72fa425..a9b472bc36a 100644
--- a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
+++ b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4
@@ -124,6 +124,11 @@ dropMacro
: DROP TEMPORARY MACRO ifExists? macroName
;
+createFunction
+ : CREATE TEMPORARY FUNCTION functionName AS className
+ | CREATE FUNCTION functionName AS className createFunctionOptions?
+ ;
+
alterDatabaseSpecification_
: SET DBPROPERTIES LP_ dbProperties RP_
| SET OWNER (USER | ROLE) identifier
@@ -492,3 +497,25 @@ macroParameterList
macroParameter
: columnName dataTypeClause
;
+
+className
+ : string_
+ ;
+
+resourcePath
+ : string_
+ ;
+
+resourceClause
+ : JAR resourcePath
+ | FILE resourcePath
+ | ARCHIVE resourcePath
+ ;
+
+createFunctionOption
+ : (COMMA_ resourceClause)*
+ ;
+
+createFunctionOptions
+ : USING resourceClause createFunctionOption
+ ;
diff --git
a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
index 55335adc633..e3f25887ae3 100644
--- a/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
+++ b/parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4
@@ -3357,3 +3357,7 @@ DISTRIBUTED
MACRO
: M A C R O
;
+
+JAR
+ : J A R
+ ;
diff --git
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
b/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
index c1e3df8c739..a269b59fd03 100644
---
a/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
+++
b/parser/sql/dialect/hive/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/HiveStatement.g4
@@ -46,6 +46,7 @@ execute
| alterIndex
| createMacro
| dropMacro
+ | createFunction
) (SEMI_ EOF? | EOF)
| EOF
;
diff --git
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
index b20fca1f626..4b93bf6242c 100644
---
a/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
+++
b/parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java
@@ -47,6 +47,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropInde
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.AlterIndexContext;
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateMacroContext;
import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.DropMacroContext;
+import
org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateFunctionContext;
import
org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
@@ -74,6 +75,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.vi
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.AlterMaterializedViewStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.macro.CreateMacroStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.macro.DropMacroStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.function.CreateFunctionStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.TruncateStatement;
@@ -411,4 +413,9 @@ public final class HiveDDLStatementVisitor extends
HiveStatementVisitor implemen
public ASTNode visitDropMacro(final DropMacroContext ctx) {
return new DropMacroStatement(getDatabaseType());
}
+
+ @Override
+ public ASTNode visitCreateFunction(final CreateFunctionContext ctx) {
+ return new CreateFunctionStatement(getDatabaseType());
+ }
}
diff --git a/test/it/parser/src/main/resources/case/ddl/create-function.xml
b/test/it/parser/src/main/resources/case/ddl/create-function.xml
index bcdc3ac4e88..f691fd3fa64 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-function.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-function.xml
@@ -31,4 +31,13 @@
<create-function sql-case-id="create_function_with_loop" />
<create-function
sql-case-id="create_function_with_aggregate_using_function" />
<create-function sql-case-id="create_function_with_simple_arithmetic" />
+ <create-function sql-case-id="create_temporary_function_basic" />
+ <create-function sql-case-id="create_function_basic" />
+ <create-function sql-case-id="create_function_with_db" />
+ <create-function sql-case-id="create_function_with_single_jar" />
+ <create-function sql-case-id="create_function_with_single_file" />
+ <create-function sql-case-id="create_function_with_single_archive" />
+ <create-function sql-case-id="create_function_with_two_resources" />
+ <create-function sql-case-id="create_function_with_three_resource_types" />
+ <create-function
sql-case-id="create_function_with_three_resource_types_and_db" />
</sql-parser-test-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml
b/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml
index 64b94b795c7..3a8f71c8768 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-function.xml
@@ -74,4 +74,13 @@
<sql-case id="create_function_with_loop" value="CREATE FUNCTION f(cur
SYS_REFCURSOR, mgr_hiredate DATE) RETURN NUMBER IS emp_hiredate DATE; before
number :=0; after number:=0; begin loop fetch cur into emp_hiredate; exit when
cur%NOTFOUND; if emp_hiredate > mgr_hiredate then after:=after+1; else
before:=before+1; end if; end loop; close cur; if before > after then return 1;
else return 0; end if; end;" db-types="Oracle" />
<sql-case id="create_function_with_aggregate_using_function" value="CREATE
OR REPLACE EDITIONABLE FUNCTION MY_FUNC (P1 VARCHAR2) RETURN VARCHAR2 AGGREGATE
USING MY_AGG_FUNC AS LANGUAGE JAVA NAME 'test';" db-types="Oracle" />
<sql-case id="create_function_with_simple_arithmetic" value="CREATE
FUNCTION ADD_INT(A INT, B INT DEFAULT 0) RETURNS INT AS BEGIN RETURN A+B; END"
db-types="Firebird"/>
+ <sql-case id="create_temporary_function_basic" value="CREATE TEMPORARY
FUNCTION parse_json AS 'com.example.JsonParser';" db-types="Hive" />
+ <sql-case id="create_function_basic" value="CREATE FUNCTION
calculate_score AS 'com.example.ScoreCalculator';" db-types="Hive" />
+ <sql-case id="create_function_with_db" value="CREATE FUNCTION
db1.calculate_score AS 'com.example.ScoreCalculator';" db-types="Hive" />
+ <sql-case id="create_function_with_single_jar" value="CREATE FUNCTION
parse_json AS 'com.example.JsonParser' USING JAR
'hdfs:///udfs/json-parser.jar';" db-types="Hive" />
+ <sql-case id="create_function_with_single_file" value="CREATE FUNCTION
load_config AS 'com.example.ConfigLoader' USING FILE
'hdfs:///udfs/app.properties';" db-types="Hive" />
+ <sql-case id="create_function_with_single_archive" value="CREATE FUNCTION
process_archive_data AS 'com.example.ArchiveProcessor' USING ARCHIVE
'hdfs:///udfs/data-files.tar.gz';" db-types="Hive" />
+ <sql-case id="create_function_with_two_resources" value="CREATE FUNCTION
process_data AS 'com.example.DataProcessor' USING JAR
'hdfs:///udfs/data-processor.jar', FILE 'hdfs:///udfs/config.properties';"
db-types="Hive" />
+ <sql-case id="create_function_with_three_resource_types" value="CREATE
FUNCTION process_multi_data AS 'com.example.MultiDataProcessor' USING JAR
'hdfs:///udfs/core-processor.jar', FILE
'hdfs:///configs/processing-rules.json', ARCHIVE
'hdfs:///datasets/sample-data.tar.gz';" db-types="Hive" />
+ <sql-case id="create_function_with_three_resource_types_and_db"
value="CREATE FUNCTION db1.process_multi_data AS
'com.example.MultiDataProcessor' USING JAR 'hdfs:///udfs/core-processor.jar',
FILE 'hdfs:///configs/processing-rules.json', ARCHIVE
'hdfs:///datasets/sample-data.tar.gz';" db-types="Hive" />
</sql-cases>