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 bc12f090b2763..9cbe793cd6916 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 40270ed978d09..b97ceef8c63a8 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 967f511cadb0d..db83bc4b88bb2 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 b79fc727c6513..65dd08b50abc3 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 d4e2581702ddc..49889d179a741 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 030371c202f5f..2e40630d724e2 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/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 f5880261be43e..f9d296c1b1043 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 @@ -28,6 +28,7 @@ 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; import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment; @@ -35,6 +36,9 @@ 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.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 org.apache.shardingsphere.test.sql.SQLCaseType; @@ -92,6 +96,9 @@ private static void assertProjection(final SQLStatementAssertMessage assertMessa } 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())); @@ -117,6 +124,14 @@ private static void assertColumnProjection(final SQLStatementAssertMessage asser } } + 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())); @@ -132,11 +147,15 @@ private static void assertExpressionProjection(final SQLStatementAssertMessage a assertThat(assertMessage.getText("Expression projection alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias())); } - 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 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("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/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 493f5c1428a64..0000000000000 --- 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/ExpectedTopProjection.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/jaxb/projection/ExpectedTopProjection.java index b7dff265e46ef..0596f49213ceb 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,9 +20,8 @@ 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 @@ -30,9 +29,18 @@ @XmlAccessorType(XmlAccessType.FIELD) public final class ExpectedTopProjection extends AbstractExpectedProjection { - @XmlElement(name = "row-number-value-segment") - private ExpectedRowNumberValueSegment top; + @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 = "row-number-alias") - private String rowNumberAlias; + @XmlAttribute(name = "alias") + private String alias; } 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 d8e327ed661b6..133a7c4da53fa 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 @@ -22,7 +22,7 @@ - + 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 6790e93d25e43..b2a60fe85bed4 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 @@ -137,9 +137,7 @@
- - - + @@ -206,7 +204,7 @@
- + @@ -245,7 +243,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 6570f55ede6e7..798138c58e3a5 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 @@ -87,7 +87,7 @@
- + @@ -129,7 +129,7 @@
- + @@ -171,7 +171,7 @@
- + @@ -213,9 +213,7 @@
- - - +