You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/04/07 00:31:24 UTC
[shardingsphere] branch master updated: support for SELECT special functions (#24888)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 e3527b31a9a support for SELECT special functions (#24888)
e3527b31a9a is described below
commit e3527b31a9a43ae1e031e70926b00f89e3e9e253
Author: kanha gupta <92...@users.noreply.github.com>
AuthorDate: Fri Apr 7 06:01:06 2023 +0530
support for SELECT special functions (#24888)
* support for Char function
* support for Weight string SQL
* Support for Char & weight string Function
---
.../statement/impl/MySQLStatementSQLVisitor.java | 11 ++++++++--
.../test/it/optimize/SQLNodeConverterEngineIT.java | 2 ++
.../resources/case/dml/select-special-function.xml | 24 ++++++++++++++++++++--
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index 3703568a693..656ed7f831f 100644
--- a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -954,7 +954,12 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
@Override
public final ASTNode visitCharFunction(final CharFunctionContext ctx) {
calculateParameterCount(ctx.expr());
- return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
+ FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
+ for (ExprContext each : ctx.expr()) {
+ ASTNode expr = visit(each);
+ result.getParameters().add((ExpressionSegment) expr);
+ }
+ return result;
}
@Override
@@ -966,7 +971,9 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
@Override
public final ASTNode visitWeightStringFunction(final WeightStringFunctionContext ctx) {
calculateParameterCount(Collections.singleton(ctx.expr()));
- return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.WEIGHT_STRING().getText(), getOriginalText(ctx));
+ FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.WEIGHT_STRING().getText(), getOriginalText(ctx));
+ result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
+ return result;
}
@Override
diff --git a/test/it/optimizer/src/test/java/org/apache/shardingsphere/test/it/optimize/SQLNodeConverterEngineIT.java b/test/it/optimizer/src/test/java/org/apache/shardingsphere/test/it/optimize/SQLNodeConverterEngineIT.java
index 954d930de75..e3ec5422aa5 100644
--- a/test/it/optimizer/src/test/java/org/apache/shardingsphere/test/it/optimize/SQLNodeConverterEngineIT.java
+++ b/test/it/optimizer/src/test/java/org/apache/shardingsphere/test/it/optimize/SQLNodeConverterEngineIT.java
@@ -191,6 +191,8 @@ class SQLNodeConverterEngineIT {
result.add("select_natural_full_join");
result.add("select_order_by_for_nulls_first");
result.add("select_order_by_for_nulls_last");
+ result.add("select_char");
+ result.add("select_weight_string");
return result;
}
// CHECKSTYLE:ON
diff --git a/test/it/parser/src/main/resources/case/dml/select-special-function.xml b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index 994ec106c10..172d31f4e62 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -128,7 +128,23 @@
<projections start-index="7" stop-index="29">
<expression-projection text="CHAR(77,121,83,81,'76')" start-index="7" stop-index="29">
<expr>
- <function function-name="CHAR" start-index="7" stop-index="29" text="CHAR(77,121,83,81,'76')" />
+ <function function-name="CHAR" start-index="7" stop-index="29" text="CHAR(77,121,83,81,'76')" >
+ <parameter>
+ <literal-expression value="77" start-index="12" stop-index="13" />
+ </parameter>
+ <parameter>
+ <literal-expression value="121" start-index="15" stop-index="17" />
+ </parameter>
+ <parameter>
+ <literal-expression value="83" start-index="19" stop-index="20" />
+ </parameter>
+ <parameter>
+ <literal-expression value="81" start-index="22" stop-index="23" />
+ </parameter>
+ <parameter>
+ <literal-expression value="76" start-index="25" stop-index="28" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>
@@ -170,7 +186,11 @@
<projections start-index="7" stop-index="26">
<expression-projection text="WEIGHT_STRING('bar')" start-index="7" stop-index="26">
<expr>
- <function function-name="WEIGHT_STRING" start-index="7" stop-index="26" text="WEIGHT_STRING('bar')" />
+ <function function-name="WEIGHT_STRING" start-index="7" stop-index="26" text="WEIGHT_STRING('bar')" >
+ <parameter>
+ <literal-expression value="bar" start-index="21" stop-index="25" />
+ </parameter>
+ </function>
</expr>
</expression-projection>
</projections>