diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/extractor/impl/dml/select/item/impl/TopProjectionExtractor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/extractor/impl/dml/select/item/impl/TopProjectionExtractor.java index bc12f090b27633..9cbe793cd6916c 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/extractor/impl/dml/select/item/impl/TopProjectionExtractor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/extractor/impl/dml/select/item/impl/TopProjectionExtractor.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.ParameterMarkerRowNumberValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.RowNumberValueSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; import java.util.Map; @@ -44,7 +44,7 @@ public final class TopProjectionExtractor implements OptionalSQLSegmentExtractor private final ExpressionExtractor expressionExtractor = new ExpressionExtractor(); @Override - public Optional extract(final ParserRuleContext expressionNode, final Map parameterMarkerIndexes) { + public Optional extract(final ParserRuleContext expressionNode, final Map parameterMarkerIndexes) { Optional topNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.TOP); if (!topNode.isPresent()) { return Optional.absent(); @@ -55,8 +55,8 @@ public Optional extract(final ParserRuleContext expressionNode, fina Optional rowNumberValueSegment = createRowNumberValueSegment(topExpr.get()); Preconditions.checkState(rowNumberValueSegment.isPresent()); ParserRuleContext rowNumberAliasNode = ExtractorUtils.getFirstChildNode(topNode.get().getParent(), RuleName.ALIAS); - return Optional.of( - new TopSegment(topNode.get().getStart().getStartIndex(), topNode.get().getStop().getStopIndex(), topNode.get().getText(), rowNumberValueSegment.get(), rowNumberAliasNode.getText())); + return Optional.of(new TopProjectionSegment(topNode.get().getStart().getStartIndex(), topNode.get().getStop().getStopIndex(), + topNode.get().getText(), rowNumberValueSegment.get(), rowNumberAliasNode.getText())); } private Optional createRowNumberValueSegment(final ExpressionSegment topExpr) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopProjectionSegment.java similarity index 91% rename from shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopSegment.java rename to shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopProjectionSegment.java index 40270ed978d093..b97ceef8c63a8c 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopSegment.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/pagination/top/TopProjectionSegment.java @@ -23,13 +23,13 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.RowNumberValueSegment; /** - * Top segment. + * Top projection segment. * * @author zhangliang */ @RequiredArgsConstructor @Getter -public final class TopSegment implements ProjectionSegment { +public final class TopProjectionSegment implements ProjectionSegment { private final int startIndex; @@ -39,5 +39,5 @@ public final class TopSegment implements ProjectionSegment { private final RowNumberValueSegment top; - private final String rowNumberAlias; + private final String alias; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngine.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngine.java index 967f511cadb0d6..db83bc4b88bb27 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngine.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngine.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.sql.parser.relation.segment.select.projection.ProjectionsContext; import org.apache.shardingsphere.sql.parser.relation.segment.select.pagination.PaginationContext; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.LimitSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement; @@ -49,11 +49,11 @@ public PaginationContext createPaginationContext(final SelectStatement selectSta if (limitSegment.isPresent()) { return new LimitPaginationContextEngine().createPaginationContext(limitSegment.get(), parameters); } - Optional topSegment = selectStatement.findSQLSegment(TopSegment.class); + Optional topProjectionSegment = selectStatement.findSQLSegment(TopProjectionSegment.class); Optional whereSegment = selectStatement.findSQLSegment(WhereSegment.class); - if (topSegment.isPresent()) { + if (topProjectionSegment.isPresent()) { return new TopPaginationContextEngine().createPaginationContext( - topSegment.get(), whereSegment.isPresent() ? whereSegment.get().getAndPredicates() : Collections.emptyList(), parameters); + topProjectionSegment.get(), whereSegment.isPresent() ? whereSegment.get().getAndPredicates() : Collections.emptyList(), parameters); } if (whereSegment.isPresent()) { return new RowNumberPaginationContextEngine().createPaginationContext(whereSegment.get().getAndPredicates(), projectionsContext, parameters); diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngine.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngine.java index b79fc727c65139..65dd08b50abc38 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngine.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/main/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngine.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.ParameterMarkerRowNumberValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.RowNumberValueSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.value.PredicateCompareRightValue; @@ -44,15 +44,15 @@ public final class TopPaginationContextEngine { /** * Create pagination context. * - * @param topSegment top segment + * @param topProjectionSegment top projection segment * @param andPredicates and predicates * @param parameters SQL parameters * @return pagination context */ - public PaginationContext createPaginationContext(final TopSegment topSegment, final Collection andPredicates, final List parameters) { - Optional rowNumberPredicate = getRowNumberPredicate(andPredicates, topSegment.getRowNumberAlias()); + public PaginationContext createPaginationContext(final TopProjectionSegment topProjectionSegment, final Collection andPredicates, final List parameters) { + Optional rowNumberPredicate = getRowNumberPredicate(andPredicates, topProjectionSegment.getAlias()); Optional offset = rowNumberPredicate.isPresent() ? createOffsetWithRowNumber(rowNumberPredicate.get()) : Optional.absent(); - PaginationValueSegment rowCount = topSegment.getTop(); + PaginationValueSegment rowCount = topProjectionSegment.getTop(); return new PaginationContext(offset.orNull(), rowCount, parameters); } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngineTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngineTest.java index d4e2581702ddcb..49889d179a7414 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngineTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/PaginationContextEngineTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.sql.parser.relation.segment.select.projection.ProjectionsContext; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.LimitSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement; import org.junit.Test; @@ -53,7 +53,7 @@ public void assertCreatePaginationContextWhenLimitSegmentIsPresent() { public void assertCreatePaginationContextWhenLimitSegmentAbsentAndTopSegmentPresent() { SelectStatement selectStatement = mock(SelectStatement.class); when(selectStatement.findSQLSegment(LimitSegment.class)).thenReturn(Optional.absent()); - when(selectStatement.findSQLSegment(TopSegment.class)).thenReturn(Optional.of(new TopSegment(0, 10, "text", null, "rowNumberAlias"))); + when(selectStatement.findSQLSegment(TopProjectionSegment.class)).thenReturn(Optional.of(new TopProjectionSegment(0, 10, "text", null, "rowNumberAlias"))); when(selectStatement.findSQLSegment(WhereSegment.class)).thenReturn(Optional.absent()); PaginationContext paginationContext = new PaginationContextEngine().createPaginationContext(selectStatement, null, Collections.emptyList()); assertFalse(paginationContext.getOffsetSegment().isPresent()); @@ -64,7 +64,7 @@ public void assertCreatePaginationContextWhenLimitSegmentAbsentAndTopSegmentPres public void assertCreatePaginationContextWhenLimitSegmentTopSegmentAbsentAndWhereSegmentPresent() { SelectStatement selectStatement = mock(SelectStatement.class); when(selectStatement.findSQLSegment(LimitSegment.class)).thenReturn(Optional.absent()); - when(selectStatement.findSQLSegment(TopSegment.class)).thenReturn(Optional.absent()); + when(selectStatement.findSQLSegment(TopProjectionSegment.class)).thenReturn(Optional.absent()); when(selectStatement.findSQLSegment(WhereSegment.class)).thenReturn(Optional.of(new WhereSegment(0, 10, 10))); ProjectionsContext projectionsContext = mock(ProjectionsContext.class); when(projectionsContext.findAlias(anyString())).thenReturn(Optional.absent()); @@ -77,7 +77,7 @@ public void assertCreatePaginationContextWhenLimitSegmentTopSegmentAbsentAndWher public void assertCreatePaginationContextWhenResultIsPaginationContext() { SelectStatement selectStatement = mock(SelectStatement.class); when(selectStatement.findSQLSegment(LimitSegment.class)).thenReturn(Optional.absent()); - when(selectStatement.findSQLSegment(TopSegment.class)).thenReturn(Optional.absent()); + when(selectStatement.findSQLSegment(TopProjectionSegment.class)).thenReturn(Optional.absent()); when(selectStatement.findSQLSegment(WhereSegment.class)).thenReturn(Optional.absent()); assertThat(new PaginationContextEngine().createPaginationContext(selectStatement, mock(ProjectionsContext.class), Collections.emptyList()), instanceOf(PaginationContext.class)); } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngineTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngineTest.java index 030371c202f5fb..2e40630d724e29 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngineTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-relation/src/test/java/org/apache/shardingsphere/sql/parser/relation/segment/select/pagination/engine/TopPaginationContextEngineTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.PaginationValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.ParameterMarkerRowNumberValueSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.value.PredicateCompareRightValue; @@ -57,10 +57,10 @@ public void setUp() { @Test public void assertCreatePaginationContextWhenRowNumberPredicateNotPresent() { - TopSegment topSegment = new TopSegment(0, 10, "text", null, "rowNumberAlias"); + TopProjectionSegment topProjectionSegment = new TopProjectionSegment(0, 10, "text", null, "rowNumberAlias"); Collection andPredicates = Collections.emptyList(); List parameters = Collections.emptyList(); - PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(topSegment, andPredicates, parameters); + PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(topProjectionSegment, andPredicates, parameters); assertFalse(paginationContext.getOffsetSegment().isPresent()); assertFalse(paginationContext.getRowCountSegment().isPresent()); } @@ -85,7 +85,7 @@ public void assertCreatePaginationContextWhenPredicateInRightValue() { Collection andPredicates = Collections.singleton(andPredicate); ProjectionsContext projectionsContext = mock(ProjectionsContext.class); when(projectionsContext.findAlias(anyString())).thenReturn(Optional.of("predicateRowNumberAlias")); - PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(new TopSegment(0, 10, "text", null, name), andPredicates, Collections.emptyList()); + PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(new TopProjectionSegment(0, 10, "text", null, name), andPredicates, Collections.emptyList()); assertFalse(paginationContext.getOffsetSegment().isPresent()); assertFalse(paginationContext.getRowCountSegment().isPresent()); } @@ -103,7 +103,8 @@ public void assertCreatePaginationContextWhenParameterMarkerRowNumberValueSegmen Collection andPredicates = Collections.singleton(andPredicate); ProjectionsContext projectionsContext = mock(ProjectionsContext.class); when(projectionsContext.findAlias(anyString())).thenReturn(Optional.of("predicateRowNumberAlias")); - PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(new TopSegment(0, 10, "text", null, name), andPredicates, Collections.singletonList(1)); + PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext( + new TopProjectionSegment(0, 10, "text", null, name), andPredicates, Collections.singletonList(1)); assertTrue(paginationContext.getOffsetSegment().isPresent()); PaginationValueSegment paginationValueSegment = paginationContext.getOffsetSegment().get(); assertThat(paginationValueSegment, instanceOf(ParameterMarkerRowNumberValueSegment.class)); @@ -126,7 +127,7 @@ private void assertCreatePaginationContextWhenRowNumberPredicatePresentAndWithGi Collection andPredicates = Collections.singleton(andPredicate); ProjectionsContext projectionsContext = mock(ProjectionsContext.class); when(projectionsContext.findAlias(anyString())).thenReturn(Optional.of("predicateRowNumberAlias")); - PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(new TopSegment(0, 10, "text", null, name), andPredicates, Collections.emptyList()); + PaginationContext paginationContext = topPaginationContextEngine.createPaginationContext(new TopProjectionSegment(0, 10, "text", null, name), andPredicates, Collections.emptyList()); assertTrue(paginationContext.getOffsetSegment().isPresent()); PaginationValueSegment paginationValueSegment = paginationContext.getOffsetSegment().get(); assertThat(paginationValueSegment, instanceOf(NumberLiteralRowNumberValueSegment.class)); diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/SQLStatementAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/SQLStatementAssert.java index 96c1967d15f227..d8e750413c211c 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/SQLStatementAssert.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/SQLStatementAssert.java @@ -80,12 +80,12 @@ public static void assertIs(final SQLStatementAssertMessage assertMessage, final } private static void assertSelectStatement(final SQLStatementAssertMessage assertMessage, final SelectStatement actual, final ParserResult expected, final SQLCaseType sqlCaseType) { - ProjectionAssert.assertIs(assertMessage, actual.getProjections(), expected.getProjections(), sqlCaseType); - Optional groupBySegment = actual.findSQLSegment(GroupBySegment.class); + ProjectionAssert.assertIs(assertMessage, actual.getProjections(), expected.getProjections()); + Optional groupBySegment = actual.getGroupBy(); if (groupBySegment.isPresent()) { GroupByAssert.assertIs(assertMessage, groupBySegment.get().getGroupByItems(), expected.getGroupByColumns()); } - Optional orderBySegment = actual.findSQLSegment(OrderBySegment.class); + Optional orderBySegment = actual.getOrderBy(); if (orderBySegment.isPresent()) { OrderByAssert.assertIs(assertMessage, orderBySegment.get().getOrderByItems(), expected.getOrderByColumns()); } @@ -94,7 +94,7 @@ private static void assertSelectStatement(final SQLStatementAssertMessage assert PaginationAssert.assertOffset(assertMessage, limitSegment.get().getOffset().orNull(), expected.getOffset(), sqlCaseType); PaginationAssert.assertRowCount(assertMessage, limitSegment.get().getRowCount().orNull(), expected.getRowCount(), sqlCaseType); } - Optional whereSegment = actual.findSQLSegment(WhereSegment.class); + Optional whereSegment = actual.getWhere(); if (whereSegment.isPresent() && null != expected.getWhereSegment()) { PredicateAssert.assertIs(assertMessage, whereSegment.get(), expected.getWhereSegment(), sqlCaseType); } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/projection/ProjectionAssert.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/projection/ProjectionAssert.java index 0a8bfd33b94941..a3937d77393284 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/projection/ProjectionAssert.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/asserts/projection/ProjectionAssert.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedProjection; import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedProjections; import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedShorthandProjection; +import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedTableSegment; import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedTopProjection; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationDistinctProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment; @@ -35,13 +36,16 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ShorthandProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopSegment; -import org.apache.shardingsphere.test.sql.SQLCaseType; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.ParameterMarkerRowNumberValueSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment; +import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment; -import java.util.Collection; -import java.util.LinkedList; +import java.util.List; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; /** @@ -58,46 +62,97 @@ public final class ProjectionAssert { * @param assertMessage assert message * @param actual actual projection * @param expected expected projections - * @param sqlCaseType SQL case type */ - public static void assertIs(final SQLStatementAssertMessage assertMessage, final ProjectionsSegment actual, final ExpectedProjections expected, final SQLCaseType sqlCaseType) { - Collection projections = actual.getProjections(); - assertThat(assertMessage.getText("Projections size error: "), projections.size(), is(expected.getSize())); - Collection expectedBaseProjections = new LinkedList<>(); - for (ProjectionSegment each : projections) { - if (each instanceof ShorthandProjectionSegment) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedShorthandProjection.class); - } - if (each instanceof AggregationProjectionSegment) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedAggregationProjection.class); - } - if (each instanceof AggregationDistinctProjectionSegment) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedAggregationDistinctProjection.class); - } - if (each instanceof ColumnProjectionSegment) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedColumnProjection.class); - } - if (each instanceof ExpressionProjectionSegment) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedExpressionProjection.class); - } - if (each instanceof TopSegment && SQLCaseType.Literal.equals(sqlCaseType)) { - expectedBaseProjections = expected.findExpectedProjections(ExpectedTopProjection.class); - } - if (!expectedBaseProjections.isEmpty()) { - assertProjection(assertMessage, each, expectedBaseProjections); - } + public static void assertIs(final SQLStatementAssertMessage assertMessage, final ProjectionsSegment actual, final ExpectedProjections expected) { + assertProjections(assertMessage, actual, expected); + List expectedProjections = expected.getExpectedProjections(); + int count = 0; + for (ProjectionSegment each : actual.getProjections()) { + assertProjection(assertMessage, each, expectedProjections.get(count)); + count++; } } - private static void assertProjection(final SQLStatementAssertMessage assertMessage, final ProjectionSegment actual, final Collection expected) { - String actualText = actual.getText(); - String expectedText = ""; - for (ExpectedProjection each: expected) { - if (actualText.equals(each.getText())) { - expectedText = each.getText(); - break; - } + private static void assertProjections(final SQLStatementAssertMessage assertMessage, final ProjectionsSegment actual, final ExpectedProjections expected) { + assertThat(assertMessage.getText("Projections size assertion error: "), actual.getProjections().size(), is(expected.getSize())); + assertThat(assertMessage.getText("Projections distinct row assertion error: "), actual.isDistinctRow(), is(expected.isDistinctRow())); + assertThat(assertMessage.getText("Projections start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex())); + assertThat(assertMessage.getText("Projections stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex())); + } + + private static void assertProjection(final SQLStatementAssertMessage assertMessage, final ProjectionSegment actual, final ExpectedProjection expected) { + if (actual instanceof ShorthandProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedShorthandProjection.class)); + assertShorthandProjection(assertMessage, (ShorthandProjectionSegment) actual, (ExpectedShorthandProjection) expected); + } else if (actual instanceof ColumnProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedColumnProjection.class)); + assertColumnProjection(assertMessage, (ColumnProjectionSegment) actual, (ExpectedColumnProjection) expected); + } else if (actual instanceof AggregationProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedAggregationProjection.class)); + assertAggregationProjection(assertMessage, (AggregationProjectionSegment) actual, (ExpectedAggregationProjection) expected); + } else if (actual instanceof ExpressionProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedExpressionProjection.class)); + assertExpressionProjection(assertMessage, (ExpressionProjectionSegment) actual, (ExpectedExpressionProjection) expected); + } else if (actual instanceof TopProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedTopProjection.class)); + assertTopProjection(assertMessage, (TopProjectionSegment) actual, (ExpectedTopProjection) expected); + } + assertThat(assertMessage.getText("Projection start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex())); + assertThat(assertMessage.getText("Projection stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex())); + } + + private static void assertShorthandProjection(final SQLStatementAssertMessage assertMessage, final ShorthandProjectionSegment actual, final ExpectedShorthandProjection expected) { + if (actual.getOwner().isPresent()) { + assertOwner(assertMessage, actual.getOwner().get(), expected.getOwner()); + } else { + assertNull(expected.getOwner()); + } + } + + private static void assertColumnProjection(final SQLStatementAssertMessage assertMessage, final ColumnProjectionSegment actual, final ExpectedColumnProjection expected) { + assertThat(assertMessage.getText("Column projection name assertion error: "), actual.getName(), is(expected.getName())); + assertThat(assertMessage.getText("Column projection start delimiter assertion error: "), actual.getQuoteCharacter().getStartDelimiter(), is(expected.getStartDelimiter())); + assertThat(assertMessage.getText("Column projection end delimiter assertion error: "), actual.getQuoteCharacter().getEndDelimiter(), is(expected.getEndDelimiter())); + assertThat(assertMessage.getText("Column projection alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias())); + if (actual.getOwner().isPresent()) { + assertOwner(assertMessage, actual.getOwner().get(), expected.getOwner()); + } else { + assertNull(expected.getOwner()); + } + } + + private static void assertOwner(final SQLStatementAssertMessage assertMessage, final TableSegment actual, final ExpectedTableSegment expected) { + assertThat(assertMessage.getText("Projection owner name assertion error: "), actual.getTableName(), is(expected.getName())); + assertThat(assertMessage.getText("Projection owner name start delimiter assertion error: "), actual.getTableQuoteCharacter().getStartDelimiter(), is(expected.getStartDelimiter())); + assertThat(assertMessage.getText("Projection owner name end delimiter assertion error: "), actual.getTableQuoteCharacter().getEndDelimiter(), is(expected.getEndDelimiter())); + assertThat(assertMessage.getText("Projection owner name start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex())); + assertThat(assertMessage.getText("Projection owner name stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex())); + } + + private static void assertAggregationProjection(final SQLStatementAssertMessage assertMessage, final AggregationProjectionSegment actual, final ExpectedAggregationProjection expected) { + assertThat(assertMessage.getText("Aggregation projection type assertion error: "), actual.getType().name(), is(expected.getType())); + assertThat(assertMessage.getText("Aggregation projection inner expression start index assertion error: "), actual.getInnerExpressionStartIndex(), is(expected.getInnerExpressionStartIndex())); + assertThat(assertMessage.getText("Aggregation projection alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias())); + if (actual instanceof AggregationDistinctProjectionSegment) { + assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedAggregationDistinctProjection.class)); + assertThat(assertMessage.getText("Aggregation projection alias assertion error: "), + ((AggregationDistinctProjectionSegment) actual).getDistinctExpression(), is(((ExpectedAggregationDistinctProjection) expected).getDistinctExpression())); + } + } + + private static void assertExpressionProjection(final SQLStatementAssertMessage assertMessage, final ExpressionProjectionSegment actual, final ExpectedExpressionProjection expected) { + assertThat(assertMessage.getText("Expression projection alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias())); + } + + private static void assertTopProjection(final SQLStatementAssertMessage assertMessage, final TopProjectionSegment actual, final ExpectedTopProjection expected) { + if (actual.getTop() instanceof NumberLiteralRowNumberValueSegment) { + assertThat(assertMessage.getText("Expression projection top value assertion error: "), ((NumberLiteralRowNumberValueSegment) actual.getTop()).getValue(), is(expected.getTopValue())); + } else { + assertThat(assertMessage.getText("Expression projection top parameter index assertion error: "), + ((ParameterMarkerRowNumberValueSegment) actual.getTop()).getParameterIndex(), is(expected.getTopParameterIndex())); } - assertThat(assertMessage.getText("Projection text assert error: "), actualText, is(expectedText)); + assertThat(assertMessage.getText("Expression projection top value start index assertion error: "), actual.getTop().getStartIndex(), is(expected.getTopValueStartIndex())); + assertThat(assertMessage.getText("Expression projection top value stop index assertion error: "), actual.getTop().getStopIndex(), is(expected.getTopValueStopIndex())); + assertThat(assertMessage.getText("Expression projection alias assertion error: "), actual.getAlias(), is(expected.getAlias())); } } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedBaseProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/AbstractExpectedProjection.java similarity index 87% rename from shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedBaseProjection.java rename to shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/AbstractExpectedProjection.java index 5366e3fd21a986..86d8faf69d9335 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedBaseProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/AbstractExpectedProjection.java @@ -27,14 +27,11 @@ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public class ExpectedBaseProjection implements ExpectedProjection { +public abstract class AbstractExpectedProjection implements ExpectedProjection { @XmlAttribute(name = "start-index") - private Integer startIndex; + private int startIndex; @XmlAttribute(name = "stop-index") - private Integer stopIndex; - - @XmlAttribute - private String text; + private int stopIndex; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationDistinctProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationDistinctProjection.java index dcafcd2da7df7e..4762da73fa43d2 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationDistinctProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationDistinctProjection.java @@ -28,7 +28,7 @@ @Setter @XmlAccessorType(XmlAccessType.FIELD) public final class ExpectedAggregationDistinctProjection extends ExpectedAggregationProjection { - - @XmlAttribute + + @XmlAttribute(name = "distinct-expression") private String distinctExpression; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationProjection.java index d622ff341db258..58e41efb5235db 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedAggregationProjection.java @@ -27,17 +27,14 @@ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public class ExpectedAggregationProjection extends ExpectedBaseProjection { - - @XmlAttribute - private Integer innerExpressionStartIndex; +public class ExpectedAggregationProjection extends AbstractExpectedProjection { @XmlAttribute private String type; + @XmlAttribute(name = "inner-expression-start-index") + private int innerExpressionStartIndex; + @XmlAttribute private String alias; - - @XmlAttribute(name = "aggregation-inner-expression") - private String innerExpression; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedColumnProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedColumnProjection.java index 5bcbeeb8985ce6..b8e1f9e473c0ac 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedColumnProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedColumnProjection.java @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.sql.parser.core.constant.QuoteCharacter; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -29,17 +28,20 @@ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public final class ExpectedColumnProjection extends ExpectedBaseProjection { - - @XmlAttribute - private String alias; +public final class ExpectedColumnProjection extends AbstractExpectedProjection { @XmlAttribute private String name; + @XmlAttribute(name = "start-delimiter") + private String startDelimiter = ""; + + @XmlAttribute(name = "end-delimiter") + private String endDelimiter = ""; + @XmlAttribute - private QuoteCharacter quoteCharacter = QuoteCharacter.NONE; + private String alias; - @XmlElement(name = "table-segment") - private ExpectedTableSegment owner = new ExpectedTableSegment(); + @XmlElement(name = "owner") + private ExpectedTableSegment owner; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedExpressionProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedExpressionProjection.java index 6da660cdab8810..32f21492e50e1c 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedExpressionProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedExpressionProjection.java @@ -27,7 +27,8 @@ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public final class ExpectedExpressionProjection extends ExpectedBaseProjection { +public final class ExpectedExpressionProjection extends AbstractExpectedProjection { + @XmlAttribute private String alias; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjection.java index 6fea9c0f3a794b..50a15c1ca1535f 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjection.java @@ -20,9 +20,16 @@ public interface ExpectedProjection { /** - * Get text. + * Get start index. * - * @return text + * @return start index */ - String getText(); + int getStartIndex(); + + /** + * Get stop index. + * + * @return stop index + */ + int getStopIndex(); } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjections.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjections.java index 4d573898bdcfd2..569900350b6603 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjections.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedProjections.java @@ -24,47 +24,45 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; +import java.util.List; -@Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) public final class ExpectedProjections { + @Getter @XmlAttribute(name = "start-index") - private Integer startIndex; + private int startIndex; + @Getter @XmlAttribute(name = "stop-index") - private Integer stopIndex; + private int stopIndex; - @XmlAttribute + @Getter + @XmlAttribute(name = "distinct-row") private boolean distinctRow; - @XmlElementWrapper(name = "shorthand-projections") @XmlElement(name = "shorthand-projection") - private Collection expectedShorthandProjections = new LinkedList<>(); + private Collection shorthandProjections = new LinkedList<>(); + + @XmlElement(name = "column-projection") + private Collection columnProjections = new LinkedList<>(); - @XmlElementWrapper(name = "aggregation-projections") @XmlElement(name = "aggregation-projection") - private Collection expectedAggregationProjections = new LinkedList<>(); + private Collection aggregationProjections = new LinkedList<>(); - @XmlElementWrapper(name = "aggregation-distinct-projections") @XmlElement(name = "aggregation-distinct-projection") - private Collection expectedAggregationDistinctProjections = new LinkedList<>(); + private Collection aggregationDistinctProjections = new LinkedList<>(); - @XmlElementWrapper(name = "column-projections") - @XmlElement(name = "column-projection") - private Collection expectedColumnProjections = new LinkedList<>(); - - @XmlElementWrapper(name = "expression-projections") @XmlElement(name = "expression-projection") - private Collection expectedExpressionProjections = new LinkedList<>(); + private Collection expressionProjections = new LinkedList<>(); - @XmlElementWrapper(name = "top-projections") @XmlElement(name = "top-projection") - private Collection expectedTopProjections = new LinkedList<>(); + private Collection topProjections = new LinkedList<>(); /** * Get size. @@ -72,38 +70,29 @@ public final class ExpectedProjections { * @return size */ public int getSize() { - return expectedAggregationProjections.size() + expectedShorthandProjections.size() - + expectedAggregationDistinctProjections.size() + expectedColumnProjections.size() - + expectedExpressionProjections.size() + expectedTopProjections.size(); + return shorthandProjections.size() + columnProjections.size() + aggregationProjections.size() + aggregationDistinctProjections.size() + expressionProjections.size() + topProjections.size(); } /** - * Find expected projections. - * - * @param expectedProjectionType expected projections type - * @param type of projection type + * Get expected projections. + * * @return expected projections */ - public Collection findExpectedProjections(final Class expectedProjectionType) { - Collection result = new LinkedList<>(); - if (expectedProjectionType.equals(ExpectedShorthandProjection.class)) { - result.addAll(expectedShorthandProjections); - } - if (expectedProjectionType.equals(ExpectedAggregationProjection.class)) { - result.addAll(expectedAggregationProjections); - } - if (expectedProjectionType.equals(ExpectedColumnProjection.class)) { - result.addAll(expectedColumnProjections); - } - if (expectedProjectionType.equals(ExpectedAggregationDistinctProjection.class)) { - result.addAll(expectedAggregationDistinctProjections); - } - if (expectedProjectionType.equals(ExpectedExpressionProjection.class)) { - result.addAll(expectedExpressionProjections); - } - if (expectedProjectionType.equals(ExpectedTopProjection.class)) { - result.addAll(expectedExpressionProjections); - } + public List getExpectedProjections() { + List result = new LinkedList<>(); + result.addAll(shorthandProjections); + result.addAll(columnProjections); + result.addAll(aggregationProjections); + result.addAll(aggregationDistinctProjections); + result.addAll(expressionProjections); + result.addAll(topProjections); + Collections.sort(result, new Comparator() { + + @Override + public int compare(final ExpectedProjection o1, final ExpectedProjection o2) { + return o1.getStartIndex() - o2.getStartIndex(); + } + }); return result; } } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedRowNumberValueSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedRowNumberValueSegment.java deleted file mode 100644 index 493f5c1428a645..00000000000000 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedRowNumberValueSegment.java +++ /dev/null @@ -1,43 +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.integrate.jaxb.projection; - -import lombok.Getter; -import lombok.Setter; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@Getter -@Setter -@XmlAccessorType(XmlAccessType.FIELD) -public final class ExpectedRowNumberValueSegment { - - @XmlAttribute(name = "parameter-index") - private Integer parameterIndex; - - @XmlAttribute(name = "start-index") - private Integer startIndex; - - @XmlAttribute(name = "stop-index") - private Integer stopIndex; - - @XmlAttribute(name = "bound-opened") - private boolean boundOpened; -} diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedShorthandProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedShorthandProjection.java index c9ddd2bc21b783..a7d251e2b37a22 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedShorthandProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedShorthandProjection.java @@ -27,9 +27,8 @@ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public final class ExpectedShorthandProjection extends ExpectedBaseProjection { - - @XmlElement(name = "table-segment") - private ExpectedTableSegment owner = new ExpectedTableSegment(); - +public final class ExpectedShorthandProjection extends AbstractExpectedProjection { + + @XmlElement(name = "owner") + private ExpectedTableSegment owner; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTableSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTableSegment.java index 1fc957972d2c8f..7bff3d2b2c61c7 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTableSegment.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTableSegment.java @@ -19,12 +19,10 @@ import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.sql.parser.core.constant.QuoteCharacter; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; @Getter @Setter @@ -32,20 +30,17 @@ public final class ExpectedTableSegment { @XmlAttribute(name = "start-index") - private Integer startIndex; + private int startIndex; @XmlAttribute(name = "stop-index") - private Integer stopIndex; + private int stopIndex; @XmlAttribute private String name; - @XmlAttribute - private QuoteCharacter quoteCharacter = QuoteCharacter.NONE; - - @XmlElement(name = "schema-segment") - private ExpectedSchemaSegment expectedSchemaSegment = new ExpectedSchemaSegment(); + @XmlAttribute(name = "start-delimiter") + private String startDelimiter = ""; - @XmlAttribute - private String alias; + @XmlAttribute(name = "end-delimiter") + private String endDelimiter = ""; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTopProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTopProjection.java index 7a5aa9c26917dd..0596f49213ceb4 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTopProjection.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTopProjection.java @@ -20,19 +20,27 @@ import lombok.Getter; import lombok.Setter; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) -public final class ExpectedTopProjection extends ExpectedBaseProjection { - - @XmlElement(name = "row-number-value-segment") - private ExpectedRowNumberValueSegment top; - - @XmlAttribute(name = "row-number-alias") - private String rowNumberAlias; +public final class ExpectedTopProjection extends AbstractExpectedProjection { + + @XmlAttribute(name = "top-value") + private Long topValue; + + @XmlAttribute(name = "top-parameter-index") + private Integer topParameterIndex; + + @XmlAttribute(name = "top-value-start-index") + private int topValueStartIndex; + + @XmlAttribute(name = "top-value-stop-index") + private int topValueStopIndex; + + @XmlAttribute(name = "alias") + private String alias; } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/long_sql.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/long_sql.xml index 37afcd3a60f63b..488859bece150a 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/long_sql.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/long_sql.xml @@ -21,6 +21,9 @@ + + + @@ -26423,10 +26426,5 @@ - - - - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml index 91ff754ad93cd8..0c6a0d1fe945dd 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml @@ -19,9 +19,7 @@ - - - + @@ -29,6 +27,11 @@
+ + + + + @@ -39,19 +42,21 @@ - - - - - - -
+ + + + + + + + + @@ -62,79 +67,63 @@ - - - - - - - - - - -
+ + + - - - - -
+ + + - - - - -
+ + + - - - - -
+ + + - - - - -
+ + + @@ -145,17 +134,15 @@ - - - - -
+ + + @@ -166,11 +153,6 @@ - - - - - @@ -178,9 +160,7 @@
- - - + @@ -205,9 +185,7 @@
- - - + @@ -236,9 +214,7 @@
- - - + @@ -264,9 +240,7 @@
- - - + @@ -289,6 +263,9 @@
+ + + @@ -301,17 +278,15 @@ - - - - -
+ + + @@ -324,11 +299,6 @@ - - - - - @@ -337,11 +307,9 @@
- - - - - + + + @@ -365,16 +333,14 @@
+ + + + + - - - - - - - @@ -383,6 +349,11 @@
+ + + + + @@ -403,13 +374,6 @@ - - - - - - - @@ -418,6 +382,11 @@
+ + + + + @@ -438,13 +407,6 @@ - - - - - - - @@ -453,6 +415,11 @@
+ + + + + @@ -468,13 +435,6 @@ - - - - - - - @@ -483,6 +443,11 @@
+ + + + + @@ -498,19 +463,17 @@ - - - - - - -
+ + + + > + @@ -518,13 +481,6 @@ - - - - - > - - @@ -532,6 +488,11 @@
+ + + + + @@ -539,19 +500,15 @@ - - - - - - -
+ + + @@ -562,17 +519,15 @@ - - - - -
+ + + @@ -583,17 +538,15 @@ - - - - -
+ + + @@ -601,83 +554,70 @@ - - - - -
+ + + - - - - -
+ + + - - - - -
+ + + + + - - - - -
+ + + + + - - - - - - -
+ + + - - - - - @@ -685,17 +625,17 @@
+ + + + + + + + - - - - - - - - @@ -703,9 +643,7 @@
- - - + @@ -713,10 +651,8 @@
- - - - + + @@ -725,9 +661,7 @@
- - - + @@ -736,10 +670,8 @@
- - - - + + @@ -748,12 +680,8 @@
- - - - - - + + @@ -768,12 +696,8 @@
- - - - - - + + @@ -787,14 +711,12 @@
+ + + - - - - - @@ -802,9 +724,7 @@
- - - + @@ -813,13 +733,9 @@
- - - - - - - + + + @@ -830,9 +746,7 @@
- - - + @@ -840,64 +754,56 @@ + + + - - - - -
+ + + - - - - -
+ + + - - - - -
+ + + - - - - - @@ -905,9 +811,7 @@
- - - + @@ -916,9 +820,7 @@
- - - + @@ -926,10 +828,8 @@
- - - - + + @@ -948,9 +848,7 @@
- - - + @@ -959,9 +857,7 @@
- - - + @@ -969,10 +865,8 @@
- - - - + + @@ -990,10 +884,8 @@
- - - - + + @@ -1002,17 +894,13 @@
- - - + - - - + @@ -1021,9 +909,7 @@
- - - + @@ -1032,9 +918,7 @@
- - - + @@ -1043,17 +927,13 @@
- - - + - - - - + + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_aggregate.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_aggregate.xml index f8f8c213316ac9..bcc7cbabfceb90 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_aggregate.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_aggregate.xml @@ -22,9 +22,7 @@
- - - + @@ -33,9 +31,7 @@
- - - + @@ -44,9 +40,7 @@
- - - + @@ -55,9 +49,7 @@
- - - + @@ -66,9 +58,7 @@
- - - + @@ -77,9 +67,7 @@
- - - + @@ -88,9 +76,7 @@
- - - + @@ -99,6 +85,9 @@
+ + + @@ -111,11 +100,6 @@ - - - - - @@ -123,6 +107,9 @@
+ + + @@ -135,11 +122,6 @@ - - - - - @@ -147,9 +129,7 @@
- - - + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_expression.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_expression.xml index 7081acafa75504..133a7c4da53fa1 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_expression.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_expression.xml @@ -21,34 +21,34 @@
+ + + + - - - - -
+ + + - - - - -
+ + + @@ -57,10 +57,5 @@ - - - - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_group_by.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_group_by.xml index e98ae1307eef81..4ef6c0e242ba58 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_group_by.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_group_by.xml @@ -21,30 +21,25 @@
+ + + + - - - - - - - -
- - - - + + + @@ -52,14 +47,6 @@ - - - - - - - - @@ -67,12 +54,8 @@
- - - - - - + + @@ -87,12 +70,8 @@
- - - - - - + + @@ -107,12 +86,8 @@
- - - - - - + + @@ -127,12 +102,8 @@
- - - - - - + + @@ -147,6 +118,9 @@
+ + + @@ -159,11 +133,6 @@ - - - - - @@ -174,9 +143,7 @@
- - - + @@ -192,12 +159,8 @@
- - - - - - + + @@ -212,25 +175,27 @@
+ + + + + - - - - - - -
+ + + + @@ -239,14 +204,6 @@ - - - - - - - - @@ -257,12 +214,8 @@
- - - - - - + + @@ -274,12 +227,8 @@
- - - - - - + + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_join.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_join.xml index 4edf76c48b3163..5d6a854ce7f7cb 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_join.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_join.xml @@ -30,24 +30,22 @@ - - - - - + + + -
- - - - + + + + + @@ -55,13 +53,6 @@ - - - - - - - @@ -69,6 +60,11 @@
+ + + + + @@ -76,12 +72,5 @@ - - - - - - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_or.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_or.xml index ce9d13c275ae1e..10e1ba847bbbea 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_or.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_or.xml @@ -21,6 +21,9 @@
+ + + @@ -33,17 +36,15 @@ - - - - -
+ + + @@ -56,33 +57,29 @@ - - - - -
+ + + - - - - -
+ + + @@ -103,17 +100,15 @@ - - - - -
+ + + @@ -153,11 +148,6 @@ - - - - - @@ -165,6 +155,11 @@
+ + + + + @@ -183,13 +178,6 @@ - - - - - - - @@ -198,6 +186,11 @@
+ + + + + @@ -221,12 +214,5 @@ - - - - - - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_order_by.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_order_by.xml index cf9f039946e329..fc62a5a0c00e34 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_order_by.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_order_by.xml @@ -21,15 +21,13 @@
+ + + - - - - - @@ -37,6 +35,11 @@
+ + + + + @@ -46,29 +49,20 @@ - - - - - - -
+ + + + + - - - - - - - @@ -76,6 +70,11 @@
+ + + + + @@ -86,13 +85,6 @@ - - - - - - - @@ -100,16 +92,14 @@
+ + + + + - - - - - - - @@ -117,66 +107,56 @@
+ + + + + - - - - - - -
+ + + + + + + - - - - - - - - - - -
+ + + + + - - - - - - -
+ + + - - - - - @@ -191,35 +171,28 @@ - -
- + + + + + - - - - - - -
+ + + - - - - - @@ -227,18 +200,16 @@
+ + + + + + + + - - - - - - - - - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination.xml index b83dde6900e8cd..b2a60fe85bed42 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination.xml @@ -22,6 +22,11 @@
+ + + + + @@ -34,13 +39,6 @@ - - - - - - - @@ -52,6 +50,11 @@
+ + + + + @@ -64,13 +67,6 @@ - - - - - - - @@ -82,6 +78,11 @@
+ + + + + @@ -94,13 +95,6 @@ - - - - - - - @@ -113,6 +107,11 @@
+ + + + + @@ -125,13 +124,6 @@ - - - - - - - @@ -144,6 +136,21 @@
+ + + + + + + + + + + + + + + @@ -156,19 +163,6 @@ - - - - - - - - - - - - - @@ -180,6 +174,11 @@
+ + + + + @@ -192,13 +191,6 @@ - - - - - - - @@ -211,6 +203,21 @@
+ + + + + + + + + + + + + + + @@ -223,18 +230,6 @@ - - - - - - - - - - - - @@ -247,6 +242,21 @@
+ + + + + + + + + + + + + + + @@ -259,18 +269,6 @@ - - - - - - - - - - - - @@ -283,6 +281,17 @@
+ + + + + + + + + + + @@ -295,19 +304,6 @@ - - - - - - - - - - - - - @@ -319,6 +315,17 @@
+ + + + + + + + + + + @@ -331,19 +338,6 @@ - - - - - - - - - - - - - @@ -356,6 +350,17 @@
+ + + + + + + + + + + @@ -368,19 +373,6 @@ - - - - - - - - - - - - - @@ -393,9 +385,7 @@
- - - + @@ -408,9 +398,7 @@
- - - + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination_group_by_order_by.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination_group_by_order_by.xml index bbd017078611e3..798138c58e3a54 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination_group_by_order_by.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select_pagination_group_by_order_by.xml @@ -22,6 +22,11 @@
+ + + + + @@ -34,13 +39,6 @@ - - - - - - - @@ -56,6 +54,11 @@
+ + + + + @@ -68,13 +71,6 @@ - - - - - - - @@ -90,6 +86,21 @@
+ + + + + + + + + + + + + + + @@ -102,17 +113,6 @@ - - - - - - - - - - - @@ -128,6 +128,21 @@
+ + + + + + + + + + + + + + + @@ -140,17 +155,6 @@ - - - - - - - - - - - @@ -166,6 +170,21 @@
+ + + + + + + + + + + + + + + @@ -178,17 +197,6 @@ - - - - - - - - - - - @@ -204,6 +212,21 @@
+ + + + + + + + + + + + + + + @@ -216,19 +239,6 @@ - - - - - - - - - - - - - @@ -244,6 +254,17 @@
+ + + + + + + + + + + @@ -256,19 +277,6 @@ - - - - - - - - - - - - - @@ -284,6 +292,17 @@
+ + + + + + + + + + + @@ -296,19 +315,6 @@ - - - - - - - - - - - - - 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 204891ca7703a0..092de93a2528c7 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 @@ -37,17 +37,13 @@
- - - + + + + - - - - - @@ -55,9 +51,7 @@
- - - +