Skip to content

Commit

Permalink
Fix oracle create table listPartitionDesc and subpartitionTemplate sy…
Browse files Browse the repository at this point in the history
…ntax (#29222)
  • Loading branch information
zihaoAK47 authored Nov 28, 2023
1 parent 7b9b9b8 commit 7bfc3d4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1094,13 +1094,12 @@ subpartitionByList
;

subpartitionByHash
: SUBPARTITION BY HASH columnNames (SUBPARTITIONS NUMBER_ (STORE IN LP_ tablespaceName (COMMA_ tablespaceName)? RP_)? | subpartitionTemplate)?
: SUBPARTITION BY HASH columnNames (SUBPARTITIONS INTEGER_ (STORE IN LP_ tablespaceName (COMMA_ tablespaceName)? RP_)? | subpartitionTemplate)?
;

subpartitionTemplate
: SUBPARTITION TEMPLATE
(LP_? rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)* | listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)* RP_?)
| hashSubpartitionQuantity
: SUBPARTITION TEMPLATE (LP_ (rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)*
| listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)*) RP_) | hashSubpartitionQuantity
;

rangeSubpartitionDesc
Expand Down Expand Up @@ -1129,7 +1128,8 @@ compositeListPartitions
;

listPartitionDesc
: PARTITIONSET partitionSetName listValuesClause (TABLESPACE SET tablespaceSetName)? lobStorageClause? (SUBPARTITIONS STORE IN LP_? tablespaceSetName (COMMA_ tablespaceSetName)* RP_?)?
: PARTITION partitionName? listValuesClause tablePartitionDescription (LP_ (rangeSubpartitionDesc (COMMA_ rangeSubpartitionDesc)*
| listSubpartitionDesc (COMMA_ listSubpartitionDesc)* | individualHashSubparts (COMMA_ individualHashSubparts)*) RP_ | hashSubpartsByQuantity)?
;

compositeHashPartitions
Expand Down
56 changes: 56 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/create-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2081,4 +2081,60 @@
<column name="inserter" start-index="62" stop-index="69" />
</column-definition>
</create-table>

<create-table sql-case-id="create_table_partition_by_list_subpartition_by_hash">
<table name="car_rentals" start-index="13" stop-index="23" />
<column-definition type="NUMBER" start-index="30" stop-index="50">
<column name="id" start-index="30" stop-index="31" />
</column-definition>
<column-definition type="NUMBER" start-index="58" stop-index="85">
<column name="customer_id" start-index="58" stop-index="68" />
</column-definition>
<column-definition type="VARCHAR2" start-index="93" stop-index="134">
<column name="confirmation_number" start-index="93" stop-index="111" />
</column-definition>
<column-definition type="NUMBER" start-index="142" stop-index="156">
<column name="car_id" start-index="142" stop-index="147" />
</column-definition>
<column-definition type="VARCHAR2" start-index="164" stop-index="184">
<column name="car_type" start-index="164" stop-index="171" />
</column-definition>
<column-definition type="VARCHAR2" start-index="192" stop-index="233">
<column name="requested_car_type" start-index="192" stop-index="209" />
</column-definition>
<column-definition type="DATE" start-index="241" stop-index="270">
<column name="reservation_date" start-index="241" stop-index="256" />
</column-definition>
<column-definition type="DATE" start-index="278" stop-index="303">
<column name="start_date" start-index="278" stop-index="287" />
</column-definition>
<column-definition type="DATE" start-index="311" stop-index="323">
<column name="end_date" start-index="311" stop-index="318" />
</column-definition>
</create-table>

<create-table sql-case-id="create_table_subpartition_by_range_subpartition_template">
<table name="account_balance_history" start-index="13" stop-index="35" />
<column-definition type="NUMBER" start-index="42" stop-index="59">
<column name="id" start-index="42" stop-index="43" />
</column-definition>
<column-definition type="NUMBER" start-index="67" stop-index="96">
<column name="account_number" start-index="67" stop-index="80" />
</column-definition>
<column-definition type="NUMBER" start-index="104" stop-index="133">
<column name="customer_id" start-index="104" stop-index="114" />
</column-definition>
<column-definition type="DATE" start-index="141" stop-index="172">
<column name="transaction_date" start-index="141" stop-index="156" />
</column-definition>
<column-definition type="NUMBER" start-index="180" stop-index="204">
<column name="amount_credited" start-index="180" stop-index="194" />
</column-definition>
<column-definition type="NUMBER" start-index="212" stop-index="232">
<column name="amount_debited" start-index="212" stop-index="225" />
</column-definition>
<column-definition type="NUMBER" start-index="240" stop-index="273">
<column name="end_of_day_balance" start-index="240" stop-index="257" />
</column-definition>
</create-table>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,42 @@
PARTITION costs_q2_2003 VALUES LESS THAN (TO_DATE('01-JUN-2003', 'DD-MON-YYYY')),
PARTITION costs_recent VALUES LESS THAN (MAXVALUE))" db-types="Oracle" />
<sql-case id="create_table_default_user" value="CREATE TABLE audit_trail (value1 NUMBER, value2 VARCHAR2(32), inserter VARCHAR2(30) DEFAULT USER)" db-types="Oracle" />
<sql-case id="create_table_partition_by_list_subpartition_by_hash" value="CREATE TABLE car_rentals
(id NUMBER NOT NULL,
customer_id NUMBER NOT NULL,
confirmation_number VARCHAR2(12) NOT NULL,
car_id NUMBER,
car_type VARCHAR2(10),
requested_car_type VARCHAR2(10) NOT NULL,
reservation_date DATE NOT NULL,
start_date DATE NOT NULL,
end_date DATE,
country as (substr(confirmation_number,9,2))
) PARTITION BY LIST (country)
SUBPARTITION BY HASH (customer_id)
SUBPARTITIONS 16
(PARTITION north_america VALUES ('US','CA','MX'),
PARTITION south_america VALUES ('BR','AR','PE'),
PARTITION europe VALUES ('GB','DE','NL','BE','FR','ES','IT','CH'),
PARTITION apac VALUES ('NZ','AU','IN','CN')
) ENABLE ROW MOVEMENT" db-types="Oracle" />
<sql-case id="create_table_subpartition_by_range_subpartition_template" value="CREATE TABLE account_balance_history
(id NUMBER NOT NULL,
account_number NUMBER NOT NULL,
customer_id NUMBER NOT NULL,
transaction_date DATE NOT NULL,
amount_credited NUMBER,
amount_debited NUMBER,
end_of_day_balance NUMBER NOT NULL
) PARTITION BY RANGE(transaction_date)
INTERVAL (NUMTODSINTERVAL(7,'DAY'))
SUBPARTITION BY RANGE(end_of_day_balance)
SUBPARTITION TEMPLATE
(SUBPARTITION unacceptable VALUES LESS THAN (-1000),
SUBPARTITION credit VALUES LESS THAN (0),
SUBPARTITION low VALUES LESS THAN (500),
SUBPARTITION normal VALUES LESS THAN (5000),
SUBPARTITION high VALUES LESS THAN (20000),
SUBPARTITION extraordinary VALUES LESS THAN (MAXVALUE)
) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-JAN-2007','dd-MON-yyyy')))" db-types="Oracle" />
</sql-cases>

0 comments on commit 7bfc3d4

Please sign in to comment.