Skip to content

Commit

Permalink
Fix alter tablespace assert and add other sql parse test (#28793)
Browse files Browse the repository at this point in the history
* Add alter table sql parse test

* Add oracle select sql parse test

* Fix alter tablespace assert
  • Loading branch information
zihaoAK47 authored Oct 18, 2023
1 parent 96451bb commit 2ee5baf
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ public final class AlterTablespaceStatementAssert {
* @param expected expected alter tablespace statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final AlterTablespaceStatement actual, final AlterTablespaceStatementTestCase expected) {
if (null != expected.getTablespace()) {
assertTablespace(assertContext, actual, expected);
}
if (null != expected.getRenameTablespace()) {
assertRenameTablespace(assertContext, actual, expected);
}
assertTablespace(assertContext, actual, expected);
assertRenameTablespace(assertContext, actual, expected);
}

private static void assertTablespace(final SQLCaseAssertContext assertContext, final AlterTablespaceStatement actual, final AlterTablespaceStatementTestCase expected) {
Expand All @@ -56,8 +52,8 @@ private static void assertTablespace(final SQLCaseAssertContext assertContext, f
} else {
assertNotNull(actual.getTablespaceSegment(), assertContext.getText("Actual tablespace should exist."));
IdentifierValueAssert.assertIs(assertContext, actual.getTablespaceSegment().getIdentifier(), expected.getTablespace(), "Tablespace");
SQLSegmentAssert.assertIs(assertContext, actual.getTablespaceSegment(), expected.getTablespace());
}
SQLSegmentAssert.assertIs(assertContext, actual.getTablespaceSegment(), expected.getTablespace());
}

private static void assertRenameTablespace(final SQLCaseAssertContext assertContext, final AlterTablespaceStatement actual, final AlterTablespaceStatementTestCase expected) {
Expand All @@ -66,7 +62,7 @@ private static void assertRenameTablespace(final SQLCaseAssertContext assertCont
} else {
assertNotNull(actual.getRenameTablespaceSegment(), assertContext.getText("Actual rename tablespace should exist."));
IdentifierValueAssert.assertIs(assertContext, actual.getRenameTablespaceSegment().getIdentifier(), expected.getRenameTablespace(), "Tablespace");
SQLSegmentAssert.assertIs(assertContext, actual.getRenameTablespaceSegment(), expected.getRenameTablespace());
}
SQLSegmentAssert.assertIs(assertContext, actual.getRenameTablespaceSegment(), expected.getRenameTablespace());
}
}
21 changes: 20 additions & 1 deletion test/it/parser/src/main/resources/case/ddl/alter-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1744,11 +1744,21 @@
<table name="table_name" start-index="12" stop-index="21" />
</alter-table>

<alter-table sql-case-id="alter_table_modify_constraint_rely">
<alter-table sql-case-id="alter_table_modify_constraint_rely1">
<table name="time" start-index="12" stop-index="15" />
<modify-constraint start-index="35" stop-index="41" constraint-name="pk_time" />
</alter-table>

<alter-table sql-case-id="alter_table_modify_constraint_rely2">
<table name="times" start-index="12" stop-index="16" />
<modify-constraint start-index="18" stop-index="47" constraint-name="time_pk" />
</alter-table>

<alter-table sql-case-id="alter_table_modify_constraint_rely3">
<table name="sales" start-index="12" stop-index="16" />
<modify-constraint start-index="18" stop-index="53" constraint-name="sales_time_fk" />
</alter-table>

<alter-table sql-case-id="alter_table_enable_row_movement">
<table name="table" start-index="12" stop-index="16" />
</alter-table>
Expand All @@ -1765,4 +1775,13 @@
</primary-key-column>
</add-constraint>
</alter-table>

<alter-table sql-case-id="alter_table_add_unique">
<table name="xwarehouses" start-index="12" stop-index="22" />
<add-constraint start-index="29" stop-index="57">
<index-column name="WarehouseId" start-index="36" stop-index="56" start-delimiter='"' end-delimiter='"'>
<owner start-index="36" stop-index="42" name="XMLDATA" />
</index-column>
</add-constraint>
</alter-table>
</sql-parser-test-cases>
144 changes: 116 additions & 28 deletions test/it/parser/src/main/resources/case/ddl/alter-tablespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,120 @@
<tablespace start-index="17" stop-index="19" name="ts1" />
<rename start-index="31" stop-index="33" name="ts2" />
</alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_read_only"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_read_write"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_add_datafile"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_add_datafile_autoextend_next_maxsize_unlimited"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_add_datafile_size_autoextend_next_maxsize"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_add_datafile_size_reuse"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_add_tempfile_size_autoextend"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_shrink_tempfile"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_shrink_space"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_shrink_space_keep"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_drop_tempfile"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_drop_datafile"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_group_newname"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_group_empty"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_begin_backup"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_end_backup"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_online"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_offline"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_offline_normal"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_offline_immediate"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_offline_temporary"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_flashback_off"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_flashback_on"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_retention_guarantee"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_retention_noguarantee"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_rename_datafile"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_rename_datafile_single"></alter-tablespace>
<alter-tablespace sql-case-id="alter_tablespace_rename_datafile_multiple"></alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_read_only">
<tablespace start-index="17" stop-index="19" name="ts1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_read_write">
<tablespace start-index="17" stop-index="23" name="sales_1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_datafile">
<tablespace start-index="17" stop-index="19" name="ts1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_datafile_autoextend_next_maxsize_unlimited">
<tablespace start-index="17" stop-index="26" name="undotbs_01" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_datafile_size_autoextend_next_maxsize">
<tablespace start-index="17" stop-index="22" name="tbs_03" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_datafile_size_reuse">
<tablespace start-index="17" stop-index="22" name="stocks" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_add_tempfile_size_autoextend">
<tablespace start-index="17" stop-index="25" name="temp_demo" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_shrink_tempfile">
<tablespace start-index="17" stop-index="19" name="ts1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_shrink_space">
<tablespace start-index="17" stop-index="25" name="temp_demo" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_shrink_space_keep">
<tablespace start-index="17" stop-index="23" name="lmtemp1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_drop_tempfile">
<tablespace start-index="17" stop-index="19" name="ts1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_drop_datafile">
<tablespace start-index="17" stop-index="19" name="ts1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_group_newname">
<tablespace start-index="17" stop-index="23" name="lmtemp2" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_group_empty">
<tablespace start-index="17" stop-index="23" name="lmtemp3" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_begin_backup">
<tablespace start-index="17" stop-index="22" name="tbs_01" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_end_backup">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_online">
<tablespace start-index="17" stop-index="22" name="tbs_02" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_offline">
<tablespace start-index="17" stop-index="21" name="tbs_4" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_offline_normal">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_offline_immediate">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_offline_temporary">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_flashback_off">
<tablespace start-index="17" stop-index="21" name="tbs_3" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_flashback_on">
<tablespace start-index="17" stop-index="21" name="tbs_3" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_retention_guarantee">
<tablespace start-index="17" stop-index="23" name="undots1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_retention_noguarantee">
<tablespace start-index="17" stop-index="23" name="undots1" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_rename_datafile">
<tablespace start-index="17" stop-index="22" name="tbs_02" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_rename_datafile_single">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_rename_datafile_multiple">
<tablespace start-index="17" stop-index="21" name="users" />
</alter-tablespace>

<alter-tablespace sql-case-id="alter_tablespace_autoextend_on_next_g">
<tablespace start-index="17" stop-index="22" name="bigtbs" />
</alter-tablespace>
</sql-parser-test-cases>
43 changes: 42 additions & 1 deletion test/it/parser/src/main/resources/case/dml/select-group-by.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,48 @@
<column-item name="user_id" start-index="83" stop-index="89" />
</order-by>
</select>


<select sql-case-id="select_group_by_with_sum_where">
<from>
<join-table join-type="COMMA">
<left>
<simple-table name="sales" alias="s" start-index="65" stop-index="71" />
</left>
<right>
<simple-table name="products" alias="p" start-index="74" stop-index="83" />
</right>
</join-table>
</from>
<projections start-index="7" stop-index="58">
<column-projection name="prod_subcategory" start-index="7" stop-index="24">
<owner start-index="7" stop-index="7" name="p" />
</column-projection>
<aggregation-projection type="SUM" alias="sum_amount" expression="SUM(s.amount_sold)" start-index="27" stop-index="44" />
</projections>
<where start-index="85" stop-index="111">
<expr>
<binary-operation-expression start-index="91" stop-index="111">
<left>
<column name="prod_id" start-index="91" stop-index="99">
<owner name="s" start-index="91" stop-index="91" />
</column>
</left>
<operator>=</operator>
<right>
<column name="prod_id" start-index="103" stop-index="111">
<owner name="p" start-index="103" stop-index="103" />
</column>
</right>
</binary-operation-expression>
</expr>
</where>
<group-by>
<column-item name="prod_subcategory" start-index="122" stop-index="139">
<owner name="p" start-index="122" stop-index="122" />
</column-item>
</group-by>
</select>

<select sql-case-id="select_group_by_with_count">
<from>
<simple-table name="t_order" start-index="53" stop-index="59" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@
<sql-case id="alter_table_move_compress_for_oltp" value="ALTER TABLE table_name MOVE COMPRESS FOR OLTP" db-types="Oracle" />
<sql-case id="alter_table_modify_encrypt_identified_by_password" value="ALTER TABLE t1 MODIFY ( a CLOB ENCRYPT IDENTIFIED BY foo)" db-types="Oracle" />
<sql-case id="alter_table_move_nocompress_parallel" value="ALTER TABLE table_name MOVE NOCOMPRESS PARALLEL" db-types="Oracle" />
<sql-case id="alter_table_modify_constraint_rely" value="ALTER TABLE time MODIFY CONSTRAINT pk_time RELY" db-types="Oracle" />
<sql-case id="alter_table_modify_constraint_rely1" value="ALTER TABLE time MODIFY CONSTRAINT pk_time RELY" db-types="Oracle" />
<sql-case id="alter_table_modify_constraint_rely2" value="ALTER TABLE times MODIFY CONSTRAINT time_pk RELY" db-types="Oracle" />
<sql-case id="alter_table_modify_constraint_rely3" value="ALTER TABLE sales MODIFY CONSTRAINT sales_time_fk RELY" db-types="Oracle" />
<sql-case id="alter_table_enable_row_movement" value="ALTER TABLE table ENABLE ROW MOVEMENT" db-types="Oracle" />
<sql-case id="alter_table_set_interval" value="ALTER TABLE transactions SET INTERVAL()" db-types="Oracle" />
<sql-case id="alter_table_add_primary_key_xmldata" value="ALTER TABLE xwarehouses ADD (PRIMARY KEY(XMLDATA.&quot;WarehouseId&quot;))" db-types="Oracle" />
<sql-case id="alter_table_add_primary_key_xmldata" value="ALTER TABLE xwarehouses ADD (PRIMARY KEY(XMLDATA.&quot;WarehouseId&quot;))" db-types="Oracle" />
<sql-case id="alter_table_add_unique" value="ALTER TABLE xwarehouses ADD (UNIQUE(XMLDATA.&quot;WarehouseId&quot;))" db-types="Oracle" />
</sql-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
'/u02/oracle/rbdb1/user2.dbf'
TO '/u02/oracle/rbdb1/users01.dbf',
'/u02/oracle/rbdb1/users02.dbf'" db-types="Oracle" />
<sql-case id="alter_tablespace_autoextend_on_next_g" value="ALTER TABLESPACE bigtbs AUTOEXTEND ON NEXT 20G" db-types="Oracle" />
</sql-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<sql-cases>
<sql-case id="select_group_by_with_sum" value="SELECT SUM(order_id) AS orders_sum, user_id FROM t_order GROUP BY user_id ORDER BY user_id" />
<sql-case id="select_group_by_with_sum_where" value="SELECT p.prod_subcategory, SUM(s.amount_sold) AS sum_amount FROM sales s, products p WHERE s.prod_id = p.prod_id GROUP BY p.prod_subcategory" db-types="Oracle" />
<sql-case id="select_group_by_with_count" value="SELECT COUNT(order_id) AS orders_count, user_id FROM t_order GROUP BY user_id ORDER BY user_id" />
<sql-case id="select_group_by_with_max" value="SELECT MAX(order_id) AS max_order_id, user_id FROM t_order GROUP BY user_id ORDER BY user_id" />
<sql-case id="select_group_by_with_min" value="SELECT MIN(order_id) AS min_order_id, user_id FROM t_order GROUP BY user_id ORDER BY user_id" />
Expand Down

0 comments on commit 2ee5baf

Please sign in to comment.