未验证 提交 a9767bd0 编写于 作者: J Juan Pan(Trista) 提交者: GitHub

Support query with between subquery (#4752)

上级 7dea4fd0
......@@ -21,4 +21,8 @@
<!-- <sql-case id="select_sub_query_with_multiple_tables" value="SELECT t.* FROM (SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id and o.order_id IN (?, ?)) t ORDER BY t.item_id" db-types="SQLServer,Oracle" />-->
<!-- <sql-case id="select_sub_query_with_order_by" value="SELECT COUNT(1) as orders_count FROM (SELECT * FROM t_order ORDER BY order_id desc) t" db-types="H2,MySQL,PostgreSQL,Oracle" />-->
<!-- <sql-case id="select_sub_query_with_group_by" value="SELECT COUNT(1) as order_items_count FROM (SELECT order_id FROM t_order_item GROUP BY order_id) t" db-types="H2,MySQL,PostgreSQL,Oracle" />-->
<!-- <sql-case id="select_sub_query_with_table" value="SELECT t.* FROM (SELECT * FROM t_order o WHERE o.order_id IN (?, ?)) t ORDER BY t.item_id" />-->
<sql-case id="select_with_equal_subquery" value="SELECT * FROM t_order WHERE user_id = (SELECT user_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
<sql-case id="select_with_in_subquery" value="SELECT * FROM t_order WHERE user_id in (SELECT user_id FROM t_order_item WHERE id in (10, 11))" db-types="MySQL" />
<sql-case id="select_with_between_subquery" value="SELECT * FROM t_order WHERE user_id between (select user_id from t_order_item where order_id = 10) and ?" db-types="MySQL" />
</sql-cases>
......@@ -46,8 +46,6 @@
<sql-case id="select_between_with_geography" value="SELECT * FROM t_order WHERE rule BETWEEN ?::jsonb AND ?::jsonb AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND order_id = ?" db-types="PostgreSQL" />
<sql-case id="select_with_schema" value="SELECT * FROM db1.t_order" />
<sql-case id="select_special_function_nested" value="SELECT sum(if(status=0, 1, 0)) func_status FROM t_order WHERE user_id = ? AND order_id = ?" db-types="MySQL" />
<sql-case id="select_with_equal_subquery" value="SELECT * FROM t_order WHERE user_id = (SELECT user_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
<sql-case id="select_with_in_subquery" value="SELECT * FROM t_order WHERE user_id in (SELECT user_id FROM t_order_item WHERE id in (10, 11))" db-types="MySQL" />
<sql-case id="select_with_interval_function" value="SELECT INTERVAL(status,1,5) func_status FROM t_order WHERE user_id = ? AND order_id = ?" db-types="MySQL" />
<sql-case id="select_with_left_function" value="SELECT CONCAT(LEFT(status, 7), 'test') FROM t_order_item WHERE user_id = 10" db-types="MySQL" />
<sql-case id="select_for_update" value="SELECT * FROM t_order WHERE user_id = ? FOR UPDATE" lock-clause="true"/>
......
......@@ -386,6 +386,9 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor<ASTNode> {
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
}
......
......@@ -368,6 +368,9 @@ public abstract class OracleVisitor extends OracleStatementBaseVisitor<ASTNode>
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
}
......
......@@ -370,6 +370,9 @@ public abstract class PostgreSQLVisitor extends PostgreSQLStatementBaseVisitor<A
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
}
......
......@@ -359,6 +359,9 @@ public abstract class SQL92Visitor extends SQL92StatementBaseVisitor<ASTNode> {
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
}
......
......@@ -368,6 +368,9 @@ public abstract class SQLServerVisitor extends SQLServerStatementBaseVisitor<AST
if (astNode instanceof ParameterMarkerValue) {
return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue());
}
if (astNode instanceof SubquerySegment) {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
}
......
......@@ -46,4 +46,122 @@
</projections>
</select>
-->
<!-- <select sql-case-id="select_sub_query_with_table" parameters="1, 2">-->
<!-- <table name="t_order" alias="o" start-index="33" stop-index="39" />-->
<!-- <conditions>-->
<!-- <condition column-name="order_id" table-name="t_order" operator="IN">-->
<!-- <value index="0" literal="1" type="int" />-->
<!-- <value index="1" literal="2" type="int" />-->
<!-- </condition>-->
<!-- </conditions>-->
<!-- </select>-->
<select sql-case-id="select_with_equal_subquery">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where start-index="22" stop-index="85">
<and-predicate>
<predicate start-index="28" literal-stop-index="85">
<column-left-value name="user_id" start-index="28" stop-index="34" />
<operator type="=" />
<compare-right-value>
<subquery>
<select>
<table name="t_order_item" start-index="59" stop-index="70" />
<projections start-index="46" stop-index="52">
<column-projection name="user_id" start-index="46" stop-index="52" />
</projections>
<where start-index="72" stop-index="85">
<and-predicate>
<predicate start-index="78" literal-stop-index="84">
<column-left-value name="id" start-index="78" stop-index="79" />
<operator type="=" />
<compare-right-value>
<literal-expression value="10" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>
</subquery>
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>
<select sql-case-id="select_with_in_subquery">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where start-index="22" stop-index="93">
<and-predicate>
<predicate start-index="28" literal-stop-index="93">
<column-left-value name="user_id" start-index="28" stop-index="34" />
<in-right-value>
<subquery>
<select>
<table name="t_order_item" start-index="60" stop-index="71" />
<projections start-index="47" stop-index="53">
<column-projection name="user_id" start-index="47" stop-index="53" />
</projections>
<where start-index="73" stop-index="92">
<and-predicate>
<predicate start-index="79" literal-stop-index="92">
<column-left-value name="id" start-index="79" stop-index="80" />
<in-right-value>
<literal-expression value="10" />
<literal-expression value="11" />
</in-right-value>
</predicate>
</and-predicate>
</where>
</select>
</subquery>
</in-right-value>
</predicate>
</and-predicate>
</where>
</select>
<select sql-case-id="select_with_between_subquery" parameters="12">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where start-index="22" stop-index="106">
<and-predicate>
<predicate start-index="28" stop-index="103" literal-stop-index="104">
<column-left-value name="user_id" start-index="28" stop-index="34" />
<between-right-value>
<between-subquery>
<select>
<table name="t_order_item" start-index="65" stop-index="76" />
<projections start-index="52" stop-index="58">
<column-projection name="user_id" start-index="52" stop-index="58" />
</projections>
<where start-index="78" stop-index="96">
<and-predicate>
<predicate start-index="84" stop-index="96" literal-stop-index="96">
<column-left-value name="order_id" start-index="84" stop-index="91" />
<operator type="=" />
<compare-right-value>
<literal-expression value="10" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>
</between-subquery>
<and-parameter-marker-expression value="0" />
<and-literal-expression value="12" />
</between-right-value>
</predicate>
</and-predicate>
</where>
</select>
</sql-parser-test-cases>
......@@ -1282,77 +1282,6 @@
</where>
</select>
<select sql-case-id="select_with_equal_subquery">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where start-index="22" stop-index="85">
<and-predicate>
<predicate start-index="28" literal-stop-index="85">
<column-left-value name="user_id" start-index="28" stop-index="34" />
<operator type="=" />
<compare-right-value>
<subquery>
<select>
<table name="t_order_item" start-index="59" stop-index="70" />
<projections start-index="46" stop-index="52">
<column-projection name="user_id" start-index="46" stop-index="52" />
</projections>
<where start-index="72" stop-index="85">
<and-predicate>
<predicate start-index="78" literal-stop-index="84">
<column-left-value name="id" start-index="78" stop-index="79" />
<operator type="=" />
<compare-right-value>
<literal-expression value="10" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>
</subquery>
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>
<select sql-case-id="select_with_in_subquery">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where start-index="22" stop-index="93">
<and-predicate>
<predicate start-index="28" literal-stop-index="93">
<column-left-value name="user_id" start-index="28" stop-index="34" />
<in-right-value>
<subquery>
<select>
<table name="t_order_item" start-index="60" stop-index="71" />
<projections start-index="47" stop-index="53">
<column-projection name="user_id" start-index="47" stop-index="53" />
</projections>
<where start-index="73" stop-index="92">
<and-predicate>
<predicate start-index="79" literal-stop-index="92">
<column-left-value name="id" start-index="79" stop-index="80" />
<in-right-value>
<literal-expression value="10" />
<literal-expression value="11" />
</in-right-value>
</predicate>
</and-predicate>
</where>
</select>
</subquery>
</in-right-value>
</predicate>
</and-predicate>
</where>
</select>
<select sql-case-id="select_with_interval_function" parameters="12, 1000">
<table name="t_order" start-index="45" stop-index="51" />
<projections start-index="7" stop-index="38">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册