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 3915058 replace expressionProjectionSegment with right segment.
(#13530)
3915058 is described below
commit 3915058d5dbeeb70d4d2bd940c68b47c72fa772c
Author: tuichenchuxin <[email protected]>
AuthorDate: Wed Nov 10 18:20:57 2021 +0800
replace expressionProjectionSegment with right segment. (#13530)
---
.../statement/impl/MySQLStatementSQLVisitor.java | 66 +++++-----
.../main/resources/case/dml/select-expression.xml | 6 +-
.../src/main/resources/case/dml/select.xml | 146 ++++++++-------------
3 files changed, 94 insertions(+), 124 deletions(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index 499d793..ec8b569 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -742,35 +742,43 @@ public abstract class MySQLStatementSQLVisitor extends
MySQLStatementBaseVisitor
@Override
public final ASTNode visitSpecialFunction(final SpecialFunctionContext
ctx) {
- FunctionSegment functionSegment;
if (null != ctx.groupConcatFunction()) {
- functionSegment = (FunctionSegment)
visit(ctx.groupConcatFunction());
- } else if (null != ctx.windowFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.windowFunction());
- } else if (null != ctx.castFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.castFunction());
- } else if (null != ctx.convertFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.convertFunction());
- } else if (null != ctx.positionFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.positionFunction());
- } else if (null != ctx.substringFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.substringFunction());
- } else if (null != ctx.extractFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.extractFunction());
- } else if (null != ctx.charFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.charFunction());
- } else if (null != ctx.trimFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.trimFunction());
- } else if (null != ctx.weightStringFunction()) {
- functionSegment = (FunctionSegment)
visit(ctx.weightStringFunction());
- } else if (null != ctx.valuesFunction()) {
- functionSegment = (FunctionSegment) visit(ctx.valuesFunction());
- } else if (null != ctx.currentUserFunction()) {
- functionSegment = (FunctionSegment)
visit(ctx.currentUserFunction());
- } else {
- functionSegment = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
getOriginalText(ctx), getOriginalText(ctx));
+ return visit(ctx.groupConcatFunction());
+ }
+ if (null != ctx.windowFunction()) {
+ return visit(ctx.windowFunction());
+ }
+ if (null != ctx.castFunction()) {
+ return visit(ctx.castFunction());
+ }
+ if (null != ctx.convertFunction()) {
+ return visit(ctx.convertFunction());
+ }
+ if (null != ctx.positionFunction()) {
+ return visit(ctx.positionFunction());
+ }
+ if (null != ctx.substringFunction()) {
+ return visit(ctx.substringFunction());
+ }
+ if (null != ctx.extractFunction()) {
+ return visit(ctx.extractFunction());
+ }
+ if (null != ctx.charFunction()) {
+ return visit(ctx.charFunction());
+ }
+ if (null != ctx.trimFunction()) {
+ return visit(ctx.trimFunction());
+ }
+ if (null != ctx.weightStringFunction()) {
+ return visit(ctx.weightStringFunction());
+ }
+ if (null != ctx.valuesFunction()) {
+ return visit(ctx.valuesFunction());
+ }
+ if (null != ctx.currentUserFunction()) {
+ return visit(ctx.currentUserFunction());
}
- return new ExpressionProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), getOriginalText(ctx), functionSegment);
+ return new FunctionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), getOriginalText(ctx), getOriginalText(ctx));
}
@Override
@@ -844,9 +852,7 @@ public abstract class MySQLStatementSQLVisitor extends
MySQLStatementBaseVisitor
@Override
public final ASTNode visitRegularFunction(final RegularFunctionContext
ctx) {
- FunctionSegment functionSegment = null !=
ctx.completeRegularFunction() ? (FunctionSegment)
visit(ctx.completeRegularFunction()) : (FunctionSegment)
visit(ctx.shorthandRegularFunction());
- // TODO Function call should return function segment.
- return new
ExpressionProjectionSegment(functionSegment.getStartIndex(),
functionSegment.getStopIndex(), functionSegment.getText(), functionSegment);
+ return null != ctx.completeRegularFunction() ?
visit(ctx.completeRegularFunction()) : visit(ctx.shorthandRegularFunction());
}
@Override
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-expression.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-expression.xml
index 44af5de..9f63536 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-expression.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-expression.xml
@@ -1328,11 +1328,7 @@
<expr>
<binary-operation-expression start-index="28" stop-index="43">
<left>
- <expression-projection text="now()" start-index="28"
stop-index="32">
- <expr>
- <function function-name="now" start-index="28"
stop-index="32" text="now()" />
- </expr>
- </expression-projection>
+ <function function-name="now" start-index="28"
stop-index="32" text="now()" />
</left>
<operator><</operator>
<right>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
index c3bb500..6f912d9 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
@@ -810,6 +810,18 @@
<right>
<list-expression start-index="67"
stop-index="87" literal-stop-index="92">
<items>
+ <function
function-name="CONCAT" literal-text="CONCAT('%%', 'init', '%%')"
start-index="67" stop-index="87" literal-stop-index="92" text="CONCAT('%%', ?,
'%%')">
+ <parameter>
+ <literal-expression
value="%%" start-index="74" stop-index="77" />
+ </parameter>
+ <parameter>
+ <literal-expression
value="init" start-index="80" stop-index="80" literal-start-index="80"
literal-stop-index="85" />
+
<parameter-marker-expression value="0" start-index="80" stop-index="80" />
+ </parameter>
+ <parameter>
+ <literal-expression
value="%%" start-index="83" stop-index="86" literal-start-index="88"
literal-stop-index="91" />
+ </parameter>
+ </function>
<expression-projection
text="CONCAT('%%', ?, '%%')" literal-text="CONCAT('%%', 'init', '%%')"
start-index="67" stop-index="87" literal-stop-index="92" />
</items>
</list-expression>
@@ -2674,18 +2686,14 @@
<expr>
<function function-name="CONCAT" start-index="7"
stop-index="37" text="CONCAT(LEFT(status, 7), 'test')">
<parameter>
- <expression-projection start-index="14"
stop-index="28" text="LEFT(status, 7)">
- <expr>
- <function function-name="LEFT"
start-index="14" stop-index="28" text="LEFT(status, 7)">
- <parameter>
- <column name="status"
start-index="19" stop-index="24" />
- </parameter>
- <parameter>
- <literal-expression value="7"
start-index="27" stop-index="27" />
- </parameter>
- </function>
- </expr>
- </expression-projection>
+ <function function-name="LEFT" start-index="14"
stop-index="28" text="LEFT(status, 7)">
+ <parameter>
+ <column name="status" start-index="19"
stop-index="24" />
+ </parameter>
+ <parameter>
+ <literal-expression value="7"
start-index="27" stop-index="27" />
+ </parameter>
+ </function>
</parameter>
<parameter>
<literal-expression value="test" start-index="31"
stop-index="36" />
@@ -2730,18 +2738,14 @@
<expr>
<binary-operation-expression start-index="28" stop-index="47">
<left>
- <expression-projection text="MOD(order_id, 1)"
start-index="28" stop-index="43">
- <expr>
- <function function-name="MOD" start-index="28"
stop-index="43" text="MOD(order_id, 1)">
- <parameter>
- <column name="order_id"
start-index="32" stop-index="39" />
- </parameter>
- <parameter>
- <literal-expression value="1"
start-index="42" stop-index="42" />
- </parameter>
- </function>
- </expr>
- </expression-projection>
+ <function function-name="MOD" start-index="28"
stop-index="43" text="MOD(order_id, 1)">
+ <parameter>
+ <column name="order_id" start-index="32"
stop-index="39" />
+ </parameter>
+ <parameter>
+ <literal-expression value="1" start-index="42"
stop-index="42" />
+ </parameter>
+ </function>
</left>
<operator>=</operator>
<right>
@@ -2763,22 +2767,14 @@
<expr>
<binary-operation-expression start-index="28" stop-index="79">
<left>
- <expression-projection text="DATE_FORMAT(current_date,
'%Y-%m-%d')" start-index="28" stop-index="64">
- <expr>
- <function function-name="DATE_FORMAT"
start-index="28" stop-index="64" text="DATE_FORMAT(current_date, '%Y-%m-%d')">
- <parameter>
- <expression-projection
text="current_date" start-index="40" stop-index="51">
- <expr>
- <function
function-name="current_date" start-index="40" stop-index="51"
text="current_date"/>
- </expr>
- </expression-projection>
- </parameter>
- <parameter>
- <literal-expression value="%Y-%m-%d"
start-index="54" stop-index="63" />
- </parameter>
- </function>
- </expr>
- </expression-projection>
+ <function function-name="DATE_FORMAT" start-index="28"
stop-index="64" text="DATE_FORMAT(current_date, '%Y-%m-%d')">
+ <parameter>
+ <function function-name="current_date"
start-index="40" stop-index="51" text="current_date"/>
+ </parameter>
+ <parameter>
+ <literal-expression value="%Y-%m-%d"
start-index="54" stop-index="63" />
+ </parameter>
+ </function>
</left>
<operator>=</operator>
<right>
@@ -2800,40 +2796,28 @@
<expr>
<binary-operation-expression start-index="28" stop-index="106">
<left>
- <expression-projection
text="ST_DISTANCE_SPHERE(POINT(113.358772, 23.1273723),
POINT(user_id,order_id))" start-index="28" stop-index="101">
- <expr>
- <function function-name="ST_DISTANCE_SPHERE"
start-index="28" stop-index="101" text="ST_DISTANCE_SPHERE(POINT(113.358772,
23.1273723), POINT(user_id,order_id))">
+ <function function-name="ST_DISTANCE_SPHERE"
start-index="28" stop-index="101" text="ST_DISTANCE_SPHERE(POINT(113.358772,
23.1273723), POINT(user_id,order_id))">
+ <parameter>
+ <function function-name="POINT"
start-index="47" stop-index="75" text="POINT(113.358772, 23.1273723)">
<parameter>
- <expression-projection
start-index="47" stop-index="75" text="POINT(113.358772, 23.1273723)">
- <expr>
- <function
function-name="POINT" start-index="47" stop-index="75" text="POINT(113.358772,
23.1273723)">
- <parameter>
- <literal-expression
value="113.358772" start-index="53" stop-index="62" />
- </parameter>
- <parameter>
- <literal-expression
value="23.1273723" start-index="65" stop-index="74" />
- </parameter>
- </function>
- </expr>
- </expression-projection>
+ <literal-expression value="113.358772"
start-index="53" stop-index="62" />
</parameter>
<parameter>
- <expression-projection
start-index="78" stop-index="100" text="POINT(user_id,order_id)">
- <expr>
- <function
function-name="POINT" start-index="78" stop-index="100"
text="POINT(user_id,order_id)">
- <parameter>
- <column name="user_id"
start-index="84" stop-index="90" />
- </parameter>
- <parameter>
- <column
name="order_id" start-index="92" stop-index="99" />
- </parameter>
- </function>
- </expr>
- </expression-projection>
+ <literal-expression value="23.1273723"
start-index="65" stop-index="74" />
+ </parameter>
+ </function>
+ </parameter>
+ <parameter>
+ <function function-name="POINT"
start-index="78" stop-index="100" text="POINT(user_id,order_id)">
+ <parameter>
+ <column name="user_id"
start-index="84" stop-index="90" />
+ </parameter>
+ <parameter>
+ <column name="order_id"
start-index="92" stop-index="99" />
</parameter>
</function>
- </expr>
- </expression-projection>
+ </parameter>
+ </function>
</left>
<operator>!=</operator>
<right>
@@ -3378,11 +3362,7 @@
<column name="date" start-index="28" stop-index="31"/>
</left>
<right>
- <expression-projection text="CURRENT_DATE"
start-index="35" stop-index="46">
- <expr>
- <function function-name="CURRENT_DATE"
start-index="35" stop-index="46" text="CURRENT_DATE" />
- </expr>
- </expression-projection>
+ <function function-name="CURRENT_DATE"
start-index="35" stop-index="46" text="CURRENT_DATE" />
</right>
<operator>=</operator>
</binary-operation-expression>
@@ -3404,11 +3384,7 @@
<column name="date" start-index="28" stop-index="31"/>
</left>
<right>
- <expression-projection text="CURRENT_DATE()"
start-index="35" stop-index="48">
- <expr>
- <function function-name="CURRENT_DATE"
start-index="35" stop-index="48" text="CURRENT_DATE()" />
- </expr>
- </expression-projection>
+ <function function-name="CURRENT_DATE"
start-index="35" stop-index="48" text="CURRENT_DATE()" />
</right>
<operator>=</operator>
</binary-operation-expression>
@@ -3430,11 +3406,7 @@
<column name="time" start-index="28" stop-index="31"/>
</left>
<right>
- <expression-projection text="CURRENT_TIME"
start-index="35" stop-index="46">
- <expr>
- <function function-name="CURRENT_TIME"
start-index="35" stop-index="46" text="CURRENT_TIME" />
- </expr>
- </expression-projection>
+ <function function-name="CURRENT_TIME"
start-index="35" stop-index="46" text="CURRENT_TIME" />
</right>
<operator>=</operator>
</binary-operation-expression>
@@ -3456,11 +3428,7 @@
<column name="time" start-index="28" stop-index="31"/>
</left>
<right>
- <expression-projection text="CURRENT_TIME()"
start-index="35" stop-index="48">
- <expr>
- <function function-name="CURRENT_TIME"
start-index="35" stop-index="48" text="CURRENT_TIME()" />
- </expr>
- </expression-projection>
+ <function function-name="CURRENT_TIME"
start-index="35" stop-index="48" text="CURRENT_TIME()" />
</right>
<operator>=</operator>
</binary-operation-expression>