This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 37b44043674 Add more clickhouse parser test cases (#37600)
37b44043674 is described below
commit 37b44043674b861ae1f57be6ffab94f5dcf8339c
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 1 14:01:48 2026 +0800
Add more clickhouse parser test cases (#37600)
---
.../src/main/resources/case/dml/clickhouse.xml | 228 +++++++++++++++++++++
.../resources/sql/supported/dml/clickhouse.xml | 8 +
2 files changed, 236 insertions(+)
diff --git a/test/it/parser/src/main/resources/case/dml/clickhouse.xml
b/test/it/parser/src/main/resources/case/dml/clickhouse.xml
index 4d60f10bd2e..4354da8da1d 100644
--- a/test/it/parser/src/main/resources/case/dml/clickhouse.xml
+++ b/test/it/parser/src/main/resources/case/dml/clickhouse.xml
@@ -287,4 +287,232 @@
<column-item name="merged_id" start-index="351" stop-index="359" />
</order-by>
</select>
+
+ <select sql-case-id="clickhouse_select_literals">
+ <projections start-index="7" stop-index="70">
+ <column-projection name="0x1A" alias="hex_lit" start-index="7"
stop-index="21" />
+ <column-projection name="0b101" alias="bit_lit" start-index="24"
stop-index="39" />
+ <column-projection name="TRUE" alias="bool_lit" start-index="42"
stop-index="57" />
+ <column-projection name="NULL" alias="nil" start-index="60"
stop-index="70" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="77" stop-index="83" />
+ </from>
+ </select>
+
+ <select sql-case-id="clickhouse_select_functions_right_join">
+ <projections start-index="7" stop-index="159">
+ <expression-projection alias="pos" text="POSITION('a' IN 'abc')"
start-index="7" stop-index="35">
+ <expr>
+ <function function-name="POSITION" start-index="7"
stop-index="28" text="POSITION('a' IN 'abc')">
+ </function>
+ </expr>
+ </expression-projection>
+ <expression-projection alias="price" text="CAST(order_id AS
DATETIME64(3))" start-index="38" stop-index="77">
+ <expr>
+ <function function-name="CAST" start-index="38"
stop-index="68" text="CAST(order_id AS DATETIME64(3))">
+ <parameter>
+ <column name="order_id" start-index="43"
stop-index="50" />
+ </parameter>
+ <parameter>
+ <data-type value="DATETIME64" start-index="55"
stop-index="67">
+ <data-type-length precision="3"
start-index="65" stop-index="67" />
+ </data-type>
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ <expression-projection alias="tiny" text="CAST(1 AS INT8)"
start-index="80" stop-index="102">
+ <expr>
+ <function function-name="CAST" start-index="80"
stop-index="94" text="CAST(1 AS INT8)">
+ <parameter>
+ <literal-expression value="1" start-index="85"
stop-index="85" />
+ </parameter>
+ <parameter>
+ <data-type value="INT8" start-index="90"
stop-index="93" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ <expression-projection alias="inter" text="INTERVAL2DAY"
start-index="105" stop-index="127">
+ <expr>
+ <common-expression text="INTERVAL2DAY" start-index="105"
stop-index="118" />
+ </expr>
+ </expression-projection>
+ <aggregation-distinct-projection type="COUNT"
expression="COUNT(DISTINCT user_id)" distinct-inner-expression="user_id"
alias="cnt" start-index="130" stop-index="152" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="166" stop-index="172" />
+ </from>
+ <order-by>
+ <index-item index="1" order-direction="ASC" start-index="183"
stop-index="183" />
+ </order-by>
+ </select>
+
+ <select sql-case-id="clickhouse_select_not_predicate">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="14" stop-index="20" />
+ </from>
+ <where start-index="22" stop-index="43">
+ <expr>
+ <not-expression start-index="28" stop-index="43">
+ <expr>
+ <binary-operation-expression start-index="33"
stop-index="42">
+ <left>
+ <column name="status" start-index="33"
stop-index="38" />
+ </left>
+ <operator>></operator>
+ <right>
+ <literal-expression value="0" start-index="42"
stop-index="42" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </not-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="clickhouse_select_not_like">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="14" stop-index="20" />
+ </from>
+ <where start-index="22" stop-index="47">
+ <expr>
+ <binary-operation-expression start-index="28" stop-index="47">
+ <left>
+ <column name="status" start-index="28" stop-index="33"
/>
+ </left>
+ <operator>NOT LIKE</operator>
+ <right>
+ <list-expression start-index="44" stop-index="47">
+ <items>
+ <literal-expression value="A%"
start-index="44" stop-index="47" />
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="clickhouse_select_in_list_and_subquery">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="14" stop-index="20" />
+ </from>
+ <where start-index="22" stop-index="122">
+ <expr>
+ <binary-operation-expression start-index="28" stop-index="122">
+ <left>
+ <binary-operation-expression start-index="28"
stop-index="99">
+ <left>
+ <in-expression start-index="28"
stop-index="47">
+ <not>false</not>
+ <left>
+ <column name="user_id"
start-index="28" stop-index="34" />
+ </left>
+ <right>
+ <list-expression start-index="39"
stop-index="47">
+ <items>
+ <literal-expression value="1"
start-index="40" stop-index="40" />
+ </items>
+ <items>
+ <literal-expression value="2"
start-index="43" stop-index="43" />
+ </items>
+ <items>
+ <literal-expression value="3"
start-index="46" stop-index="46" />
+ </items>
+ </list-expression>
+ </right>
+ </in-expression>
+ </left>
+ <operator>AND</operator>
+ <right>
+ <in-expression start-index="53"
stop-index="99">
+ <not>false</not>
+ <left>
+ <column name="order_id"
start-index="53" stop-index="60" />
+ </left>
+ <right>
+ <subquery start-index="65"
stop-index="99">
+ <select>
+ <projections start-index="73"
stop-index="80">
+ <column-projection
name="order_id" start-index="73" stop-index="80" />
+ </projections>
+ <from>
+ <simple-table
name="t_order_item" start-index="87" stop-index="98" />
+ </from>
+ </select>
+ </subquery>
+ </right>
+ </in-expression>
+ </right>
+ </binary-operation-expression>
+ </left>
+ <operator>AND</operator>
+ <right>
+ <binary-operation-expression start-index="105"
stop-index="122">
+ <left>
+ <column name="status" start-index="105"
stop-index="110" />
+ </left>
+ <operator>IS</operator>
+ <right>
+ <literal-expression value="NOT NULL"
start-index="115" stop-index="122" />
+ </right>
+ </binary-operation-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="clickhouse_select_param_projection" parameters="1">
+ <projections start-index="7" stop-index="22">
+ <expression-projection alias="param_alias" text="?"
start-index="7" stop-index="22">
+ <expr>
+ <parameter-marker-expression parameter-index="0"
start-index="7" stop-index="7" />
+ <literal-expression value="1" start-index="7"
stop-index="7" />
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="clickhouse_select_subquery_projection">
+ <from>
+ <simple-table name="t_order" start-index="34" stop-index="40" />
+ </from>
+ <projections start-index="7" stop-index="27">
+ <subquery-projection start-index="7" stop-index="27"
alias="sub_val" text="(SELECT 1)" literal-text="(SELECT 1)">
+ <subquery>
+ <select>
+ <projections start-index="15" stop-index="15">
+ <expression-projection start-index="15"
stop-index="15" text="1" />
+ </projections>
+ </select>
+ </subquery>
+ </subquery-projection>
+ </projections>
+ </select>
+ <update sql-case-id="clickhouse_update_without_where">
+ <table start-index="7" stop-index="13">
+ <simple-table name="t_order" start-index="7" stop-index="13" />
+ </table>
+ <set start-index="15" stop-index="28">
+ <assignment start-index="19" stop-index="28">
+ <column name="status" start-index="19" stop-index="24" />
+ <assignment-value>
+ <literal-expression value="0" start-index="28"
stop-index="28" />
+ </assignment-value>
+ </assignment>
+ </set>
+ </update>
+
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/clickhouse.xml
b/test/it/parser/src/main/resources/sql/supported/dml/clickhouse.xml
index 3f120c120a8..b7d90cd53bd 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/clickhouse.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/clickhouse.xml
@@ -22,4 +22,12 @@
<sql-case id="clickhouse_update_left_join" value="UPDATE t_order o LEFT
JOIN t_order_item i ON o.order_id = i.order_id SET o.status = 1, i.status = 2
WHERE o.order_id = ? AND i.user_id = ?" db-types="ClickHouse" />
<sql-case id="clickhouse_delete_with_owner" value="ALTER TABLE db1.t_order
DELETE WHERE order_id = ?" db-types="ClickHouse" />
<sql-case id="clickhouse_select_distinct_join_using" value="SELECT
DISTINCT *, o.*, sum(i.amount) AS total_amount, o.status AS status_alias,
o.order_id + i.order_id AS merged_id, toString(o.user_id) AS user_text FROM
t_order o JOIN t_order_item i USING (order_id) WHERE o.status = ? AND i.amount
> 100 GROUP BY o.order_id, i.order_id, o.status, o.user_id HAVING
sum(i.amount) > 1000 ORDER BY total_amount DESC, merged_id"
db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_literals" value="SELECT 0x1A AS hex_lit,
0b101 AS bit_lit, TRUE AS bool_lit, NULL AS nil FROM t_order"
db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_functions_right_join" value="SELECT
POSITION('a' IN 'abc') AS pos, CAST(order_id AS DATETIME64(3)) AS price, CAST(1
AS INT8) AS tiny, INTERVAL 2 DAY AS inter, COUNT(DISTINCT user_id) AS cnt FROM
t_order ORDER BY 1" db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_not_predicate" value="SELECT * FROM
t_order WHERE NOT (status > 0)" db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_not_like" value="SELECT * FROM t_order
WHERE status NOT LIKE 'A%'" db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_in_list_and_subquery" value="SELECT * FROM
t_order WHERE user_id IN (1, 2, 3) AND order_id IN (SELECT order_id FROM
t_order_item) AND status IS NOT NULL" db-types="ClickHouse" />
+ <sql-case id="clickhouse_select_param_projection" value="SELECT ? AS
param_alias" db-types="ClickHouse" case-types="PLACEHOLDER" />
+ <sql-case id="clickhouse_select_subquery_projection" value="SELECT (SELECT
1) AS sub_val FROM t_order" db-types="ClickHouse" />
+ <sql-case id="clickhouse_update_without_where" value="UPDATE t_order SET
status = 0" db-types="ClickHouse" />
</sql-cases>