Skip to content

Commit

Permalink
Add mysql select InExpression parse (#25535) (#26476)
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaoAK47 authored Jul 4, 2023
1 parent 5f8032c commit 71c24ee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,11 @@ private ASTNode createProjection(final ProjectionContext ctx, final AliasSegment
result.setAlias(alias);
return result;
}
if (projection instanceof InExpression) {
ExpressionProjectionSegment result = new ExpressionProjectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx.expr()), (InExpression) projection);
result.setAlias(alias);
return result;
}
LiteralExpressionSegment column = (LiteralExpressionSegment) projection;
ExpressionProjectionSegment result = null == alias
? new ExpressionProjectionSegment(column.getStartIndex(), column.getStopIndex(), String.valueOf(column.getLiterals()), column)
Expand Down
37 changes: 37 additions & 0 deletions test/it/parser/src/main/resources/case/dml/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,43 @@
-->

<sql-parser-test-cases>
<select sql-case-id="select_with_exist_in">
<projections start-index="7" stop-index="93">
<expression-projection text="+0 IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1)" start-index="7" stop-index="93">
<expr>
<in-expression start-index="8" stop-index="92">
<left start-index="8" stop-index="9">
<literal-expression start-index="8" stop-index="9" value="0" />
</left>
<right start-index="13" stop-index="92">
<list-expression start-index="13" stop-index="92">
<items>
<common-expression start-index="14" stop-index="66" text="0b111111111111111111111111111111111111111111111111111" />
</items>
<items>
<function start-index="68" stop-index="83" text="rpad(1.0,2048,1)" function-name="rpad">
<parameter>
<literal-expression start-index="73" stop-index="75" value="1.0" />
</parameter>
<parameter>
<literal-expression start-index="77" stop-index="80" value="2048" />
</parameter>
<parameter>
<literal-expression start-index="82" stop-index="82" value="1" />
</parameter>
</function>
</items>
<items>
<literal-expression start-index="85" stop-index="91" value="32767.1" />
</items>
</list-expression>
</right>
</in-expression>
</expr>
</expression-projection>
</projections>
</select>

<select sql-case-id="select_constant_without_table" >
<projections start-index="7" stop-index="12">
<expression-projection text="1" alias="a" start-index="7" stop-index="12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
-->

<sql-cases>
<sql-case id="select_with_exist_in" value="SELECT (+0 IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1))" db-types="MySQL" />
<sql-case id="select_constant_without_table" value="SELECT 1 as a" db-types="MySQL, PostgreSQL,openGauss, SQLServer" />
<sql-case id="select_with_operator_ilike" value="SELECT id from t_order where name !~ '^pg_toast'" db-types="PostgreSQL,openGauss" />
<sql-case id="select_with_binary_operation_of_aggregation_expr" value="SELECT (count(*)+1) as a" db-types="MySQL" />
Expand Down

0 comments on commit 71c24ee

Please sign in to comment.