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 5c70cc5a712 Fix PostgreSQL and openGauss time extract function parse
week and quarter error (#33564)
5c70cc5a712 is described below
commit 5c70cc5a71279c9926eca701e66bcdcd59f72e11
Author: ironman <[email protected]>
AuthorDate: Fri Nov 8 16:10:02 2024 +0800
Fix PostgreSQL and openGauss time extract function parse week and quarter
error (#33564)
* Fix PostgreSQL time extract function parse week and quarter error
* Fix openGauss time extract function parse week and quarter error
* Support time extract function parse week and quarter in openGauss
* Added support for time extract function parse week and quarter in
PostgreSQL and openGauss
---
.../src/main/antlr4/imports/opengauss/BaseRule.g4 | 4 ++
.../src/main/antlr4/imports/postgresql/BaseRule.g4 | 4 ++
.../resources/case/dml/select-special-function.xml | 44 ++++++++++++++++++++++
.../sql/supported/dml/select-special-function.xml | 2 +
.../main/resources/sql/unsupported/unsupported.xml | 2 -
5 files changed, 54 insertions(+), 2 deletions(-)
diff --git
a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4
b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4
index abf4c2e63d3..610ebdda0be 100644
--- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4
+++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4
@@ -329,6 +329,7 @@ unreservedWord
| PROCEDURES
| PROGRAM
| PUBLICATION
+ | QUARTER
| QUOTE
| RANGE
| READ
@@ -427,6 +428,7 @@ unreservedWord
| VIEW
| VIEWS
| VOLATILE
+ | WEEK
| WHITESPACE
| WITHIN
| WITHOUT
@@ -1147,7 +1149,9 @@ extractList
extractArg
: YEAR
+ | QUARTER
| MONTH
+ | WEEK
| DAY
| HOUR
| MINUTE
diff --git
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
index 751ca07f4e0..4a1910c3b99 100644
---
a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
+++
b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
@@ -330,6 +330,7 @@ unreservedWord
| PROCEDURES
| PROGRAM
| PUBLICATION
+ | QUARTER
| QUOTE
| RANGE
| READ
@@ -428,6 +429,7 @@ unreservedWord
| VIEW
| VIEWS
| VOLATILE
+ | WEEK
| WHITESPACE
| WITHIN
| WITHOUT
@@ -1114,7 +1116,9 @@ extractList
extractArg
: YEAR
+ | QUARTER
| MONTH
+ | WEEK
| DAY
| HOUR
| MINUTE
diff --git
a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index 696568f2e08..6712182134b 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -440,6 +440,50 @@
</projections>
</select>
+ <select sql-case-id="select_extract_function_week">
+ <projections start-index="7" stop-index="56">
+ <expression-projection text="EXTRACT(WEEK FROM TIMESTAMP
'2001-02-16 20:38:40')" start-index="7" stop-index="56">
+ <expr>
+ <function function-name="EXTRACT" start-index="7"
stop-index="56" text="EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40')">
+ <parameter>
+ <extract-arg start-index="15" stop-index="18"
text="WEEK" />
+ </parameter>
+ <parameter>
+ <type-cast-expression>
+ <expression>
+ <literal-expression value="2001-02-16
20:38:40" start-index="35" stop-index="55" />
+ </expression>
+ <data-type>TIMESTAMP</data-type>
+ </type-cast-expression>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="select_extract_function_quarter">
+ <projections start-index="7" stop-index="59">
+ <expression-projection text="EXTRACT(QUARTER FROM TIMESTAMP
'2001-02-16 20:38:40')" start-index="7" stop-index="59">
+ <expr>
+ <function function-name="EXTRACT" start-index="7"
stop-index="59" text="EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')">
+ <parameter>
+ <extract-arg start-index="15" stop-index="21"
text="QUARTER" />
+ </parameter>
+ <parameter>
+ <type-cast-expression>
+ <expression>
+ <literal-expression value="2001-02-16
20:38:40" start-index="38" stop-index="58" />
+ </expression>
+ <data-type>TIMESTAMP</data-type>
+ </type-cast-expression>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
<select sql-case-id="select_extract_function_for_oracle">
<projections start-index="7" stop-index="56" literal-start-index="7"
literal-stop-index="56">
<expression-projection text="EXTRACT(YEAR FROM TIMESTAMP
'2001-02-16 20:38:40')" start-index="7" stop-index="56" literal-start-index="7"
literal-stop-index="56">
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
index 69b82813984..17a6a5208a8 100644
---
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
+++
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
@@ -40,6 +40,8 @@
<sql-case id="select_values" value="SELECT VALUES(order_id) FROM t_order"
db-types="MySQL" />
<sql-case id="select_current_user_brackets" value="SELECT CURRENT_USER()"
db-types="MySQL" />
<sql-case id="select_extract_function" value="SELECT EXTRACT(YEAR FROM
TIMESTAMP '2001-02-16 20:38:40')" db-types="PostgreSQL,openGauss" />
+ <sql-case id="select_extract_function_week" value="SELECT EXTRACT(WEEK
FROM TIMESTAMP '2001-02-16 20:38:40')" db-types="PostgreSQL,openGauss" />
+ <sql-case id="select_extract_function_quarter" value="SELECT
EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')"
db-types="PostgreSQL,openGauss" />
<sql-case id="select_extract_function_for_oracle" value="SELECT
EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL" db-types="Oracle"
/>
<sql-case id="select_mod_function" value="SELECT MOD(order_id, 1) from
t_order" db-types="PostgreSQL,openGauss" />
<sql-case id="select_sys_xml_agg" value="SELECT
SYS_XMLAGG(SYS_XMLGEN(last_name)) XMLAGG FROM employees WHERE last_name LIKE
'R%' ORDER BY xmlagg;" db-types="Oracle" />
diff --git a/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
b/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
index d9f55d822d7..adfbcb535a9 100644
--- a/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
+++ b/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
@@ -262,8 +262,6 @@
<sql-case id="unsupported_select_case_for_opengauss_438" value="select
B'101' | as result;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_439" value="select
B'101' # as result;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_440" value="select
B'11110' # B'0000';" db-types="openGauss" />
- <sql-case id="unsupported_select_case_for_opengauss_443" value="select
extract(quarter from timestamp '2001-02-16 20:38:40') from sys_dummy;"
db-types="openGauss" />
- <sql-case id="unsupported_select_case_for_opengauss_444" value="select
extract(week from timestamp '2001-02-16 20:38:40') from sys_dummy;"
db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_447" value="select
atan(11 11) from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_448" value="select
atan(,) from sys_dummy;" db-types="openGauss" />
<sql-case id="unsupported_select_case_for_opengauss_451" value="select
$$the lexeme ' ' , contains spaces$$::tsvector@@ ','::tsquery as result;"
db-types="openGauss" />