This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 918ef25b405 Register Firebird parameters of STARTING WITH, IS DISTINCT
FROM and SIMILAR TO predicates (#40176)
918ef25b405 is described below
commit 918ef25b405063a83c258d783b5996941410b342
Author: Maxim Igoshin <[email protected]>
AuthorDate: Fri Oct 16 10:42:57 2026 +0300
Register Firebird parameters of STARTING WITH, IS DISTINCT FROM and SIMILAR
TO predicates (#40176)
---
.../statement/FirebirdStatementVisitor.java | 27 +++++
.../parser/src/main/resources/case/dml/select.xml | 117 +++++++++++++++++++++
.../main/resources/sql/supported/dml/select.xml | 4 +
3 files changed, 148 insertions(+)
diff --git
a/parser/sql/engine/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/engine/firebird/visitor/statement/FirebirdStatementVisitor.java
b/parser/sql/engine/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/engine/firebird/visitor/statement/FirebirdStatementVisitor.java
index 2a8e16dd30a..d03f6c83248 100644
---
a/parser/sql/engine/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/engine/firebird/visitor/statement/FirebirdStatementVisitor.java
+++
b/parser/sql/engine/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/engine/firebird/visitor/statement/FirebirdStatementVisitor.java
@@ -328,6 +328,9 @@ public abstract class FirebirdStatementVisitor extends
FirebirdStatementBaseVisi
if (null != ctx.LIKE()) {
return createBinaryOperationExpressionFromLike(ctx);
}
+ if (null != ctx.STARTING() || null != ctx.DISTINCT() || null !=
ctx.SIMILAR()) {
+ return createBinaryOperationExpressionFromPredicate(ctx);
+ }
return visit(ctx.bitExpr(0));
}
@@ -367,6 +370,30 @@ public abstract class FirebirdStatementVisitor extends
FirebirdStatementBaseVisi
return new BetweenExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, between, and, not);
}
+ private BinaryOperationExpression
createBinaryOperationExpressionFromPredicate(final PredicateContext ctx) {
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0));
+ ExpressionSegment right = null == ctx.ESCAPE() ? (ExpressionSegment)
visit(ctx.bitExpr(1)) : createEscapedPattern(ctx);
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, getPredicateOperator(ctx), text);
+ }
+
+ private ListExpression createEscapedPattern(final PredicateContext ctx) {
+ ListExpression result = new
ListExpression(ctx.bitExpr(1).start.getStartIndex(),
ctx.bitExpr(2).stop.getStopIndex());
+ result.getItems().add((ExpressionSegment) visit(ctx.bitExpr(1)));
+ result.getItems().add((ExpressionSegment) visit(ctx.bitExpr(2)));
+ return result;
+ }
+
+ private String getPredicateOperator(final PredicateContext ctx) {
+ if (null != ctx.STARTING()) {
+ return null == ctx.NOT() ? "STARTING WITH" : "NOT STARTING WITH";
+ }
+ if (null != ctx.DISTINCT()) {
+ return null == ctx.NOT() ? "IS DISTINCT FROM" : "IS NOT DISTINCT
FROM";
+ }
+ return null == ctx.NOT() ? "SIMILAR TO" : "NOT SIMILAR TO";
+ }
+
@Override
public final ASTNode visitBitExpr(final BitExprContext ctx) {
if (null != ctx.simpleExpr()) {
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml
b/test/it/parser/src/main/resources/case/dml/select.xml
index dfdd8a9253d..6ad1d998049 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -15508,4 +15508,121 @@
</column-projection>
</projections>
</select>
+
+ <select sql-case-id="select_where_is_not_distinct_from_firebird"
parameters="'init'">
+ <from>
+ <simple-table name="t_order" start-index="21" stop-index="27" />
+ </from>
+ <projections start-index="7" stop-index="14">
+ <column-projection name="order_id" start-index="7" stop-index="14"
/>
+ </projections>
+ <where start-index="29" stop-index="63" literal-stop-index="68">
+ <expr>
+ <binary-operation-expression start-index="35" stop-index="63"
literal-stop-index="68">
+ <left>
+ <column name="status" start-index="35" stop-index="40"
/>
+ </left>
+ <operator>IS NOT DISTINCT FROM</operator>
+ <right>
+ <parameter-marker-expression parameter-index="0"
start-index="63" stop-index="63" />
+ <literal-expression value="init" start-index="63"
stop-index="68" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_where_starting_with_firebird"
parameters="'in'">
+ <from>
+ <simple-table name="t_order" start-index="21" stop-index="27" />
+ </from>
+ <projections start-index="7" stop-index="14">
+ <column-projection name="order_id" start-index="7" stop-index="14"
/>
+ </projections>
+ <where start-index="29" stop-index="56" literal-stop-index="59">
+ <expr>
+ <binary-operation-expression start-index="35" stop-index="56"
literal-stop-index="59">
+ <left>
+ <column name="status" start-index="35" stop-index="40"
/>
+ </left>
+ <operator>STARTING WITH</operator>
+ <right>
+ <parameter-marker-expression parameter-index="0"
start-index="56" stop-index="56" />
+ <literal-expression value="in" start-index="56"
stop-index="59" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_where_similar_to_escape_firebird"
parameters="'in#%', '#'">
+ <from>
+ <simple-table name="t_order" start-index="21" stop-index="27" />
+ </from>
+ <projections start-index="7" stop-index="14">
+ <column-projection name="order_id" start-index="7" stop-index="14"
/>
+ </projections>
+ <where start-index="29" stop-index="62" literal-stop-index="69">
+ <expr>
+ <binary-operation-expression start-index="35" stop-index="62"
literal-stop-index="69">
+ <left>
+ <column name="status" start-index="35" stop-index="40"
/>
+ </left>
+ <operator>SIMILAR TO</operator>
+ <right>
+ <list-expression start-index="53" stop-index="62"
literal-start-index="53" literal-stop-index="69">
+ <items>
+ <parameter-marker-expression
parameter-index="0" start-index="53" stop-index="53" />
+ <literal-expression value="in#%"
start-index="53" stop-index="58" />
+ </items>
+ <items>
+ <parameter-marker-expression
parameter-index="1" start-index="62" stop-index="62" />
+ <literal-expression value="#" start-index="67"
stop-index="69" />
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_where_is_distinct_from_and_equal_firebird"
parameters="'init', 1">
+ <from>
+ <simple-table name="t_order" start-index="21" stop-index="27" />
+ </from>
+ <projections start-index="7" stop-index="14">
+ <column-projection name="order_id" start-index="7" stop-index="14"
/>
+ </projections>
+ <where start-index="29" stop-index="76" literal-stop-index="81">
+ <expr>
+ <binary-operation-expression start-index="35" stop-index="76"
literal-stop-index="81">
+ <left>
+ <binary-operation-expression start-index="35"
stop-index="59" literal-stop-index="64">
+ <left>
+ <column name="status" start-index="35"
stop-index="40" />
+ </left>
+ <operator>IS DISTINCT FROM</operator>
+ <right>
+ <parameter-marker-expression
parameter-index="0" start-index="59" stop-index="59" />
+ <literal-expression value="init"
start-index="59" stop-index="64" />
+ </right>
+ </binary-operation-expression>
+ </left>
+ <operator>AND</operator>
+ <right>
+ <binary-operation-expression start-index="65"
stop-index="76" literal-start-index="70" literal-stop-index="81">
+ <left>
+ <column name="order_id" start-index="65"
stop-index="72" literal-start-index="70" literal-stop-index="77" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <parameter-marker-expression
parameter-index="1" start-index="76" stop-index="76" />
+ <literal-expression value="1" start-index="81"
stop-index="81" />
+ </right>
+ </binary-operation-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
index 49fc00dbd87..7b3545c8011 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
@@ -587,4 +587,8 @@
<sql-case id="select_in_with_owner_column_rhs_oracle" value="SELECT * FROM
t_order o WHERE o.user_id IN o.order_id" db-types="Oracle" />
<sql-case id="select_in_with_function_rhs_oracle" value="SELECT * FROM
t_order o WHERE o.user_id IN NVL(o.order_id, 0)" db-types="Oracle" />
<sql-case id="select_parenthesized_column_alias" value="SELECT
(c.password) PASSWORD FROM t_account c"
db-types="Oracle,PostgreSQL,openGauss,SQLServer,Hive" />
+ <sql-case id="select_where_is_not_distinct_from_firebird" value="SELECT
order_id FROM t_order WHERE status IS NOT DISTINCT FROM ?" db-types="Firebird"
/>
+ <sql-case id="select_where_starting_with_firebird" value="SELECT order_id
FROM t_order WHERE status STARTING WITH ?" db-types="Firebird" />
+ <sql-case id="select_where_similar_to_escape_firebird" value="SELECT
order_id FROM t_order WHERE status SIMILAR TO ? ESCAPE ?" db-types="Firebird" />
+ <sql-case id="select_where_is_distinct_from_and_equal_firebird"
value="SELECT order_id FROM t_order WHERE status IS DISTINCT FROM ? AND
order_id = ?" db-types="Firebird" />
</sql-cases>