This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 e25ec1ae531 Remove useless ExplicitTableExpression and parse table
statement to shorthand query (#27245)
e25ec1ae531 is described below
commit e25ec1ae531cd56919774fb7e6b364ee98fc855d
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Jul 17 11:42:51 2023 +0800
Remove useless ExplicitTableExpression and parse table statement to
shorthand query (#27245)
---
.../dialect/mysql/MySQLMatchAgainstFunction.java | 8 ++-
.../visitor/statement/MySQLStatementVisitor.java | 10 +---
.../segment/dml/expr/ExplicitTableExpression.java | 41 --------------
.../src/test/resources/converter/select-table.xml | 3 +-
.../segment/expression/ExpressionAssert.java | 21 +------
.../impl/expr/ExpectedExplicitTableExpression.java | 30 ----------
.../jaxb/segment/impl/expr/ExpectedExpression.java | 3 -
.../parser/src/main/resources/case/dal/explain.xml | 11 ++--
.../parser/src/main/resources/case/dml/table.xml | 66 ++++++++++------------
9 files changed, 47 insertions(+), 146 deletions(-)
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/function/dialect/mysql/MySQLMatchAgainstFunction.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/function/dialect/mysql/MySQLMatchAgainstFunction.java
index 0ce4320e5d5..797b12367ef 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/function/dialect/mysql/MySQLMatchAgainstFunction.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/function/dialect/mysql/MySQLMatchAgainstFunction.java
@@ -26,6 +26,7 @@ import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperandCountRange;
import org.apache.calcite.sql.SqlSyntax;
import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.SqlWriter.Frame;
import org.apache.calcite.sql.SqlWriter.FrameType;
import org.apache.calcite.sql.SqlWriter.FrameTypeEnum;
import org.apache.calcite.sql.type.InferTypes;
@@ -49,6 +50,12 @@ public final class MySQLMatchAgainstFunction extends
SqlFunction {
@Override
public void unparse(final SqlWriter writer, final SqlCall call, final int
leftPrecedence, final int rightPrecedence) {
+ Frame frame = writer.startList(FRAME_TYPE, "MATCH", "");
+ writeParameters(writer, call);
+ writer.endList(frame);
+ }
+
+ private void writeParameters(final SqlWriter writer, final SqlCall call) {
writer.sep("(");
List<SqlNode> operandList = call.getOperandList();
int size = operandList.size();
@@ -65,7 +72,6 @@ public final class MySQLMatchAgainstFunction extends
SqlFunction {
String searchModifier = ((SqlLiteral)
Util.last(operandList)).toValue();
writer.sep(searchModifier);
writer.sep(")");
- writer.endList(writer.startList(FRAME_TYPE, "MATCH", ""));
}
@Override
diff --git
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
index 9d2804b72e2..3392f8a3cdb 100644
---
a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
+++
b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java
@@ -170,7 +170,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOp
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CaseWhenExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CollateExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExistsSubqueryExpression;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExplicitTableExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
@@ -812,12 +811,9 @@ public abstract class MySQLStatementVisitor extends
MySQLStatementBaseVisitor<AS
@Override
public ASTNode visitTableStatement(final TableStatementContext ctx) {
MySQLSelectStatement result = new MySQLSelectStatement();
- int startIndex = ctx.getStart().getStartIndex();
- int stopIndex = ctx.getStop().getStopIndex();
- TableNameSegment tableNameSegment = new
TableNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), new
IdentifierValue(ctx.tableName().getText()));
- ExplicitTableExpression explicitTableExpression = new
ExplicitTableExpression(startIndex, stopIndex, tableNameSegment);
- result.setProjections(new ProjectionsSegment(startIndex, stopIndex));
- result.getProjections().getProjections().add(new
ExpressionProjectionSegment(startIndex, stopIndex, getOriginalText(ctx),
explicitTableExpression));
+ result.setProjections(new
ProjectionsSegment(ctx.start.getStartIndex(), ctx.start.getStartIndex()));
+ result.getProjections().getProjections().add(new
ShorthandProjectionSegment(ctx.start.getStartIndex(),
ctx.start.getStartIndex()));
+ result.setFrom(new SimpleTableSegment(new
TableNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), new
IdentifierValue(ctx.tableName().getText()))));
return result;
}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/expr/ExplicitTableExpression.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/expr/ExplicitTableExpression.java
deleted file mode 100644
index 20803e1096e..00000000000
---
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/expr/ExplicitTableExpression.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-
-/**
- * Explicit table expression.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ExplicitTableExpression implements ExpressionSegment {
-
- private final int startIndex;
-
- private final int stopIndex;
-
- private final TableNameSegment tableNameSegment;
-
- @Override
- public String getText() {
- return tableNameSegment.getIdentifier().getValue();
- }
-}
diff --git a/test/it/optimizer/src/test/resources/converter/select-table.xml
b/test/it/optimizer/src/test/resources/converter/select-table.xml
index 02744a265ae..5c0dc9575a5 100644
--- a/test/it/optimizer/src/test/resources/converter/select-table.xml
+++ b/test/it/optimizer/src/test/resources/converter/select-table.xml
@@ -17,6 +17,5 @@
-->
<sql-node-converter-test-cases>
- <!-- TODO fix UnsupportedSQLOperationException when execute this case -->
- <!--<test-cases sql-case-id="select_from_with_table" expected-sql="SELECT
* FROM (TABLE `t0`) AS `dt`" db-types="MySQL" />-->
+ <test-cases sql-case-id="select_from_with_table" expected-sql="SELECT *
FROM (SELECT * FROM `t0`) AS `dt`" db-types="MySQL" />
</sql-node-converter-test-cases>
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/expression/ExpressionAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/expression/ExpressionAssert.java
index 0816686b199..a02679904d2 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/expression/ExpressionAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/expression/ExpressionAssert.java
@@ -26,7 +26,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOp
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CaseWhenExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CollateExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExistsSubqueryExpression;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExplicitTableExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExtractArgExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
@@ -49,7 +48,6 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAsse
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.SQLSegmentAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.column.ColumnAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.generic.DataTypeAssert;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.identifier.IdentifierValueAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert.InsertValuesClauseAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.owner.OwnerAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.projection.ProjectionAssert;
@@ -59,11 +57,11 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedCaseWhenExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedCollateExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedExistsSubquery;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedExplicitTableExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedExtractArgExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedInExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedListExpression;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedMatchExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedNotExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedTypeCastExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedValuesExpression;
@@ -73,7 +71,6 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.simple.ExpectedParameterMarkerExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.simple.ExpectedSubquery;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.function.ExpectedFunction;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedMatchExpression;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.sql.type.SQLCaseType;
import java.util.Iterator;
@@ -398,20 +395,6 @@ public final class ExpressionAssert {
}
}
- private static void assertExplicitExpression(final SQLCaseAssertContext
assertContext, final ExplicitTableExpression actual, final
ExpectedExplicitTableExpression expected) {
- if (null == expected) {
- assertNull(actual, assertContext.getText("Table segment should not
exist."));
- return;
- }
- assertNotNull(actual, assertContext.getText("Table segment should
exist."));
- if (null == expected.getName()) {
- assertNull(actual.getTableNameSegment(),
assertContext.getText("Table segment should not exist."));
- } else {
- assertNotNull(actual.getTableNameSegment(),
assertContext.getText("Table segment should exist."));
- IdentifierValueAssert.assertIs(assertContext,
actual.getTableNameSegment().getIdentifier(), expected, "table");
- }
- }
-
/**
* Assert extract arg expression.
*
@@ -491,8 +474,6 @@ public final class ExpressionAssert {
assertVariableSegment(assertContext, (VariableSegment) actual,
expected.getVariableSegment());
} else if (actual instanceof ValuesExpression) {
assertValuesExpression(assertContext, (ValuesExpression) actual,
expected.getValuesExpression());
- } else if (actual instanceof ExplicitTableExpression) {
- assertExplicitExpression(assertContext, (ExplicitTableExpression)
actual, expected.getExplicitTableExpression());
} else if (actual instanceof ExtractArgExpression) {
assertExtractArgExpression(assertContext, (ExtractArgExpression)
actual, expected.getExtractArgExpression());
} else if (actual instanceof MatchAgainstExpression) {
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExplicitTableExpression.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExplicitTableExpression.java
deleted file mode 100644
index 7de8cb83675..00000000000
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExplicitTableExpression.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr;
-
-import lombok.Getter;
-import lombok.Setter;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedIdentifierSQLSegment;
-
-/**
- * Expected explicit table expression.
- */
-@Getter
-@Setter
-public final class ExpectedExplicitTableExpression extends
AbstractExpectedIdentifierSQLSegment {
-}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExpression.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExpression.java
index a3e63cf95e0..3adb9a54042 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExpression.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/expr/ExpectedExpression.java
@@ -99,9 +99,6 @@ public final class ExpectedExpression extends
AbstractExpectedSQLSegment {
@XmlElement(name = "values-expression")
private ExpectedValuesExpression valuesExpression;
- @XmlElement(name = "explicit-table")
- private ExpectedExplicitTableExpression explicitTableExpression;
-
@XmlElement(name = "extract-arg")
private ExpectedExtractArgExpression extractArgExpression;
diff --git a/test/it/parser/src/main/resources/case/dal/explain.xml
b/test/it/parser/src/main/resources/case/dal/explain.xml
index 36ff838ed9d..7a552bdbec2 100644
--- a/test/it/parser/src/main/resources/case/dal/explain.xml
+++ b/test/it/parser/src/main/resources/case/dal/explain.xml
@@ -343,13 +343,12 @@
<offset value="2" literal-start-index="55"
literal-stop-index="55" />
<row-count value="1" start-index="46" stop-index="46" />
</limit>
- <projections start-index="8" stop-index="20">
- <expression-projection text="TABLE t_order" start-index="8"
stop-index="20">
- <expr>
- <explicit-table start-index="8" stop-index="20"
name="t_order" />
- </expr>
- </expression-projection>
+ <projections start-index="8" stop-index="8">
+ <shorthand-projection start-index="8" stop-index="8" />
</projections>
+ <from>
+ <simple-table name="t_order" start-index="8" stop-index="20" />
+ </from>
</select>
</describe>
diff --git a/test/it/parser/src/main/resources/case/dml/table.xml
b/test/it/parser/src/main/resources/case/dml/table.xml
index 300d37039dd..2f4dfad8767 100644
--- a/test/it/parser/src/main/resources/case/dml/table.xml
+++ b/test/it/parser/src/main/resources/case/dml/table.xml
@@ -18,23 +18,21 @@
<sql-parser-test-cases>
<select sql-case-id="explicit_table">
- <projections start-index="0" stop-index="6">
- <expression-projection text="table f" start-index="0"
stop-index="6">
- <expr>
- <explicit-table start-index="0" stop-index="6" name="f" />
- </expr>
- </expression-projection>
+ <projections start-index="0" stop-index="0">
+ <shorthand-projection start-index="0" stop-index="0" />
</projections>
+ <from>
+ <simple-table name="f" start-index="0" stop-index="6" />
+ </from>
</select>
<select sql-case-id="table_with_order_by_limit_offset">
- <projections start-index="0" stop-index="12">
- <expression-projection text="TABLE t_order" start-index="0"
stop-index="12">
- <expr>
- <explicit-table start-index="0" stop-index="12"
name="t_order" />
- </expr>
- </expression-projection>
+ <projections start-index="0" stop-index="0">
+ <shorthand-projection start-index="0" stop-index="0" />
</projections>
+ <from>
+ <simple-table name="t_order" start-index="0" stop-index="12" />
+ </from>
<order-by>
<column-item name="order_id" start-index="23" stop-index="30" />
</order-by>
@@ -45,31 +43,28 @@
</select>
<select sql-case-id="table_union">
- <projections start-index="0" stop-index="7">
- <expression-projection text="TABLE T1" start-index="0"
stop-index="7">
- <expr>
- <explicit-table start-index="0" stop-index="7" name="T1" />
- </expr>
- </expression-projection>
+ <projections start-index="0" stop-index="0">
+ <shorthand-projection start-index="0" stop-index="0" />
</projections>
+ <from>
+ <simple-table name="T1" start-index="0" stop-index="7" />
+ </from>
<combine combine-type="UNION" start-index="9" stop-index="22">
<left>
- <projections start-index="0" stop-index="7">
- <expression-projection text="TABLE T1" start-index="0"
stop-index="7">
- <expr>
- <explicit-table start-index="0" stop-index="7"
name="T1" />
- </expr>
- </expression-projection>
+ <projections start-index="0" stop-index="0">
+ <shorthand-projection start-index="0" stop-index="0" />
</projections>
+ <from>
+ <simple-table name="T1" start-index="0" stop-index="7" />
+ </from>
</left>
<right>
- <projections start-index="15" stop-index="22">
- <expression-projection text="TABLE T2" start-index="15"
stop-index="22">
- <expr>
- <explicit-table start-index="15" stop-index="22"
name="T2" />
- </expr>
- </expression-projection>
+ <projections start-index="15" stop-index="15">
+ <shorthand-projection start-index="15" stop-index="15" />
</projections>
+ <from>
+ <simple-table name="T2" start-index="15" stop-index="22" />
+ </from>
</right>
</combine>
</select>
@@ -82,13 +77,12 @@
<subquery-table alias="dt">
<subquery>
<select>
- <projections start-index="15" stop-index="22">
- <expression-projection text="TABLE t0"
start-index="15" stop-index="22">
- <expr>
- <explicit-table start-index="15"
stop-index="22" name="t0" />
- </expr>
- </expression-projection>
+ <projections start-index="15" stop-index="15">
+ <shorthand-projection start-index="15"
stop-index="15" />
</projections>
+ <from>
+ <simple-table name="t0" start-index="15"
stop-index="22" />
+ </from>
</select>
</subquery>
</subquery-table>