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 a3eaea3b04d Support Oracle SQL parsing custom functions with DISTINCT
(#28396)
a3eaea3b04d is described below
commit a3eaea3b04dbc8ffadc69c8b8f09c579033070b1
Author: ZhangCheng <[email protected]>
AuthorDate: Fri Sep 8 17:31:19 2023 +0800
Support Oracle SQL parsing custom functions with DISTINCT (#28396)
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 4 ++--
.../parser/src/main/resources/case/dml/select.xml | 26 ++++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 1 +
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index d3f383de364..3846dfdaa69 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -87,7 +87,7 @@ unreservedWord1
: TRUNCATE | FUNCTION | PROCEDURE | CASE | WHEN | CAST | TRIM | SUBSTRING
| NATURAL | JOIN | FULL | INNER | OUTER | LEFT | RIGHT
| CROSS | USING | IF | TRUE | FALSE | LIMIT | OFFSET
- | BEGIN | COMMIT | ROLLBACK | SAVEPOINT
+ | COMMIT | ROLLBACK | SAVEPOINT
| ARRAY | INTERVAL | TIME | TIMESTAMP | LOCALTIME | LOCALTIMESTAMP | YEAR
| QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND
| MICROSECOND | MAX | MIN | SUM | COUNT | AVG | ENABLE
@@ -664,7 +664,7 @@ notOperator
booleanPrimary
: booleanPrimary IS NOT? (TRUE | FALSE | UNKNOWN | NULL)
- | PRIOR predicate
+ | (PRIOR | DISTINCT) predicate
| CONNECT_BY_ROOT predicate
| booleanPrimary SAFE_EQ_ predicate
| booleanPrimary comparisonOperator (ALL | ANY) subquery
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml
b/test/it/parser/src/main/resources/case/dml/select.xml
index 8009fe15404..96a605a0345 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -6967,4 +6967,30 @@
<expression-projection start-index="7" stop-index="18" text="5!"
alias="RESULT" />
</projections>
</select>
+
+ <select sql-case-id="select_with_custom_distinct_function">
+ <projections start-index="7" stop-index="34" literal-start-index="7"
literal-stop-index="34">
+ <expression-projection text="custom_concat(distinct a.P1)"
start-index="7" stop-index="34"
+ literal-start-index="7"
literal-stop-index="34">
+ <literalText>custom_concat(distinct a.P1)</literalText>
+ <expr>
+ <function function-name="custom_concat"
text="custom_concat(distinct a.P1)" start-index="7"
+ stop-index="34" literal-start-index="7"
literal-stop-index="34">
+ <parameter>
+ <column name="P1" start-index="30" stop-index="33"
literal-start-index="30"
+ literal-stop-index="33">
+ <owner name="a" start-index="30"
stop-index="30" literal-start-index="30"
+ literal-stop-index="30"/>
+ </column>
+ </parameter>
+ <literalText>custom_concat(distinct a.P1)</literalText>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ <from>
+ <simple-table alias="a" name="TEST" start-index="41"
stop-index="46" literal-start-index="41"
+ literal-stop-index="46"/>
+ </from>
+ </select>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
index 863dd7daa58..3ed24b8e9b3 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
@@ -211,4 +211,5 @@
<sql-case id="select_with_expressions_in_projection" value="SELECT
((a.enddate - term + term2 + 1) / (last_day(term) - term + 1)) cnt, a.empid
FROM employee aWHERE nvl(disabled, 0) = 1 AND enddate BETWEEN term AND
last_day(term) AND EXISTS (SELECT 1 FROM post d WHERE a.orgid = d.orgid AND
a.postid = d.postid AND d.title != 'TEST' AND nvl(d.postid, 0) != 0)"
db-types="Oracle" />
<sql-case id="select_with_custom_table_function" value="SELECT
COUNT(empid) FROM EMPLOYEE b, custom_function(b.orgid) a WHERE a.postid =
b.postid" db-types="Oracle" />
<sql-case id="select_numeric_operator" value="SELECT 5! AS RESULT;"
db-types="openGauss" />
+ <sql-case id="select_with_custom_distinct_function" value="select
custom_concat(distinct a.P1) From TEST a;" db-types="Oracle" />
</sql-cases>