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 feb031987d5 Add more test cases on Hive SQL parser (#37671)
feb031987d5 is described below
commit feb031987d5e3601dc7d91b28da9439031795e60
Author: Haoran Meng <[email protected]>
AuthorDate: Wed Jan 7 15:17:01 2026 +0800
Add more test cases on Hive SQL parser (#37671)
---
.../src/main/resources/case/dml/insert-hive.xml | 94 +++++
.../src/main/resources/case/dml/select-hive.xml | 387 +++++++++++++++++++++
.../resources/sql/supported/dml/insert-hive.xml | 25 ++
.../resources/sql/supported/dml/select-hive.xml | 39 +++
4 files changed, 545 insertions(+)
diff --git a/test/it/parser/src/main/resources/case/dml/insert-hive.xml
b/test/it/parser/src/main/resources/case/dml/insert-hive.xml
new file mode 100644
index 00000000000..c56bf5726e9
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/dml/insert-hive.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<sql-parser-test-cases>
+ <insert sql-case-id="hive_insert_into_values">
+ <table name="t_order" start-index="12" stop-index="18" />
+ <columns start-index="19" stop-index="19" />
+ <values>
+ <value>
+ <assignment-value>
+ <literal-expression value="1" start-index="28"
stop-index="28" />
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="a" start-index="31"
stop-index="33" />
+ </assignment-value>
+ </value>
+ </values>
+ </insert>
+
+ <insert sql-case-id="hive_insert_into_columns_values">
+ <table name="t_order" start-index="12" stop-index="18" />
+ <columns start-index="20" stop-index="29">
+ <column name="id" start-index="21" stop-index="22" />
+ <column name="name" start-index="25" stop-index="28" />
+ </columns>
+ <values>
+ <value>
+ <assignment-value>
+ <literal-expression value="1" start-index="39"
stop-index="39" />
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="a" start-index="42"
stop-index="44" />
+ </assignment-value>
+ </value>
+ </values>
+ </insert>
+
+ <insert sql-case-id="hive_insert_overwrite_select">
+ <table name="t_order" start-index="23" stop-index="29" />
+ <columns start-index="0" stop-index="0" />
+ <select>
+ <projections start-index="38" stop-index="38">
+ <shorthand-projection start-index="38" stop-index="38" />
+ </projections>
+ <from>
+ <simple-table name="t_source" start-index="45" stop-index="52"
/>
+ </from>
+ </select>
+ </insert>
+
+ <insert sql-case-id="hive_insert_partition">
+ <table name="t_order" start-index="18" stop-index="24" />
+ <columns start-index="47" stop-index="47" />
+ <values>
+ <value>
+ <assignment-value>
+ <literal-expression value="1" start-index="56"
stop-index="56" />
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="a" start-index="59"
stop-index="61" />
+ </assignment-value>
+ </value>
+ </values>
+ </insert>
+
+ <insert sql-case-id="hive_from_insert">
+ <table name="t_target" start-index="37" stop-index="44" />
+ <columns start-index="14" stop-index="14" />
+ <select>
+ <projections start-index="53" stop-index="53">
+ <shorthand-projection start-index="53" stop-index="53" />
+ </projections>
+ <from>
+ <simple-table name="t_source" start-index="5" stop-index="12"
/>
+ </from>
+ </select>
+ </insert>
+
+</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/case/dml/select-hive.xml
b/test/it/parser/src/main/resources/case/dml/select-hive.xml
new file mode 100644
index 00000000000..2d62676207a
--- /dev/null
+++ b/test/it/parser/src/main/resources/case/dml/select-hive.xml
@@ -0,0 +1,387 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<sql-parser-test-cases>
+ <select sql-case-id="hive_select_simple">
+ <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>
+ </select>
+
+ <select sql-case-id="hive_select_with_where">
+ <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="39">
+ <expr>
+ <binary-operation-expression start-index="28" stop-index="39">
+ <left>
+ <column name="order_id" start-index="28"
stop-index="35" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <literal-expression value="1" start-index="39"
stop-index="39" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="hive_select_group_by">
+ <projections start-index="7" stop-index="23">
+ <column-projection name="user_id" start-index="7" stop-index="13"
/>
+ <aggregation-projection type="COUNT" expression="(*)"
start-index="16" stop-index="23" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="30" stop-index="36" />
+ </from>
+ <group-by>
+ <column-item name="user_id" start-index="47" stop-index="53" />
+ </group-by>
+ </select>
+
+ <select sql-case-id="hive_select_having">
+ <projections start-index="7" stop-index="23">
+ <column-projection name="user_id" start-index="7" stop-index="13"
/>
+ <aggregation-projection type="COUNT" expression="(*)"
start-index="16" stop-index="23" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="30" stop-index="36" />
+ </from>
+ <group-by>
+ <column-item name="user_id" start-index="47" stop-index="53" />
+ </group-by>
+ <having start-index="55" stop-index="73">
+ <expr>
+ <binary-operation-expression start-index="62" stop-index="73">
+ <left>
+ <aggregation-projection type="COUNT" expression="(*)"
start-index="62" stop-index="69" />
+ </left>
+ <operator>></operator>
+ <right>
+ <literal-expression value="1" start-index="73"
stop-index="73" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </having>
+ </select>
+
+ <select sql-case-id="hive_select_order_by">
+ <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>
+ <order-by>
+ <column-item name="order_id" order-direction="DESC"
start-index="31" stop-index="38" />
+ </order-by>
+ </select>
+
+ <select sql-case-id="hive_select_limit">
+ <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>
+ <limit start-index="22" stop-index="29">
+ <row-count value="10" start-index="28" stop-index="29" />
+ </limit>
+ </select>
+
+ <select sql-case-id="hive_select_limit_offset">
+ <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>
+ <limit start-index="22" stop-index="38">
+ <row-count value="10" start-index="28" stop-index="29" />
+ <offset value="5" start-index="38" stop-index="38" />
+ </limit>
+ </select>
+
+ <select sql-case-id="hive_select_join">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <join-table join-type="INNER" start-index="14" stop-index="63">
+ <left>
+ <simple-table name="t_order" alias="o" start-index="14"
stop-index="22" />
+ </left>
+ <right>
+ <simple-table name="t_item" alias="i" start-index="29"
stop-index="36" />
+ </right>
+ <on-condition start-index="41" stop-index="63">
+ <binary-operation-expression start-index="41"
stop-index="63">
+ <left>
+ <column name="order_id" start-index="41"
stop-index="50">
+ <owner name="o" start-index="41"
stop-index="41" />
+ </column>
+ </left>
+ <operator>=</operator>
+ <right>
+ <column name="order_id" start-index="54"
stop-index="63">
+ <owner name="i" start-index="54"
stop-index="54" />
+ </column>
+ </right>
+ </binary-operation-expression>
+ </on-condition>
+ </join-table>
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_left_join">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <join-table join-type="LEFT" start-index="14" stop-index="68">
+ <left>
+ <simple-table name="t_order" alias="o" start-index="14"
stop-index="22" />
+ </left>
+ <right>
+ <simple-table name="t_item" alias="i" start-index="34"
stop-index="41" />
+ </right>
+ <on-condition start-index="46" stop-index="68">
+ <binary-operation-expression start-index="46"
stop-index="68">
+ <left>
+ <column name="order_id" start-index="46"
stop-index="55">
+ <owner name="o" start-index="46"
stop-index="46" />
+ </column>
+ </left>
+ <operator>=</operator>
+ <right>
+ <column name="order_id" start-index="59"
stop-index="68">
+ <owner name="i" start-index="59"
stop-index="59" />
+ </column>
+ </right>
+ </binary-operation-expression>
+ </on-condition>
+ </join-table>
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_right_join">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <join-table join-type="RIGHT" start-index="14" stop-index="69">
+ <left>
+ <simple-table name="t_order" alias="o" start-index="14"
stop-index="22" />
+ </left>
+ <right>
+ <simple-table name="t_item" alias="i" start-index="35"
stop-index="42" />
+ </right>
+ <on-condition start-index="47" stop-index="69">
+ <binary-operation-expression start-index="47"
stop-index="69">
+ <left>
+ <column name="order_id" start-index="47"
stop-index="56">
+ <owner name="o" start-index="47"
stop-index="47" />
+ </column>
+ </left>
+ <operator>=</operator>
+ <right>
+ <column name="order_id" start-index="60"
stop-index="69">
+ <owner name="i" start-index="60"
stop-index="60" />
+ </column>
+ </right>
+ </binary-operation-expression>
+ </on-condition>
+ </join-table>
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_cross_join">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <join-table join-type="INNER" start-index="14" stop-index="29">
+ <left>
+ <simple-table name="t1" start-index="14" stop-index="15" />
+ </left>
+ <right>
+ <simple-table name="t2" start-index="28" stop-index="29" />
+ </right>
+ </join-table>
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_union">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t1" start-index="14" stop-index="15" />
+ </from>
+ <combine combine-type="UNION" start-index="17" stop-index="38">
+ <left>
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t1" start-index="14" stop-index="15" />
+ </from>
+ </left>
+ <right>
+ <projections start-index="30" stop-index="30">
+ <shorthand-projection start-index="30" stop-index="30" />
+ </projections>
+ <from>
+ <simple-table name="t2" start-index="37" stop-index="38" />
+ </from>
+ </right>
+ </combine>
+ </select>
+
+ <select sql-case-id="hive_select_union_all">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t1" start-index="14" stop-index="15" />
+ </from>
+ <combine combine-type="UNION_ALL" start-index="17" stop-index="42">
+ <left>
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <simple-table name="t1" start-index="14" stop-index="15" />
+ </from>
+ </left>
+ <right>
+ <projections start-index="34" stop-index="34">
+ <shorthand-projection start-index="34" stop-index="34" />
+ </projections>
+ <from>
+ <simple-table name="t2" start-index="41" stop-index="42" />
+ </from>
+ </right>
+ </combine>
+ </select>
+
+ <select sql-case-id="hive_select_distinct">
+ <projections start-index="16" stop-index="22" distinct-row="true">
+ <column-projection name="user_id" start-index="16" stop-index="22"
/>
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="29" stop-index="35" />
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_window">
+ <!-- SELECT user_id, RANK() OVER (PARTITION BY city ORDER BY salary
DESC) FROM t_employee -->
+ <projections start-index="7" stop-index="67">
+ <column-projection name="user_id" start-index="7" stop-index="13"
/>
+ <expression-projection text="RANK() OVER (PARTITION BY city ORDER
BY salary DESC)" start-index="16" stop-index="67"/>
+ </projections>
+ <from>
+ <simple-table name="t_employee" start-index="74" stop-index="83" />
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_subquery">
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <from>
+ <subquery-table alias="t" start-index="14" stop-index="38">
+ <subquery start-index="14" stop-index="38">
+ <select>
+ <projections start-index="22" stop-index="22">
+ <shorthand-projection start-index="22"
stop-index="22" />
+ </projections>
+ <from>
+ <simple-table name="t_order" start-index="29"
stop-index="35" />
+ </from>
+ </select>
+ </subquery>
+ </subquery-table>
+ </from>
+ </select>
+
+ <select sql-case-id="hive_select_substring">
+ <projections start-index="7" stop-index="28">
+ <expression-projection text="SUBSTRING('abc', 1, 2)"
start-index="7" stop-index="28">
+ <expr>
+ <function function-name="SUBSTRING" start-index="7"
stop-index="28" text="SUBSTRING('abc', 1, 2)">
+ <parameter>
+ <literal-expression value="abc" start-index="17"
stop-index="21" />
+ </parameter>
+ <parameter>
+ <literal-expression value="1" start-index="24"
stop-index="24" />
+ </parameter>
+ <parameter>
+ <literal-expression value="2" start-index="27"
stop-index="27" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="hive_select_trim">
+ <projections start-index="7" stop-index="31">
+ <expression-projection text="TRIM(BOTH ' ' FROM ' a ')"
start-index="7" stop-index="31">
+ <expr>
+ <function function-name="TRIM" start-index="7"
stop-index="31" text="TRIM(BOTH ' ' FROM ' a ')">
+ <parameter>
+ <literal-expression value="BOTH" start-index="12"
stop-index="15" />
+ </parameter>
+ <parameter>
+ <literal-expression value=" " start-index="17"
stop-index="19" />
+ </parameter>
+ <parameter>
+ <literal-expression value=" a " start-index="26"
stop-index="30" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+ <select sql-case-id="hive_select_extract">
+ <projections start-index="7" stop-index="37">
+ <expression-projection text="EXTRACT(YEAR FROM '2023-01-01')"
start-index="7" stop-index="37">
+ <expr>
+ <function function-name="EXTRACT" start-index="7"
stop-index="37" text="EXTRACT(YEAR FROM '2023-01-01')">
+ <parameter>
+ <literal-expression value="YEAR" start-index="15"
stop-index="18" />
+ </parameter>
+ <parameter>
+ <literal-expression value="2023-01-01"
start-index="25" stop-index="36" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
+
+</sql-parser-test-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/insert-hive.xml
b/test/it/parser/src/main/resources/sql/supported/dml/insert-hive.xml
new file mode 100644
index 00000000000..903914ef175
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/dml/insert-hive.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<sql-cases>
+ <sql-case id="hive_insert_into_values" value="INSERT INTO t_order VALUES
(1, 'a')" db-types="Hive" />
+ <sql-case id="hive_insert_into_columns_values" value="INSERT INTO t_order
(id, name) VALUES (1, 'a')" db-types="Hive" />
+ <sql-case id="hive_insert_overwrite_select" value="INSERT OVERWRITE TABLE
t_order SELECT * FROM t_source" db-types="Hive" />
+ <sql-case id="hive_insert_partition" value="INSERT INTO TABLE t_order
PARTITION (ds='2020') VALUES (1, 'a')" db-types="Hive" />
+ <sql-case id="hive_from_insert" value="FROM t_source INSERT OVERWRITE
TABLE t_target SELECT *" db-types="Hive" />
+</sql-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/select-hive.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select-hive.xml
new file mode 100644
index 00000000000..aaeb51b0176
--- /dev/null
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-hive.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<sql-cases>
+ <sql-case id="hive_select_simple" value="SELECT * FROM t_order"
db-types="Hive" />
+ <sql-case id="hive_select_with_where" value="SELECT * FROM t_order WHERE
order_id = 1" db-types="Hive" />
+ <sql-case id="hive_select_group_by" value="SELECT user_id, COUNT(*) FROM
t_order GROUP BY user_id" db-types="Hive" />
+ <sql-case id="hive_select_having" value="SELECT user_id, COUNT(*) FROM
t_order GROUP BY user_id HAVING COUNT(*) > 1" db-types="Hive" />
+ <sql-case id="hive_select_order_by" value="SELECT * FROM t_order ORDER BY
order_id DESC" db-types="Hive" />
+ <sql-case id="hive_select_limit" value="SELECT * FROM t_order LIMIT 10"
db-types="Hive" />
+ <sql-case id="hive_select_limit_offset" value="SELECT * FROM t_order LIMIT
10 OFFSET 5" db-types="Hive" />
+ <sql-case id="hive_select_join" value="SELECT * FROM t_order o JOIN t_item
i ON o.order_id = i.order_id" db-types="Hive" />
+ <sql-case id="hive_select_left_join" value="SELECT * FROM t_order o LEFT
JOIN t_item i ON o.order_id = i.order_id" db-types="Hive" />
+ <sql-case id="hive_select_right_join" value="SELECT * FROM t_order o RIGHT
JOIN t_item i ON o.order_id = i.order_id" db-types="Hive" />
+ <sql-case id="hive_select_cross_join" value="SELECT * FROM t1 CROSS JOIN
t2" db-types="Hive" />
+ <sql-case id="hive_select_union" value="SELECT * FROM t1 UNION SELECT *
FROM t2" db-types="Hive" />
+ <sql-case id="hive_select_union_all" value="SELECT * FROM t1 UNION ALL
SELECT * FROM t2" db-types="Hive" />
+ <sql-case id="hive_select_distinct" value="SELECT DISTINCT user_id FROM
t_order" db-types="Hive" />
+ <sql-case id="hive_select_window" value="SELECT user_id, RANK() OVER
(PARTITION BY city ORDER BY salary DESC) FROM t_employee" db-types="Hive" />
+ <sql-case id="hive_select_subquery" value="SELECT * FROM (SELECT * FROM
t_order) t" db-types="Hive" />
+ <sql-case id="hive_select_substring" value="SELECT SUBSTRING('abc', 1, 2)"
db-types="Hive" />
+ <sql-case id="hive_select_trim" value="SELECT TRIM(BOTH ' ' FROM ' a ')"
db-types="Hive" />
+ <sql-case id="hive_select_extract" value="SELECT EXTRACT(YEAR FROM
'2023-01-01')" db-types="Hive" />
+</sql-cases>