This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 9b55c2b9879 Fix PostgreSQL parser grammar for database commands and
COPY options (#40225)
9b55c2b9879 is described below
commit 9b55c2b9879240481cf8ac0bbaf073843ae570a7
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 18 23:15:52 2026 +0800
Fix PostgreSQL parser grammar for database commands and COPY options
(#40225)
---
.../src/main/antlr4/imports/postgresql/DDLStatement.g4 | 4 ++++
.../src/main/antlr4/imports/postgresql/DMLStatement.g4 | 4 ++--
.../parser/src/main/resources/case/ddl/alter-database.xml | 1 +
test/it/parser/src/main/resources/case/ddl/reindex.xml | 4 ++++
.../parser/src/main/resources/case/ddl/security-label.xml | 2 ++
test/it/parser/src/main/resources/case/dml/copy.xml | 14 ++++++++++++++
.../main/resources/sql/supported/ddl/alter-database.xml | 1 +
.../src/main/resources/sql/supported/ddl/reindex.xml | 4 ++++
.../main/resources/sql/supported/ddl/security-label.xml | 2 ++
.../parser/src/main/resources/sql/supported/dml/copy.xml | 3 +++
.../src/main/resources/sql/unsupported/unsupported.xml | 5 +++++
11 files changed, 42 insertions(+), 2 deletions(-)
diff --git
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
index 402aaa51cbb..5a39775f545 100644
---
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
+++
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
@@ -510,6 +510,7 @@ alterDatabaseClause
| RENAME TO databaseName
| OWNER TO roleSpec
| SET TABLESPACE name
+ | REFRESH COLLATION VERSION
| setResetClause
;
@@ -1905,8 +1906,10 @@ reindex
reIndexClauses
: reindexTargetType CONCURRENTLY? qualifiedName
| reindexTargetMultitable CONCURRENTLY? name
+ | (SYSTEM | DATABASE) CONCURRENTLY?
| LP_ reindexOptionList RP_ reindexTargetType CONCURRENTLY? qualifiedName
| LP_ reindexOptionList RP_ reindexTargetMultitable CONCURRENTLY? name
+ | LP_ reindexOptionList RP_ (SYSTEM | DATABASE) CONCURRENTLY?
;
reindexOptionList
@@ -1988,6 +1991,7 @@ securityLabel
securityLabelClausces
: objectTypeAnyName anyName
| COLUMN anyName
+ | ROLE name
| (TYPE | DOMAIN) typeName
| (AGGREGATE | FUNCTION) aggregateWithArgtypes
| LARGE OBJECT numericOnly
diff --git
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index dad1d1a9fb9..b4bb4c3cdf4 100644
---
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -502,12 +502,12 @@ copyOptionList
;
copyOption
- : FORMAT identifier
+ : FORMAT (identifier | BINARY)
| FREEZE booleanValue?
| DELIMITER STRING_
| NULL STRING_
| DEFAULT STRING_
- | HEADER (booleanValue | MATCH)?
+ | HEADER (booleanValue | MATCH | STRING_)?
| QUOTE STRING_
| ESCAPE STRING_
| FORCE_QUOTE (columnNames | ASTERISK_)
diff --git a/test/it/parser/src/main/resources/case/ddl/alter-database.xml
b/test/it/parser/src/main/resources/case/ddl/alter-database.xml
index 2eb4c0bae3d..8623f61e46b 100644
--- a/test/it/parser/src/main/resources/case/ddl/alter-database.xml
+++ b/test/it/parser/src/main/resources/case/ddl/alter-database.xml
@@ -99,6 +99,7 @@
<alter-database sql-case-id="alter_database_set_managedlocation" />
<alter-database sql-case-id="alter_schema_set_managedlocation" />
<alter-database sql-case-id="alter_database_set_lc_messages" />
+ <alter-database sql-case-id="alter_database_refresh_collation_version" />
<alter-database sql-case-id="alter_database_set_data_quota"
database-name="example_db" quota-type="DATA" quota-value="10995116277760" />
<alter-database sql-case-id="alter_database_set_data_quota_with_unit"
database-name="example_db" quota-type="DATA" quota-value="107374182400" />
<alter-database
sql-case-id="alter_database_set_data_quota_with_two_letter_unit"
database-name="example_db" quota-type="DATA" quota-value="1073741824" />
diff --git a/test/it/parser/src/main/resources/case/ddl/reindex.xml
b/test/it/parser/src/main/resources/case/ddl/reindex.xml
index 5f79c4b0522..93d0367e592 100644
--- a/test/it/parser/src/main/resources/case/ddl/reindex.xml
+++ b/test/it/parser/src/main/resources/case/ddl/reindex.xml
@@ -24,5 +24,9 @@
<reindex sql-case-id="reindex_index" />
<reindex sql-case-id="reindex_schema" />
<reindex sql-case-id="reindex_system" />
+ <reindex sql-case-id="reindex_system_without_name" />
+ <reindex sql-case-id="reindex_database_without_name" />
+ <reindex sql-case-id="reindex_system_without_name_with_options" />
+ <reindex sql-case-id="reindex_database_without_name_with_options" />
<reindex sql-case-id="reindex_table" />
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/case/ddl/security-label.xml
b/test/it/parser/src/main/resources/case/ddl/security-label.xml
index d6729e835cb..a00e8fc8a47 100644
--- a/test/it/parser/src/main/resources/case/ddl/security-label.xml
+++ b/test/it/parser/src/main/resources/case/ddl/security-label.xml
@@ -18,4 +18,6 @@
<sql-parser-test-cases>
<security-label sql-case-id="security_label" />
+ <security-label sql-case-id="security_label_on_role" />
+ <security-label sql-case-id="security_label_on_role_with_provider" />
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/case/dml/copy.xml
b/test/it/parser/src/main/resources/case/dml/copy.xml
index dbcbe5e9b09..13443de5d73 100644
--- a/test/it/parser/src/main/resources/case/dml/copy.xml
+++ b/test/it/parser/src/main/resources/case/dml/copy.xml
@@ -37,6 +37,20 @@
<table name="t_order" start-index="5" stop-index="11" />
</copy>
+ <copy sql-case-id="copy_table_from_stdin_with_header_zero">
+ <table name="t_order" start-index="5" stop-index="11" />
+ </copy>
+
+ <copy sql-case-id="copy_table_from_stdin_with_header_one">
+ <table name="t_order" start-index="5" stop-index="11" />
+ </copy>
+
+ <copy sql-case-id="copy_table_with_columns_to_stdout_format_binary">
+ <table name="t_order" start-index="5" stop-index="11" />
+ <column name="id" start-index="13" stop-index="14" />
+ <column name="name" start-index="17" stop-index="20" />
+ </copy>
+
<copy sql-case-id="copy_table_to_stdout_with_csv_force_quote">
<table name="t_order" start-index="5" stop-index="11" />
</copy>
diff --git
a/test/it/parser/src/main/resources/sql/supported/ddl/alter-database.xml
b/test/it/parser/src/main/resources/sql/supported/ddl/alter-database.xml
index ab8ad9fb0d3..64f4a41ab01 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-database.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-database.xml
@@ -99,6 +99,7 @@
<sql-case id="alter_database_set_managedlocation" value="ALTER DATABASE
test_db SET MANAGEDLOCATION 'hdfs://namenode:8020/user/hive/managed/test_db';"
db-types="Hive" />
<sql-case id="alter_schema_set_managedlocation" value="ALTER SCHEMA
test_db SET MANAGEDLOCATION
'hdfs://namenode:8020/user/hive/managed/another_test_db';" db-types="Hive" />
<sql-case id="alter_database_set_lc_messages" value="ALTER DATABASE
"regression" SET lc_messages TO 'C'" db-types="PostgreSQL" />
+ <sql-case id="alter_database_refresh_collation_version" value="ALTER
DATABASE "foo_db" REFRESH COLLATION VERSION;" db-types="PostgreSQL" />
<sql-case id="alter_database_set_data_quota" value="ALTER DATABASE
example_db SET DATA QUOTA 10995116277760" db-types="Doris" />
<sql-case id="alter_database_set_data_quota_with_unit" value="ALTER
DATABASE example_db SET DATA QUOTA 100G" db-types="Doris" />
<sql-case id="alter_database_set_data_quota_with_two_letter_unit"
value="ALTER DATABASE example_db SET DATA QUOTA 1GB" db-types="Doris" />
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/reindex.xml
b/test/it/parser/src/main/resources/sql/supported/ddl/reindex.xml
index 18af91e83ae..e7d19e6654b 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/reindex.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/reindex.xml
@@ -24,5 +24,9 @@
<sql-case id="reindex_index" value="REINDEX INDEX concur_reindex_part;"
db-types="PostgreSQL" />
<sql-case id="reindex_schema" value="REINDEX SCHEMA CONCURRENTLY
pg_catalog;" db-types="PostgreSQL" />
<sql-case id="reindex_system" value="REINDEX SYSTEM CONCURRENTLY
postgres;" db-types="PostgreSQL" />
+ <sql-case id="reindex_system_without_name" value="REINDEX SYSTEM;"
db-types="PostgreSQL" />
+ <sql-case id="reindex_database_without_name" value="REINDEX DATABASE
CONCURRENTLY;" db-types="PostgreSQL" />
+ <sql-case id="reindex_system_without_name_with_options" value="REINDEX
(VERBOSE) SYSTEM CONCURRENTLY;" db-types="PostgreSQL" />
+ <sql-case id="reindex_database_without_name_with_options" value="REINDEX
(VERBOSE) DATABASE;" db-types="PostgreSQL" />
<sql-case id="reindex_table" value="REINDEX TABLE CONCURRENTLY
concur_appclass_tab;" db-types="PostgreSQL" />
</sql-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/ddl/security-label.xml
b/test/it/parser/src/main/resources/sql/supported/ddl/security-label.xml
index 27ed6f1f44b..dec2a57f60d 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/security-label.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/security-label.xml
@@ -18,4 +18,6 @@
<sql-cases>
<sql-case id="security_label" value="SECURITY LABEL ON TABLE seclabel_tbl1
IS 'classified';" db-types="PostgreSQL" />
+ <sql-case id="security_label_on_role" value="SECURITY LABEL ON ROLE
"foo_role" IS 'classified';" db-types="PostgreSQL" />
+ <sql-case id="security_label_on_role_with_provider" value="SECURITY LABEL
FOR foo_provider ON ROLE foo_role IS NULL;" db-types="PostgreSQL" />
</sql-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/copy.xml
b/test/it/parser/src/main/resources/sql/supported/dml/copy.xml
index e80bad44f2f..1ca157a340d 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/copy.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/copy.xml
@@ -22,6 +22,9 @@
<sql-case id="copy_table_to_stdout_with_null_as" value="COPY t_order TO
STDOUT WITH NULL AS E'\\0';" db-types="PostgreSQL" />
<sql-case id="copy_table_from_stdin_with_delimiter_null_as" value="COPY
t_order FROM STDIN WITH DELIMITER AS ':' NULL AS E'\\X';"
db-types="PostgreSQL" />
<sql-case id="copy_table_to_stdout_format_csv" value="COPY t_order TO
STDOUT (FORMAT CSV, FORCE_QUOTE (col2), ESCAPE E'\\');"
db-types="PostgreSQL" />
+ <sql-case id="copy_table_from_stdin_with_header_zero" value="COPY t_order
FROM STDIN (FORMAT CSV, HEADER '0');" db-types="PostgreSQL" />
+ <sql-case id="copy_table_from_stdin_with_header_one" value="COPY t_order
FROM STDIN (FORMAT CSV, HEADER '1');" db-types="PostgreSQL" />
+ <sql-case id="copy_table_with_columns_to_stdout_format_binary" value="COPY
t_order(id, name) TO STDOUT (FORMAT BINARY);" db-types="PostgreSQL" />
<sql-case id="copy_table_to_stdout_with_csv_force_quote" value="COPY
t_order TO STDOUT WITH CSV ESCAPE E'\\' FORCE QUOTE col2;"
db-types="PostgreSQL" />
<sql-case id="copy_query_results_to_stdout" value="COPY (SELECT * FROM
t_order) TO STDOUT;" db-types="PostgreSQL" />
<sql-case id="copy_query_results_from_stdin" value="COPY (SELECT * FROM
t_order) FROM STDIN;" db-types="PostgreSQL" />
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 671ea4eccf1..d88175e9262 100644
--- a/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
+++ b/test/it/parser/src/main/resources/sql/unsupported/unsupported.xml
@@ -394,4 +394,9 @@
<sql-case id="unsupported_postgresql_json_exists_missing_path"
value="SELECT JSON_EXISTS('{}')" db-types="PostgreSQL" case-types="literal" />
<sql-case id="select_postgresql_json_arrayagg_filter_window" value="SELECT
JSON_ARRAYAGG(?) FILTER (WHERE ?) OVER ()" db-types="PostgreSQL"
case-types="literal" />
<sql-case id="select_postgresql_json_arrayagg_filter_without_window"
value="SELECT JSON_ARRAYAGG(?) FILTER (WHERE ?)" db-types="PostgreSQL"
case-types="literal" />
+ <sql-case id="unsupported_postgresql_reindex_schema_without_name"
value="REINDEX SCHEMA;" db-types="PostgreSQL" case-types="literal" />
+ <sql-case
id="unsupported_postgresql_reindex_schema_without_name_with_options"
value="REINDEX (VERBOSE) SCHEMA;" db-types="PostgreSQL" case-types="literal" />
+ <sql-case id="unsupported_postgresql_security_label_without_role_name"
value="SECURITY LABEL ON ROLE IS 'foo_label';" db-types="PostgreSQL"
case-types="literal" />
+ <sql-case id="unsupported_postgresql_copy_format_without_value"
value="COPY t_order TO STDOUT (FORMAT);" db-types="PostgreSQL"
case-types="literal" />
+ <sql-case id="unsupported_postgresql_copy_header_unquoted_value"
value="COPY t_order FROM STDIN (HEADER wrong_choice);" db-types="PostgreSQL"
case-types="literal" />
</sql-cases>