Skip to content

Commit

Permalink
Enhance Oracle alter table syntax rules (#28444)
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaoAK47 authored Sep 15, 2023
1 parent 74ce2f4 commit c3171c1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ relationalProperty
columnDefinition
: columnName REF? dataType SORT? visibleClause (defaultNullClause expr | identityClause)? (ENCRYPT encryptionSpecification)? (inlineConstraint+ | inlineRefConstraint)?
| REF LP_ columnName RP_ WITH ROWID
| SCOPE FOR LP_ columnName RP_ IS identifier
;

visibleClause
Expand Down Expand Up @@ -715,7 +716,7 @@ rebuildClause
;

parallelClause
: NOPARALLEL | PARALLEL NUMBER_?
: NOPARALLEL | PARALLEL (INTEGER_ | LP_ DEGREE INTEGER_ RP_)?
;

usableSpecification
Expand Down Expand Up @@ -1293,6 +1294,7 @@ alterTablePartitioning
| modifyTablePartition
| modifyTableSubpartition
| moveTablePartition
| moveTableSubPartition
| addTablePartition
| coalesceTablePartition
| dropTablePartition
Expand Down Expand Up @@ -1423,6 +1425,10 @@ moveTablePartition
: MOVE partitionExtendedName (MAPPING TABLE)? tablePartitionDescription? filterCondition? updateAllIndexesClause? parallelClause? allowDisallowClustering? ONLINE?
;

moveTableSubPartition
: MOVE subpartitionExtendedName indexingClause? partitioningStorageClause? updateIndexClauses? filterCondition? parallelClause? allowDisallowClustering? ONLINE?
;

filterCondition
: INCLUDING ROWS whereClause
;
Expand Down
34 changes: 32 additions & 2 deletions test/it/parser/src/main/resources/case/ddl/alter-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,10 @@
<alter-table sql-case-id="alter_table_add_partition_values_less_than3">
<table name="sales" start-index="12" stop-index="16" />
</alter-table>

<alter-table sql-case-id="alter_table_add_partition_values_less_than4">
<table name="shipments" start-index="12" stop-index="20" />
</alter-table>

<alter-table sql-case-id="alter_table_modify_subpartition_drop_values">
<table name="quarterly_regional_sales" start-index="12" stop-index="35" />
Expand All @@ -1658,10 +1662,14 @@
<table name="sales" start-index="12" stop-index="16" />
</alter-table>

<alter-table sql-case-id="alter_table_rename_partition">
<alter-table sql-case-id="alter_table_rename_partition1">
<table name="sales" start-index="12" stop-index="16" />
</alter-table>


<alter-table sql-case-id="alter_table_rename_partition2">
<table name="scubagear" start-index="12" stop-index="20" />
</alter-table>

<alter-table sql-case-id="alter_table_set_interval_expr">
<table name="sales" start-index="12" stop-index="16" />
</alter-table>
Expand All @@ -1672,4 +1680,26 @@
<primary-key-column name="sales_transaction_id" start-index="69" stop-index="88" />
</add-constraint>
</alter-table>

<alter-table sql-case-id="alter_table_move_subpartition_tablespace_parallel">
<table name="scuba_gear" start-index="12" stop-index="21" />
</alter-table>

<alter-table sql-case-id="alter_table_add_ref_with_rowid">
<table name="staff" start-index="12" stop-index="16" />
<add-column>
<column-definition start-index="24" stop-index="43">
<column name="dept" />
</column-definition>
</add-column>
</alter-table>

<alter-table sql-case-id="alter_table_add_scope_for_is">
<table name="staff" start-index="12" stop-index="16" />
<add-column>
<column-definition start-index="23" stop-index="49">
<column name="dept" />
</column-definition>
</add-column>
</alter-table>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,16 @@
<sql-case id="alter_table_add_partition_values_less_than1" value="ALTER TABLE quarterly_regional_sales ADD PARTITION q1_2000 VALUES LESS THAN (TO_DATE('1-APR-2000','DD-MON-YYYY')) STORAGE (INITIAL 20K NEXT 20K) TABLESPACE ts3 NOLOGGING(SUBPARTITION q1_2000_northwest VALUES ('OR', 'WA'), SUBPARTITION q1_2000_southwest VALUES ('AZ', 'UT', 'NM'), SUBPARTITION q1_2000_northeast VALUES ('NY', 'VM', 'NJ'), SUBPARTITION q1_2000_southeast VALUES ('FL', 'GA'), SUBPARTITION q1_2000_northcentral VALUES ('SD', 'WI'), SUBPARTITION q1_2000_southcentral VALUES ('OK', 'TX'))" db-types="Oracle" />
<sql-case id="alter_table_add_partition_values_less_than2" value="ALTER TABLE sales ADD PARTITION jan99 VALUES LESS THAN ('01-FEB-1999') TABLESPACE tsx" db-types="Oracle" />
<sql-case id="alter_table_add_partition_values_less_than3" value="ALTER TABLE sales ADD PARTITION sales_01_2001 VALUES LESS THAN (TO_DATE('01-FEB-2001', 'DD-MON-YYYY'))" db-types="Oracle" />
<sql-case id="alter_table_add_partition_values_less_than4" value="ALTER TABLE shipments ADD PARTITION p_2007_jan VALUES LESS THAN (TO_DATE('01-FEB-2007','dd-MON-yyyy')) COMPRESS (SUBPARTITION p07_jan_e VALUES LESS THAN (TO_DATE('15-FEB-2007','dd-MON-yyyy')), SUBPARTITION p07_jan_a VALUES LESS THAN (TO_DATE('01-MAR-2007','dd-MON-yyyy')), SUBPARTITION p07_jan_l VALUES LESS THAN (TO_DATE('01-APR-2007','dd-MON-yyyy')))" db-types="Oracle" />
<sql-case id="alter_table_modify_subpartition_drop_values" value="ALTER TABLE quarterly_regional_sales MODIFY SUBPARTITION q1_1999_southeast DROP VALUES ('KS')" db-types="Oracle" />
<sql-case id="alter_table_modify_nested_table_return_as_value" value="ALTER TABLE print_media MODIFY NESTED TABLE ad_textdocs_ntab RETURN AS VALUE" db-types="Oracle" />
<sql-case id="alter_table_modify_nested_owner_table_return_as_value" value="ALTER TABLE print_media MODIFY NESTED TABLE mytable.ad_textdocs_ntab RETURN AS VALUE" db-types="Oracle" />
<sql-case id="alter_table_modify_partition_storage" value="ALTER TABLE sales MODIFY PARTITION sales_q1 STORAGE (MAXEXTENTS 10)" db-types="Oracle" />
<sql-case id="alter_table_rename_partition" value="ALTER TABLE sales RENAME PARTITION sales_q4_2003 TO sales_currentq" db-types="Oracle" />
<sql-case id="alter_table_rename_partition1" value="ALTER TABLE sales RENAME PARTITION sales_q4_2003 TO sales_currentq" db-types="Oracle" />
<sql-case id="alter_table_rename_partition2" value="ALTER TABLE scubagear RENAME PARTITION sys_p636 TO tanks" db-types="Oracle" />
<sql-case id="alter_table_set_interval_expr" value="ALTER TABLE sales SET INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))" db-types="Oracle" />
<sql-case id="alter_table_add_constraint_primary_key_disable_validate" value="ALTER TABLE sales_01_2001 ADD CONSTRAINT sales_pk_jan01 PRIMARY KEY (sales_transaction_id) DISABLE VALIDATE" db-types="Oracle" />
<sql-case id="alter_table_move_subpartition_tablespace_parallel" value="ALTER TABLE scuba_gear MOVE SUBPARTITION bcd_types TABLESPACE tbs23 PARALLEL (DEGREE 2)" db-types="Oracle" />
<sql-case id="alter_table_add_ref_with_rowid" value="ALTER TABLE staff ADD (REF(dept) WITH ROWID)" db-types="Oracle" />
<sql-case id="alter_table_add_scope_for_is" value="ALTER TABLE staff ADD (SCOPE FOR (dept) IS offices)" db-types="Oracle" />
</sql-cases>

0 comments on commit c3171c1

Please sign in to comment.