diff --git a/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml b/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml index 23d87693f8360b7a01dfa84157437239952cc51b..962de5d9e1310be5eb2fa03278d7302ac67f083e 100644 --- a/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml +++ b/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml @@ -17,10 +17,7 @@ --> - - - - + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java index 06db32230ed260f6c132dfc9d30675d424d22912..718792b9eb92c795b206a1c6bae05f9c1de0bd8d 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/impl/MySQLDMLVisitor.java @@ -72,6 +72,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.OnDuplicateKe import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -444,8 +445,8 @@ public final class MySQLDMLVisitor extends MySQLVisitor implements DMLVisitor { result.setAlias(alias); return result; } - if (projection instanceof SubquerySegment) { - SubqueryProjectionSegment result = new SubqueryProjectionSegment((SubquerySegment) projection); + if (projection instanceof SubqueryExpressionSegment) { + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery()); result.setAlias(alias); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/impl/OracleDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/impl/OracleDMLVisitor.java index 295e8e965971bf33df4c15fdd27f679fb3f93505..827bb2edb80f29789c83b69bb4c1ec390da9b087 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/impl/OracleDMLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/impl/OracleDMLVisitor.java @@ -59,6 +59,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.InsertColumns import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -352,8 +353,8 @@ public final class OracleDMLVisitor extends OracleVisitor implements DMLVisitor result.setAlias(alias); return result; } - if (projection instanceof SubquerySegment) { - SubqueryProjectionSegment result = new SubqueryProjectionSegment((SubquerySegment) projection); + if (projection instanceof SubqueryExpressionSegment) { + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery()); result.setAlias(alias); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/impl/PostgreSQLDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/impl/PostgreSQLDMLVisitor.java index a70d47c56e8c93dbc29601e2f4cb22a654c99489..ed2a737613fccf5b29324a3941fa92678a7e26d0 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/impl/PostgreSQLDMLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/impl/PostgreSQLDMLVisitor.java @@ -62,6 +62,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.InsertColumns import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -361,8 +362,8 @@ public final class PostgreSQLDMLVisitor extends PostgreSQLVisitor implements DML result.setAlias(alias); return result; } - if (projection instanceof SubquerySegment) { - SubqueryProjectionSegment result = new SubqueryProjectionSegment((SubquerySegment) projection); + if (projection instanceof SubqueryExpressionSegment) { + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery()); result.setAlias(alias); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/impl/SQL92DMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/impl/SQL92DMLVisitor.java index d69a1ff278d5218e49f396df2bc328c3a6f59692..c21bf05436a5a27c48169a32816c3c36d9d77072 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/impl/SQL92DMLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/impl/SQL92DMLVisitor.java @@ -57,6 +57,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.InsertColumns import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -324,8 +325,8 @@ public final class SQL92DMLVisitor extends SQL92Visitor implements DMLVisitor { result.setAlias(alias); return result; } - if (projection instanceof SubquerySegment) { - SubqueryProjectionSegment result = new SubqueryProjectionSegment((SubquerySegment) projection); + if (projection instanceof SubqueryExpressionSegment) { + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery()); result.setAlias(alias); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java index 4d029394bbb51a36b7051f5107440453b1e18c27..d57b3aa5b7f76959ab0c761880f9ab94317a4b75 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java @@ -58,6 +58,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.column.InsertColumns import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.LiteralExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -347,8 +348,8 @@ public final class SQLServerDMLVisitor extends SQLServerVisitor implements DMLVi result.setAlias(alias); return result; } - if (projection instanceof SubquerySegment) { - SubqueryProjectionSegment result = new SubqueryProjectionSegment((SubquerySegment) projection); + if (projection instanceof SubqueryExpressionSegment) { + SubqueryProjectionSegment result = new SubqueryProjectionSegment(((SubqueryExpressionSegment) projection).getSubquery()); result.setAlias(alias); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/ExpectedProjections.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/ExpectedProjections.java index 2fd941e1ae95cd6de308d5328a141ff492c420ae..38a6f973d9705778ed6fcdcf7cbb228adfd379c0 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/ExpectedProjections.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/ExpectedProjections.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.p import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.impl.column.ExpectedColumnProjection; import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.impl.expression.ExpectedExpressionProjection; import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.impl.shorthand.ExpectedShorthandProjection; +import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.impl.subquery.ExpectedSubqueryProjection; import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.impl.top.ExpectedTopProjection; import javax.xml.bind.annotation.XmlAttribute; @@ -60,13 +61,17 @@ public final class ExpectedProjections extends AbstractExpectedSQLSegment { @XmlElement(name = "top-projection") private final Collection topProjections = new LinkedList<>(); + @XmlElement(name = "subquery-projection") + private final Collection subqueryProjections = new LinkedList<>(); + /** * Get size. * * @return size */ public int getSize() { - return shorthandProjections.size() + columnProjections.size() + aggregationProjections.size() + aggregationDistinctProjections.size() + expressionProjections.size() + topProjections.size(); + return shorthandProjections.size() + columnProjections.size() + aggregationProjections.size() + aggregationDistinctProjections.size() + + expressionProjections.size() + topProjections.size() + subqueryProjections.size(); } /** @@ -82,6 +87,7 @@ public final class ExpectedProjections extends AbstractExpectedSQLSegment { result.addAll(aggregationDistinctProjections); result.addAll(expressionProjections); result.addAll(topProjections); + result.addAll(subqueryProjections); result.sort(Comparator.comparingInt(ExpectedSQLSegment::getStartIndex)); return result; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/impl/subquery/ExpectedSubqueryProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/impl/subquery/ExpectedSubqueryProjection.java new file mode 100644 index 0000000000000000000000000000000000000000..bb720b3496a8f6038110a187b11af546b93d4513 --- /dev/null +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/domain/segment/impl/projection/impl/subquery/ExpectedSubqueryProjection.java @@ -0,0 +1,41 @@ +/* + * 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.integrate.jaxb.domain.segment.impl.projection.impl.subquery; + +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.AbstractExpectedDelimiterSQLSegment; +import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.expr.simple.ExpectedSubquery; +import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.projection.ExpectedProjection; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; + +/** + * Expected subquery projection. + */ +@Getter +@Setter +public final class ExpectedSubqueryProjection extends AbstractExpectedDelimiterSQLSegment implements ExpectedProjection { + + @XmlAttribute + private String alias; + + @XmlElement + private ExpectedSubquery subquery; +} diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-sub-query.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-sub-query.xml index 8fa9956919b545f38bf839f0e435fae4f7394651..c1878598599f257f58484d4b887876a445e2714f 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-sub-query.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select-sub-query.xml @@ -17,35 +17,23 @@ --> - - -