You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/11/18 07:16:08 UTC
[shardingsphere] branch master updated: Support select group by statement when column contains null values (#22253)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b5eb9ef50b9 Support select group by statement when column contains null values (#22253)
b5eb9ef50b9 is described below
commit b5eb9ef50b952cfe5e4245ce278961d8b8a9de4f
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Fri Nov 18 15:16:01 2022 +0800
Support select group by statement when column contains null values (#22253)
---
.../impl/EncryptOrderByItemTokenGeneratorTest.java | 3 +-
.../merge/dql/ShardingDQLResultMerger.java | 12 +++++-
.../merge/dql/groupby/GroupByRowComparator.java | 2 +-
.../sharding/merge/dql/orderby/CompareUtil.java | 10 +++--
.../sharding/merge/dql/orderby/OrderByValue.java | 10 ++---
.../generator/impl/ProjectionsTokenGenerator.java | 38 +++++++++++++------
.../merge/dql/ShardingDQLResultMergerTest.java | 37 ++++++++++---------
.../dql/groupby/GroupByMemoryMergedResultTest.java | 7 ++--
.../dql/groupby/GroupByRowComparatorTest.java | 37 ++++++++++---------
.../dql/groupby/GroupByStreamMergedResultTest.java | 5 ++-
.../merge/dql/groupby/GroupByValueTest.java | 21 ++++++-----
.../merge/dql/orderby/CompareUtilTest.java | 43 +++++++++++-----------
.../dql/orderby/OrderByStreamMergedResultTest.java | 5 ++-
.../merge/dql/orderby/OrderByValueTest.java | 27 +++++++-------
.../token/ShardingRemoveTokenGeneratorTest.java | 3 +-
.../orderby/engine/OrderByContextEngine.java | 12 +++++-
.../groupby/engine/GroupByContextEngineTest.java | 7 ++--
.../orderby/engine/OrderByContextEngineTest.java | 13 ++++---
.../select/pagination/PaginationContextTest.java | 5 ++-
.../engine/ProjectionsContextEngineTest.java | 17 +++++----
.../statement/impl/SelectStatementContextTest.java | 17 +++++----
.../statement/impl/MySQLStatementSQLVisitor.java | 8 ++--
.../impl/OpenGaussStatementSQLVisitor.java | 26 +++++++++----
.../impl/OracleDMLStatementSQLVisitor.java | 8 ++--
.../statement/impl/OracleStatementSQLVisitor.java | 21 ++++++++---
.../impl/PostgreSQLStatementSQLVisitor.java | 26 +++++++++----
.../statement/impl/SQL92StatementSQLVisitor.java | 6 ++-
.../impl/SQLServerStatementSQLVisitor.java | 8 ++--
.../NullsOrderDirection.java} | 23 +++++-------
.../dml/order/item/ColumnOrderByItemSegment.java | 12 ++----
.../order/item/ExpressionOrderByItemSegment.java | 16 +++-----
.../dml/order/item/IndexOrderByItemSegment.java | 9 ++---
.../segment/dml/order/item/OrderByItemSegment.java | 3 +-
.../dml/order/item/TextOrderByItemSegment.java | 5 ++-
.../asserts/segment/orderby/OrderByItemAssert.java | 2 +-
35 files changed, 289 insertions(+), 215 deletions(-)
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
index 1e3452cd472..6c5ad05a174 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
@@ -69,7 +70,7 @@ public final class EncryptOrderByItemTokenGeneratorTest {
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("certificate_number"));
columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
- ColumnOrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC);
+ ColumnOrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderDirection.FIRST);
OrderByItem orderByItem = new OrderByItem(columnOrderByItemSegment);
when(result.getOrderByContext().getItems()).thenReturn(Collections.singletonList(orderByItem));
when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList());
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
index 0d9fb296e00..0442e520ca4 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
@@ -37,9 +37,14 @@ import org.apache.shardingsphere.sharding.merge.dql.orderby.OrderByStreamMergedR
import org.apache.shardingsphere.sharding.merge.dql.pagination.LimitDecoratorMergedResult;
import org.apache.shardingsphere.sharding.merge.dql.pagination.RowNumberDecoratorMergedResult;
import org.apache.shardingsphere.sharding.merge.dql.pagination.TopAndRowNumberDecoratorMergedResult;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
import java.sql.SQLException;
import java.util.List;
@@ -107,12 +112,17 @@ public final class ShardingDQLResultMerger implements ResultMerger {
private void setGroupByForDistinctRow(final SelectStatementContext selectStatementContext) {
for (int index = 1; index <= selectStatementContext.getProjectionsContext().getExpandProjections().size(); index++) {
- OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(-1, -1, index, OrderDirection.ASC, OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(-1, -1, index, OrderDirection.ASC, createDefaultNullsOrderDirection(selectStatementContext.getSqlStatement())));
orderByItem.setIndex(index);
selectStatementContext.getGroupByContext().getItems().add(orderByItem);
}
}
+ private NullsOrderDirection createDefaultNullsOrderDirection(final SelectStatement selectStatement) {
+ return selectStatement instanceof PostgreSQLStatement || selectStatement instanceof OpenGaussStatement || selectStatement instanceof OracleStatement ? NullsOrderDirection.LAST
+ : NullsOrderDirection.FIRST;
+ }
+
private MergedResult getGroupByMergedResult(final List<QueryResult> queryResults, final SelectStatementContext selectStatementContext,
final Map<String, Integer> columnLabelIndexMap, final ShardingSphereSchema schema) throws SQLException {
return selectStatementContext.isSameGroupByAndOrderByItems()
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
index 0899f59d9f4..a324906d338 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparator.java
@@ -54,7 +54,7 @@ public final class GroupByRowComparator implements Comparator<MemoryQueryResultR
Object orderValue2 = o2.getCell(each.getIndex());
Preconditions.checkState(null == orderValue2 || orderValue2 instanceof Comparable, "Order by value must implements Comparable");
int result = CompareUtil.compareTo((Comparable) orderValue1, (Comparable) orderValue2, each.getSegment().getOrderDirection(),
- each.getSegment().getNullOrderDirection(), valueCaseSensitive.get(each.getIndex()));
+ each.getSegment().getNullsOrderDirection(), valueCaseSensitive.get(each.getIndex()));
if (0 != result) {
return result;
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
index a697ca82c9b..636155317e5 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sharding.merge.dql.orderby;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
/**
@@ -33,20 +34,21 @@ public final class CompareUtil {
* @param thisValue this value
* @param otherValue other value
* @param orderDirection order direction
- * @param nullOrderDirection order direction for null value
+ * @param nullsOrderDirection order direction for nulls value
* @param caseSensitive case sensitive
* @return compare result
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final OrderDirection nullOrderDirection, final boolean caseSensitive) {
+ public static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection,
+ final boolean caseSensitive) {
if (null == thisValue && null == otherValue) {
return 0;
}
if (null == thisValue) {
- return orderDirection == nullOrderDirection ? -1 : 1;
+ return NullsOrderDirection.FIRST.equals(nullsOrderDirection) ? -1 : 1;
}
if (null == otherValue) {
- return orderDirection == nullOrderDirection ? 1 : -1;
+ return NullsOrderDirection.FIRST.equals(nullsOrderDirection) ? 1 : -1;
}
if (!caseSensitive && thisValue instanceof String && otherValue instanceof String) {
return compareToCaseInsensitiveString((String) thisValue, (String) otherValue, orderDirection);
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
index d0bbb5f9659..5e7a83e6095 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValue.java
@@ -68,8 +68,8 @@ public final class OrderByValue implements Comparable<OrderByValue> {
private boolean getOrderValuesCaseSensitiveFromTables(final SelectStatementContext selectStatementContext,
final ShardingSphereSchema schema, final OrderByItem eachOrderByItem) throws SQLException {
- for (SimpleTableSegment eachSimpleTableSegment : selectStatementContext.getAllTables()) {
- String tableName = eachSimpleTableSegment.getTableName().getIdentifier().getValue();
+ for (SimpleTableSegment each : selectStatementContext.getAllTables()) {
+ String tableName = each.getTableName().getIdentifier().getValue();
ShardingSphereTable table = schema.getTable(tableName);
Map<String, ShardingSphereColumn> columns = table.getColumns();
OrderByItemSegment orderByItemSegment = eachOrderByItem.getSegment();
@@ -114,11 +114,11 @@ public final class OrderByValue implements Comparable<OrderByValue> {
}
@Override
- public int compareTo(final OrderByValue o) {
+ public int compareTo(final OrderByValue orderByValue) {
int i = 0;
for (OrderByItem each : orderByItems) {
- int result = CompareUtil.compareTo(orderValues.get(i), o.orderValues.get(i), each.getSegment().getOrderDirection(),
- each.getSegment().getNullOrderDirection(), orderValuesCaseSensitive.get(i));
+ int result = CompareUtil.compareTo(orderValues.get(i), orderByValue.orderValues.get(i), each.getSegment().getOrderDirection(),
+ each.getSegment().getNullsOrderDirection(), orderValuesCaseSensitive.get(i));
if (0 != result) {
return result;
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
index 32c1b8f9a71..4f69ca08a7e 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
@@ -19,6 +19,16 @@ package org.apache.shardingsphere.sharding.rewrite.token.generator.impl;
import com.google.common.base.Preconditions;
import lombok.Setter;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationProjection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.RouteContextAware;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -26,16 +36,12 @@ import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rewrite.token.generator.IgnoreForSingleRoute;
import org.apache.shardingsphere.sharding.rewrite.token.pojo.ProjectionsToken;
-import org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
-import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
-import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationProjection;
-import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
+import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import java.util.Collection;
@@ -83,7 +89,7 @@ public final class ProjectionsTokenGenerator implements OptionalSQLTokenGenerato
} else if (each instanceof DerivedProjection && ((DerivedProjection) each).getDerivedProjection() instanceof ColumnOrderByItemSegment) {
TableExtractor tableExtractor = new TableExtractor();
tableExtractor.extractTablesFromSelect(selectStatementContext.getSqlStatement());
- result.add(getDerivedProjectionTextFromColumnOrderByItemSegment((DerivedProjection) each, tableExtractor, routeUnit));
+ result.add(getDerivedProjectionTextFromColumnOrderByItemSegment((DerivedProjection) each, tableExtractor, routeUnit, selectStatementContext.getDatabaseType()));
} else if (each instanceof DerivedProjection) {
result.add(getDerivedProjectionText(each));
}
@@ -99,11 +105,12 @@ public final class ProjectionsTokenGenerator implements OptionalSQLTokenGenerato
return projection.getExpression() + " AS " + projection.getAlias().get() + " ";
}
- private String getDerivedProjectionTextFromColumnOrderByItemSegment(final DerivedProjection projection, final TableExtractor tableExtractor, final RouteUnit routeUnit) {
+ private String getDerivedProjectionTextFromColumnOrderByItemSegment(final DerivedProjection projection, final TableExtractor tableExtractor, final RouteUnit routeUnit,
+ final DatabaseType databaseType) {
Preconditions.checkState(projection.getAlias().isPresent());
Preconditions.checkState(projection.getDerivedProjection() instanceof ColumnOrderByItemSegment);
ColumnOrderByItemSegment columnOrderByItemSegment = (ColumnOrderByItemSegment) projection.getDerivedProjection();
- ColumnOrderByItemSegment newColumnOrderByItem = generateNewColumnOrderByItem(columnOrderByItemSegment, routeUnit, tableExtractor);
+ ColumnOrderByItemSegment newColumnOrderByItem = generateNewColumnOrderByItem(columnOrderByItemSegment, routeUnit, tableExtractor, databaseType);
return newColumnOrderByItem.getText() + " AS " + projection.getAlias().get() + " ";
}
@@ -116,7 +123,7 @@ public final class ProjectionsTokenGenerator implements OptionalSQLTokenGenerato
return Optional.empty();
}
- private ColumnOrderByItemSegment generateNewColumnOrderByItem(final ColumnOrderByItemSegment old, final RouteUnit routeUnit, final TableExtractor tableExtractor) {
+ private ColumnOrderByItemSegment generateNewColumnOrderByItem(final ColumnOrderByItemSegment old, final RouteUnit routeUnit, final TableExtractor tableExtractor, final DatabaseType databaseType) {
Optional<OwnerSegment> ownerSegment = old.getColumn().getOwner();
if (!ownerSegment.isPresent()) {
return old;
@@ -130,6 +137,13 @@ public final class ProjectionsTokenGenerator implements OptionalSQLTokenGenerato
IdentifierValue newOwnerIdentifier = new IdentifierValue(ownerSegment.get().getIdentifier().getQuoteCharacter().wrap(actualTableName.get()));
OwnerSegment newOwner = new OwnerSegment(0, 0, newOwnerIdentifier);
newColumnSegment.setOwner(newOwner);
- return new ColumnOrderByItemSegment(newColumnSegment, old.getOrderDirection());
+ return new ColumnOrderByItemSegment(newColumnSegment, old.getOrderDirection(), generateNewNullsOrderDirection(databaseType, old.getOrderDirection()));
+ }
+
+ private NullsOrderDirection generateNewNullsOrderDirection(final DatabaseType databaseType, final OrderDirection orderDirection) {
+ if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType || databaseType instanceof OracleDatabaseType) {
+ return OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
+ }
+ return OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.FIRST : NullsOrderDirection.LAST;
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
index f38d56601e0..55427e4d096 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
@@ -40,6 +40,7 @@ import org.apache.shardingsphere.sharding.merge.dql.pagination.LimitDecoratorMer
import org.apache.shardingsphere.sharding.merge.dql.pagination.RowNumberDecoratorMergedResult;
import org.apache.shardingsphere.sharding.merge.dql.pagination.TopAndRowNumberDecoratorMergedResult;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
@@ -168,7 +169,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -181,7 +182,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -212,7 +213,7 @@ public final class ShardingDQLResultMergerTest {
when(subquerySegment.getSelect()).thenReturn(subSelectStatement);
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement());
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
@@ -229,7 +230,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -245,8 +246,8 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -259,8 +260,8 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -291,8 +292,8 @@ public final class ShardingDQLResultMergerTest {
when(subquerySegment.getSelect()).thenReturn(subSelectStatement);
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
@@ -309,8 +310,8 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -326,7 +327,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -339,7 +340,7 @@ public final class ShardingDQLResultMergerTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -370,8 +371,8 @@ public final class ShardingDQLResultMergerTest {
when(subquerySegment.getSelect()).thenReturn(subSelectStatement);
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement());
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
@@ -389,8 +390,8 @@ public final class ShardingDQLResultMergerTest {
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
index 2d9226f8376..b50f7b1644c 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -121,8 +122,8 @@ public final class GroupByMemoryMergedResultTest {
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.AVG, "(num)"));
selectStatement.setProjections(projectionsSegment);
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
@@ -135,7 +136,7 @@ public final class GroupByMemoryMergedResultTest {
projectionsSegment.setDistinctRow(true);
projectionsSegment.getProjections().add(new ShorthandProjectionSegment(0, 0));
selectStatement.setProjections(projectionsSegment);
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
selectStatement.setProjections(projectionsSegment);
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
index 60b028e6bc8..679eab226d6 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment;
@@ -86,11 +87,11 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -129,11 +130,11 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -172,11 +173,11 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
@@ -215,8 +216,8 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -256,8 +257,8 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
@@ -301,8 +302,8 @@ public final class GroupByRowComparatorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
index f910848d67d..98d823ac419 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
@@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -170,8 +171,8 @@ public final class GroupByStreamMergedResultTest {
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.AVG, "(num)"));
selectStatement.setProjections(projectionsSegment);
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, NullsOrderDirection.FIRST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, NullsOrderDirection.FIRST))));
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByValueTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByValueTest.java
index 551b9131640..0ada960130c 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByValueTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByValueTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sharding.merge.dql.groupby;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
import org.junit.Before;
@@ -51,8 +52,8 @@ public final class GroupByValueTest {
@Test
public void assertGetGroupByValues() throws SQLException {
List<?> actual = new GroupByValue(queryResult, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC)))).getGroupValues();
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST)))).getGroupValues();
List<?> expected = Arrays.asList("1", "3");
assertThat(actual, is(expected));
}
@@ -60,11 +61,11 @@ public final class GroupByValueTest {
@Test
public void assertGroupByValueEquals() throws SQLException {
GroupByValue groupByValue1 = new GroupByValue(queryResult, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST))));
GroupByValue groupByValue2 = new GroupByValue(queryResult, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST))));
assertThat(groupByValue1, is(groupByValue2));
assertThat(groupByValue2, is(groupByValue1));
assertThat(groupByValue1.hashCode(), is(groupByValue2.hashCode()));
@@ -73,11 +74,11 @@ public final class GroupByValueTest {
@Test
public void assertGroupByValueNotEquals() throws SQLException {
GroupByValue groupByValue1 = new GroupByValue(queryResult, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderDirection.FIRST))));
GroupByValue groupByValue2 = new GroupByValue(queryResult, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST))));
assertThat(groupByValue1, not(groupByValue2));
assertThat(groupByValue1.hashCode(), not(groupByValue2.hashCode()));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtilTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtilTest.java
index 5feb7108fd3..d2a28293592 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtilTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtilTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.merge.dql.orderby;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.junit.Test;
@@ -29,66 +30,66 @@ public final class CompareUtilTest {
@Test
public void assertCompareToWhenBothNull() {
- assertThat(CompareUtil.compareTo(null, null, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(0));
+ assertThat(CompareUtil.compareTo(null, null, OrderDirection.DESC, NullsOrderDirection.FIRST, caseSensitive), is(0));
}
@Test
- public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullOrderByAsc() {
- assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(-1));
+ public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullsFirst() {
+ assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, NullsOrderDirection.FIRST, caseSensitive), is(-1));
}
@Test
- public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullOrderByDesc() {
- assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, OrderDirection.DESC, caseSensitive), is(1));
+ public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullsLast() {
+ assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, NullsOrderDirection.LAST, caseSensitive), is(1));
}
@Test
- public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullOrderByAsc() {
- assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(1));
+ public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullsFirst() {
+ assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, NullsOrderDirection.FIRST, caseSensitive), is(-1));
}
@Test
- public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullOrderByDesc() {
- assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, OrderDirection.DESC, caseSensitive), is(-1));
+ public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullsLast() {
+ assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, NullsOrderDirection.LAST, caseSensitive), is(1));
}
@Test
- public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullOrderByAsc() {
- assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(1));
+ public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullsFirst() {
+ assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, NullsOrderDirection.FIRST, caseSensitive), is(1));
}
@Test
- public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullOrderByDesc() {
- assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, OrderDirection.DESC, caseSensitive), is(-1));
+ public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullsLast() {
+ assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, NullsOrderDirection.LAST, caseSensitive), is(-1));
}
@Test
- public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullOrderByAsc() {
- assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(-1));
+ public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullsFirst() {
+ assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, NullsOrderDirection.FIRST, caseSensitive), is(1));
}
@Test
- public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullOrderByDesc() {
- assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, OrderDirection.DESC, caseSensitive), is(1));
+ public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullsLast() {
+ assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, NullsOrderDirection.LAST, caseSensitive), is(-1));
}
@Test
public void assertCompareToWhenAsc() {
- assertThat(CompareUtil.compareTo(1, 2, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(-1));
+ assertThat(CompareUtil.compareTo(1, 2, OrderDirection.ASC, NullsOrderDirection.FIRST, caseSensitive), is(-1));
}
@Test
public void assertCompareToWhenDesc() {
- assertThat(CompareUtil.compareTo(1, 2, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(1));
+ assertThat(CompareUtil.compareTo(1, 2, OrderDirection.DESC, NullsOrderDirection.FIRST, caseSensitive), is(1));
}
@Test
public void assetCompareToStringWithCaseSensitive() {
- assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(32));
+ assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, NullsOrderDirection.FIRST, caseSensitive), is(32));
}
@Test
public void assetCompareToStringWithCaseInsensitive() {
- assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, OrderDirection.ASC, !caseSensitive), is(0));
+ assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, NullsOrderDirection.FIRST, !caseSensitive), is(0));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
index 7fc3db287a9..8d6ad8bd164 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
@@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.OrderBySegment;
@@ -69,8 +70,8 @@ public final class OrderByStreamMergedResultTest {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
selectStatement.setOrderBy(new OrderBySegment(0, 0, Arrays.asList(
- new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
- new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
+ new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST),
+ new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatementContext = new SelectStatementContext(
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
index bcb73a77535..71343ecc7ab 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -93,16 +94,16 @@ public final class OrderByValueTest {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
QueryResult queryResult1 = createQueryResult("1", "2");
OrderByValue orderByValue1 = new OrderByValue(queryResult1, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
MemberAccessor accessor = Plugins.getMemberAccessor();
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("3", "4");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
@@ -151,16 +152,16 @@ public final class OrderByValueTest {
when(schema.getTable("table")).thenReturn(new ShardingSphereTable());
QueryResult queryResult1 = createQueryResult("1", "2");
OrderByValue orderByValue1 = new OrderByValue(queryResult1, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
MemberAccessor accessor = Plugins.getMemberAccessor();
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("3", "4");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
@@ -204,16 +205,16 @@ public final class OrderByValueTest {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
QueryResult queryResult1 = createQueryResult("1", "2");
OrderByValue orderByValue1 = new OrderByValue(queryResult1, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
MemberAccessor accessor = Plugins.getMemberAccessor();
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("1", "2");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
- createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST)),
+ createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderDirection.FIRST))),
selectStatementContext, schema);
accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
@@ -238,7 +239,7 @@ public final class OrderByValueTest {
}
private OrderBySegment createOrderBySegment() {
- OrderByItemSegment orderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("id")), OrderDirection.ASC, OrderDirection.ASC);
+ OrderByItemSegment orderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("id")), OrderDirection.ASC, NullsOrderDirection.FIRST);
return new OrderBySegment(0, 0, Collections.singletonList(orderByItemSegment));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
index 0def1bbeaf7..7a093152418 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.ShardingRemoveTokenGenerator;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -81,7 +82,7 @@ public final class ShardingRemoveTokenGeneratorTest {
private SelectStatementContext createUpdatesStatementContext() {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user"))));
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.FIRST))));
selectStatement.setProjections(createProjectionsSegment());
return new SelectStatementContext(
createShardingSphereMetaData(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
index ace7b9a6cbc..642d4f087d0 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.binder.segment.select.orderby.engine;
import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
@@ -27,6 +28,9 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.Co
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.OrderByItemSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
import java.util.LinkedList;
import java.util.List;
@@ -66,7 +70,8 @@ public final class OrderByContextEngine {
for (ProjectionSegment projectionSegment : selectStatement.getProjections().getProjections()) {
if (projectionSegment instanceof ColumnProjectionSegment) {
ColumnProjectionSegment columnProjectionSegment = (ColumnProjectionSegment) projectionSegment;
- ColumnOrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(columnProjectionSegment.getColumn(), OrderDirection.ASC);
+ ColumnOrderByItemSegment columnOrderByItemSegment =
+ new ColumnOrderByItemSegment(columnProjectionSegment.getColumn(), OrderDirection.ASC, createDefaultNullsOrderDirection(selectStatement));
OrderByItem item = new OrderByItem(columnOrderByItemSegment);
item.setIndex(index++);
orderByItems.add(item);
@@ -78,4 +83,9 @@ public final class OrderByContextEngine {
}
return null;
}
+
+ private NullsOrderDirection createDefaultNullsOrderDirection(final SelectStatement selectStatement) {
+ return selectStatement instanceof PostgreSQLStatement || selectStatement instanceof OpenGaussStatement || selectStatement instanceof OracleStatement ? NullsOrderDirection.LAST
+ : NullsOrderDirection.FIRST;
+ }
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/groupby/engine/GroupByContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/groupby/engine/GroupByContextEngineTest.java
index c50b528743e..95dd41ff875 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/groupby/engine/GroupByContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/groupby/engine/GroupByContextEngineTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.binder.segment.select.groupby.engine;
import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment;
@@ -98,9 +99,9 @@ public final class GroupByContextEngineTest {
}
private void assertCreateGroupByContextWithGroupBy(final SelectStatement selectStatement) {
- OrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 1, new IdentifierValue("column1")), OrderDirection.ASC);
- OrderByItemSegment indexOrderByItemSegment1 = new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, OrderDirection.DESC);
- OrderByItemSegment indexOrderByItemSegment2 = new IndexOrderByItemSegment(2, 3, 3, OrderDirection.ASC, OrderDirection.DESC);
+ OrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 1, new IdentifierValue("column1")), OrderDirection.ASC, NullsOrderDirection.LAST);
+ OrderByItemSegment indexOrderByItemSegment1 = new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, NullsOrderDirection.LAST);
+ OrderByItemSegment indexOrderByItemSegment2 = new IndexOrderByItemSegment(2, 3, 3, OrderDirection.ASC, NullsOrderDirection.LAST);
GroupBySegment groupBySegment = new GroupBySegment(0, 10, Arrays.asList(columnOrderByItemSegment, indexOrderByItemSegment1, indexOrderByItemSegment2));
selectStatement.setGroupBy(groupBySegment);
GroupByContext actualGroupByContext = new GroupByContextEngine().createGroupByContext(selectStatement);
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngineTest.java
index 40f09133675..06e8691fa79 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngineTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.binder.segment.select.orderby.engine;
import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
@@ -44,8 +45,8 @@ import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class OrderByContextEngineTest {
@@ -76,8 +77,8 @@ public final class OrderByContextEngineTest {
}
private void assertCreateOrderByWithoutOrderBy(final SelectStatement selectStatement) {
- OrderByItem orderByItem1 = new OrderByItem(new IndexOrderByItemSegment(0, 1, 1, OrderDirection.ASC, OrderDirection.DESC));
- OrderByItem orderByItem2 = new OrderByItem(new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, OrderDirection.DESC));
+ OrderByItem orderByItem1 = new OrderByItem(new IndexOrderByItemSegment(0, 1, 1, OrderDirection.ASC, NullsOrderDirection.LAST));
+ OrderByItem orderByItem2 = new OrderByItem(new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, NullsOrderDirection.LAST));
Collection<OrderByItem> orderByItems = Arrays.asList(orderByItem1, orderByItem2);
GroupByContext groupByContext = new GroupByContext(orderByItems);
OrderByContext actualOrderByContext = new OrderByContextEngine().createOrderBy(selectStatement, groupByContext);
@@ -111,9 +112,9 @@ public final class OrderByContextEngineTest {
}
private void assertCreateOrderByWithOrderBy(final SelectStatement selectStatement) {
- OrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 1, new IdentifierValue("column1")), OrderDirection.ASC);
- OrderByItemSegment indexOrderByItemSegment1 = new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, OrderDirection.DESC);
- OrderByItemSegment indexOrderByItemSegment2 = new IndexOrderByItemSegment(2, 3, 3, OrderDirection.ASC, OrderDirection.DESC);
+ OrderByItemSegment columnOrderByItemSegment = new ColumnOrderByItemSegment(new ColumnSegment(0, 1, new IdentifierValue("column1")), OrderDirection.ASC, NullsOrderDirection.FIRST);
+ OrderByItemSegment indexOrderByItemSegment1 = new IndexOrderByItemSegment(1, 2, 2, OrderDirection.ASC, NullsOrderDirection.LAST);
+ OrderByItemSegment indexOrderByItemSegment2 = new IndexOrderByItemSegment(2, 3, 3, OrderDirection.ASC, NullsOrderDirection.LAST);
OrderBySegment orderBySegment = new OrderBySegment(0, 1, Arrays.asList(columnOrderByItemSegment, indexOrderByItemSegment1, indexOrderByItemSegment2));
selectStatement.setOrderBy(orderBySegment);
GroupByContext emptyGroupByContext = new GroupByContext(Collections.emptyList());
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
index 6e5a97535e3..0194230cde8 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment;
@@ -197,8 +198,8 @@ public final class PaginationContextTest {
private void getRevisedRowCountWithMax(final SelectStatement selectStatement) {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.DESC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.LAST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.LAST))));
Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
index b1bc5133106..b17520c99e3 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
@@ -177,7 +178,7 @@ public final class ProjectionsContextEngineTest {
OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name"));
shorthandProjectionSegment.setOwner(owner);
projectionsSegment.getProjections().add(shorthandProjectionSegment);
- OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(0, 1, 0, OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(0, 1, 0, OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singletonList(orderByItem), true);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -217,7 +218,7 @@ public final class ProjectionsContextEngineTest {
OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name"));
shorthandProjectionSegment.setOwner(owner);
projectionsSegment.getProjections().add(shorthandProjectionSegment);
- OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 1, "", OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 1, "", OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singletonList(orderByItem), true);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -273,7 +274,7 @@ public final class ProjectionsContextEngineTest {
OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name"));
shorthandProjectionSegment.setOwner(owner);
projectionsSegment.getProjections().add(shorthandProjectionSegment);
- OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singletonList(orderByItem), true);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -314,7 +315,7 @@ public final class ProjectionsContextEngineTest {
OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name"));
shorthandProjectionSegment.setOwner(owner);
projectionsSegment.getProjections().add(shorthandProjectionSegment);
- OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singletonList(orderByItem), true);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -363,7 +364,7 @@ public final class ProjectionsContextEngineTest {
ColumnProjectionSegment columnProjectionSegment = new ColumnProjectionSegment(columnSegment);
columnProjectionSegment.getColumn().setOwner(owner);
projectionsSegment.getProjections().addAll(Arrays.asList(columnProjectionSegment, shorthandProjectionSegment));
- OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singleton(orderByItem), false);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -408,7 +409,7 @@ public final class ProjectionsContextEngineTest {
selectStatement.setFrom(subqueryTableSegment);
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name"));
columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("d")));
- OrderByItem groupByItem = new OrderByItem(new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC));
+ OrderByItem groupByItem = new OrderByItem(new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderDirection.FIRST));
GroupByContext groupByContext = new GroupByContext(Collections.singleton(groupByItem));
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -453,7 +454,7 @@ public final class ProjectionsContextEngineTest {
selectStatement.setFrom(subqueryTableSegment);
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name"));
columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("TAble")));
- OrderByItem groupByItem = new OrderByItem(new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC));
+ OrderByItem groupByItem = new OrderByItem(new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderDirection.FIRST));
GroupByContext groupByContext = new GroupByContext(Collections.singleton(groupByItem));
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
@@ -468,7 +469,7 @@ public final class ProjectionsContextEngineTest {
projectionsSegment.getProjections().add(new ShorthandProjectionSegment(0, 0));
selectStatement.setProjections(projectionsSegment);
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
- OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 0, "id + 1", OrderDirection.ASC));
+ OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 0, "id + 1", OrderDirection.ASC, NullsOrderDirection.FIRST));
OrderByContext orderByContext = new OrderByContext(Collections.singleton(orderByItem), false);
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
ProjectionsContextEngine engine = new ProjectionsContextEngine(DefaultDatabase.LOGIC_NAME, mockSchemas(), selectStatementContext.getDatabaseType());
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
index 0c0d8065e54..61ed7cbd8d0 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -246,8 +247,8 @@ public final class SelectStatementContextTest {
private void assertIsSameGroupByAndOrderByItems(final SelectStatement selectStatement) {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.LAST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.LAST))));
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
assertTrue(selectStatementContext.isSameGroupByAndOrderByItems());
}
@@ -316,8 +317,8 @@ public final class SelectStatementContextTest {
private void assertIsNotSameGroupByAndOrderByItemsWhenDifferentGroupByAndOrderBy(final SelectStatement selectStatement) {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.DESC))));
- selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
+ selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderDirection.LAST))));
+ selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderDirection.LAST))));
SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement);
assertFalse(selectStatementContext.isSameGroupByAndOrderByItems());
}
@@ -573,15 +574,15 @@ public final class SelectStatementContextTest {
private OrderByItemSegment createOrderByItemSegment(final String type) {
switch (type) {
case INDEX_ORDER_BY:
- return new IndexOrderByItemSegment(0, 0, 4, OrderDirection.ASC, OrderDirection.ASC);
+ return new IndexOrderByItemSegment(0, 0, 4, OrderDirection.ASC, NullsOrderDirection.FIRST);
case COLUMN_ORDER_BY_WITH_OWNER:
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name"));
columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("table")));
- return new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderDirection.FIRST);
case COLUMN_ORDER_BY_WITH_ALIAS:
- return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("n")), OrderDirection.ASC, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("n")), OrderDirection.ASC, NullsOrderDirection.FIRST);
default:
- return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("id")), OrderDirection.ASC, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("id")), OrderDirection.ASC, NullsOrderDirection.FIRST);
}
}
diff --git a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index 48080bda734..e1514e992c2 100644
--- a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -138,6 +138,7 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WindowF
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.CombineType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -1075,16 +1076,17 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
} else {
orderDirection = OrderDirection.ASC;
}
+ NullsOrderDirection nullsOrderDirection = OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.FIRST : NullsOrderDirection.LAST;
if (null != ctx.numberLiterals()) {
return new IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(), ctx.numberLiterals().getStop().getStopIndex(),
- SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection);
+ SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection, nullsOrderDirection);
} else {
ASTNode expr = visitExpr(ctx.expr());
if (expr instanceof ColumnSegment) {
- return new ColumnOrderByItemSegment((ColumnSegment) expr, orderDirection);
+ return new ColumnOrderByItemSegment((ColumnSegment) expr, orderDirection, nullsOrderDirection);
} else {
return new ExpressionOrderByItemSegment(ctx.expr().getStart().getStartIndex(),
- ctx.expr().getStop().getStopIndex(), getOriginalText(ctx.expr()), orderDirection, (ExpressionSegment) expr);
+ ctx.expr().getStop().getStopIndex(), getOriginalText(ctx.expr()), orderDirection, nullsOrderDirection, (ExpressionSegment) expr);
}
}
}
diff --git a/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java b/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
index ef50c68c2ca..b9ad9cb4b66 100644
--- a/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
+++ b/sql-parser/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
@@ -70,6 +70,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Joi
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.LimitClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NameListContext;
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NaturalJoinTypeContext;
+import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NullsOrderContext;
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NumberLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.OptOnDuplicateKeyContext;
import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.OuterJoinTypeContext;
@@ -107,6 +108,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Win
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.CombineType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -579,20 +581,28 @@ public abstract class OpenGaussStatementSQLVisitor extends OpenGaussStatementBas
@Override
public final ASTNode visitSortby(final SortbyContext ctx) {
OrderDirection orderDirection = null != ctx.ascDesc() ? generateOrderDirection(ctx.ascDesc()) : OrderDirection.ASC;
+ NullsOrderDirection nullsOrderDirection = generateNullsOrderDirection(ctx.nullsOrder(), orderDirection);
ASTNode expr = visit(ctx.aExpr());
if (expr instanceof ColumnSegment) {
ColumnSegment column = (ColumnSegment) expr;
- return new ColumnOrderByItemSegment(column, orderDirection);
+ return new ColumnOrderByItemSegment(column, orderDirection, nullsOrderDirection);
}
if (expr instanceof LiteralExpressionSegment) {
LiteralExpressionSegment index = (LiteralExpressionSegment) expr;
- return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(), Integer.parseInt(index.getLiterals().toString()), orderDirection);
+ return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(), Integer.parseInt(index.getLiterals().toString()), orderDirection, nullsOrderDirection);
}
if (expr instanceof ExpressionSegment) {
return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(),
- ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, (ExpressionSegment) expr);
+ ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, nullsOrderDirection, (ExpressionSegment) expr);
}
- return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(), ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection);
+ return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(), ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, nullsOrderDirection);
+ }
+
+ private NullsOrderDirection generateNullsOrderDirection(final NullsOrderContext ctx, final OrderDirection orderDirection) {
+ if (null == ctx) {
+ return OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
+ }
+ return null == ctx.FIRST() ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
}
private OrderDirection generateOrderDirection(final AscDescContext ctx) {
@@ -984,16 +994,16 @@ public abstract class OpenGaussStatementSQLVisitor extends OpenGaussStatementBas
if (null != ctx.aExpr()) {
ASTNode astNode = visit(ctx.aExpr());
if (astNode instanceof ColumnSegment) {
- return new ColumnOrderByItemSegment((ColumnSegment) astNode, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment((ColumnSegment) astNode, OrderDirection.ASC, NullsOrderDirection.LAST);
}
if (astNode instanceof LiteralExpressionSegment) {
LiteralExpressionSegment index = (LiteralExpressionSegment) astNode;
return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(),
- Integer.parseInt(index.getLiterals().toString()), OrderDirection.ASC);
+ Integer.parseInt(index.getLiterals().toString()), OrderDirection.ASC, NullsOrderDirection.LAST);
}
- return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC);
+ return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, NullsOrderDirection.LAST);
}
- return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC);
+ return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, NullsOrderDirection.LAST);
}
@Override
diff --git a/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java b/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
index 13ea408e76f..5615d41a859 100644
--- a/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
+++ b/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java
@@ -104,6 +104,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.UsingC
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.WhereClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.WithClauseContext;
import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -961,14 +962,15 @@ public final class OracleDMLStatementSQLVisitor extends OracleStatementSQLVisito
ASTNode expression = visit(ctx);
if (expression instanceof ColumnSegment) {
ColumnSegment column = (ColumnSegment) expression;
- return new ColumnOrderByItemSegment(column, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment(column, OrderDirection.ASC, NullsOrderDirection.LAST);
}
if (expression instanceof LiteralExpressionSegment) {
LiteralExpressionSegment literalExpression = (LiteralExpressionSegment) expression;
return new IndexOrderByItemSegment(literalExpression.getStartIndex(), literalExpression.getStopIndex(),
- SQLUtil.getExactlyNumber(literalExpression.getLiterals().toString(), 10).intValue(), OrderDirection.ASC);
+ SQLUtil.getExactlyNumber(literalExpression.getLiterals().toString(), 10).intValue(), OrderDirection.ASC, NullsOrderDirection.LAST);
}
- return new ExpressionOrderByItemSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, (ExpressionSegment) expression);
+ return new ExpressionOrderByItemSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, NullsOrderDirection.LAST,
+ (ExpressionSegment) expression);
}
private Collection<OrderByItemSegment> generateOrderByItemSegmentsFromRollupCubeClause(final RollupCubeClauseContext ctx) {
diff --git a/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java b/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
index 78bef8cf763..79cec2e3f66 100644
--- a/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
+++ b/sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
@@ -40,6 +40,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.Constr
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeLengthContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeNameContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DatetimeExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FunctionCallContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FunctionContext;
@@ -67,10 +68,10 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableN
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.UnreservedWordContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ViewNameContext;
-import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DatetimeExprContext;
-import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlAggFunctionContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlFunctionContext;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -82,12 +83,12 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.type.TypeSegm
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.DatetimeExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.NotExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.DatetimeExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
@@ -636,16 +637,24 @@ public abstract class OracleStatementSQLVisitor extends OracleStatementBaseVisit
@Override
public final ASTNode visitOrderByItem(final OrderByItemContext ctx) {
OrderDirection orderDirection = null != ctx.DESC() ? OrderDirection.DESC : OrderDirection.ASC;
+ NullsOrderDirection nullsOrderDirection = generateNullsOrderDirection(ctx, orderDirection);
if (null != ctx.columnName()) {
ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
- return new ColumnOrderByItemSegment(column, orderDirection);
+ return new ColumnOrderByItemSegment(column, orderDirection, nullsOrderDirection);
}
if (null != ctx.numberLiterals()) {
return new IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(), ctx.numberLiterals().getStop().getStopIndex(),
- SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection);
+ SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection, nullsOrderDirection);
}
return new ExpressionOrderByItemSegment(ctx.expr().getStart().getStartIndex(), ctx.expr().getStop().getStopIndex(),
- getOriginalText(ctx.expr()), orderDirection, (ExpressionSegment) visit(ctx.expr()));
+ getOriginalText(ctx.expr()), orderDirection, nullsOrderDirection, (ExpressionSegment) visit(ctx.expr()));
+ }
+
+ private NullsOrderDirection generateNullsOrderDirection(final OrderByItemContext ctx, final OrderDirection orderDirection) {
+ if (null == ctx) {
+ return OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
+ }
+ return null == ctx.FIRST() ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
}
@Override
diff --git a/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java b/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 03cdfaab3fb..04290c06c6f 100644
--- a/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ b/sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -69,6 +69,7 @@ import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Li
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameListContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NaturalJoinTypeContext;
+import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NullsOrderContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NumberLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OptOnConflictContext;
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OuterJoinTypeContext;
@@ -107,6 +108,7 @@ import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParserBas
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.CombineType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -576,20 +578,28 @@ public abstract class PostgreSQLStatementSQLVisitor extends PostgreSQLStatementP
@Override
public final ASTNode visitSortby(final SortbyContext ctx) {
OrderDirection orderDirection = null != ctx.ascDesc() ? generateOrderDirection(ctx.ascDesc()) : OrderDirection.ASC;
+ NullsOrderDirection nullsOrderDirection = generateNullsOrderDirection(ctx.nullsOrder(), orderDirection);
ASTNode expr = visit(ctx.aExpr());
if (expr instanceof ColumnSegment) {
ColumnSegment column = (ColumnSegment) expr;
- return new ColumnOrderByItemSegment(column, orderDirection);
+ return new ColumnOrderByItemSegment(column, orderDirection, nullsOrderDirection);
}
if (expr instanceof LiteralExpressionSegment) {
LiteralExpressionSegment index = (LiteralExpressionSegment) expr;
- return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(), Integer.parseInt(index.getLiterals().toString()), orderDirection);
+ return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(), Integer.parseInt(index.getLiterals().toString()), orderDirection, nullsOrderDirection);
}
if (expr instanceof ExpressionSegment) {
return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(),
- ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, (ExpressionSegment) expr);
+ ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, nullsOrderDirection, (ExpressionSegment) expr);
}
- return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(), ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection);
+ return new ExpressionOrderByItemSegment(ctx.aExpr().getStart().getStartIndex(), ctx.aExpr().getStop().getStopIndex(), getOriginalText(ctx.aExpr()), orderDirection, nullsOrderDirection);
+ }
+
+ private NullsOrderDirection generateNullsOrderDirection(final NullsOrderContext ctx, final OrderDirection orderDirection) {
+ if (null == ctx) {
+ return OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
+ }
+ return null == ctx.FIRST() ? NullsOrderDirection.LAST : NullsOrderDirection.FIRST;
}
private OrderDirection generateOrderDirection(final AscDescContext ctx) {
@@ -951,16 +961,16 @@ public abstract class PostgreSQLStatementSQLVisitor extends PostgreSQLStatementP
if (null != ctx.aExpr()) {
ASTNode astNode = visit(ctx.aExpr());
if (astNode instanceof ColumnSegment) {
- return new ColumnOrderByItemSegment((ColumnSegment) astNode, OrderDirection.ASC);
+ return new ColumnOrderByItemSegment((ColumnSegment) astNode, OrderDirection.ASC, NullsOrderDirection.LAST);
}
if (astNode instanceof LiteralExpressionSegment) {
LiteralExpressionSegment index = (LiteralExpressionSegment) astNode;
return new IndexOrderByItemSegment(index.getStartIndex(), index.getStopIndex(),
- Integer.parseInt(index.getLiterals().toString()), OrderDirection.ASC);
+ Integer.parseInt(index.getLiterals().toString()), OrderDirection.ASC, NullsOrderDirection.LAST);
}
- return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC);
+ return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, NullsOrderDirection.LAST);
}
- return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC);
+ return new ExpressionOrderByItemSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getOriginalText(ctx), OrderDirection.ASC, NullsOrderDirection.LAST);
}
@Override
diff --git a/sql-parser/dialect/sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java b/sql-parser/dialect/sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
index 98a799c07b5..7a66f7f3343 100644
--- a/sql-parser/dialect/sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
+++ b/sql-parser/dialect/sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
@@ -59,6 +59,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQL92StatementParser.TableNa
import org.apache.shardingsphere.sql.parser.autogen.SQL92StatementParser.TableNamesContext;
import org.apache.shardingsphere.sql.parser.autogen.SQL92StatementParser.UnreservedWordContext;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -534,12 +535,13 @@ public abstract class SQL92StatementSQLVisitor extends SQL92StatementBaseVisitor
@Override
public final ASTNode visitOrderByItem(final OrderByItemContext ctx) {
OrderDirection orderDirection = null != ctx.DESC() ? OrderDirection.DESC : OrderDirection.ASC;
+ NullsOrderDirection nullsOrderDirection = OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.FIRST : NullsOrderDirection.LAST;
if (null != ctx.columnName()) {
ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
- return new ColumnOrderByItemSegment(column, orderDirection);
+ return new ColumnOrderByItemSegment(column, orderDirection, nullsOrderDirection);
}
return new IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(), ctx.numberLiterals().getStop().getStopIndex(),
- SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection);
+ SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection, nullsOrderDirection);
}
@Override
diff --git a/sql-parser/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java b/sql-parser/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index 0d4568279b9..149c7c6583e 100644
--- a/sql-parser/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++ b/sql-parser/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -107,6 +107,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Whe
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WithClauseContext;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -653,16 +654,17 @@ public abstract class SQLServerStatementSQLVisitor extends SQLServerStatementBas
@Override
public final ASTNode visitOrderByItem(final OrderByItemContext ctx) {
OrderDirection orderDirection = null != ctx.DESC() ? OrderDirection.DESC : OrderDirection.ASC;
+ NullsOrderDirection nullsOrderDirection = OrderDirection.ASC.equals(orderDirection) ? NullsOrderDirection.FIRST : NullsOrderDirection.LAST;
if (null != ctx.columnName()) {
ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
- return new ColumnOrderByItemSegment(column, orderDirection);
+ return new ColumnOrderByItemSegment(column, orderDirection, nullsOrderDirection);
}
if (null != ctx.numberLiterals()) {
return new IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(), ctx.numberLiterals().getStop().getStopIndex(),
- SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection);
+ SQLUtil.getExactlyNumber(ctx.numberLiterals().getText(), 10).intValue(), orderDirection, NullsOrderDirection.FIRST);
}
return new ExpressionOrderByItemSegment(ctx.expr().getStart().getStartIndex(), ctx.expr().getStop().getStopIndex(), getOriginalText(ctx.expr()),
- orderDirection, (ExpressionSegment) visit(ctx.expr()));
+ orderDirection, nullsOrderDirection, (ExpressionSegment) visit(ctx.expr()));
}
@Override
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/NullsOrderDirection.java
similarity index 57%
copy from sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java
copy to sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/NullsOrderDirection.java
index df942bd14c6..372bc908df9 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/NullsOrderDirection.java
@@ -15,25 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
-
-import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
+package org.apache.shardingsphere.sql.parser.sql.common.constant;
/**
- * Order by item segment for text.
+ * Nulls order direction.
*/
-@ToString
-public abstract class TextOrderByItemSegment extends OrderByItemSegment {
+public enum NullsOrderDirection {
- protected TextOrderByItemSegment(final int startIndex, final int stopIndex, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
- super(startIndex, stopIndex, orderDirection, nullOrderDirection);
- }
+ /**
+ * Nulls first direction.
+ */
+ FIRST,
/**
- * Get text.
- *
- * @return text
+ * Nulls last direction.
*/
- public abstract String getText();
+ LAST
}
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ColumnOrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ColumnOrderByItemSegment.java
index 94199496c1d..8d05e424306 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ColumnOrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ColumnOrderByItemSegment.java
@@ -19,8 +19,9 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
import lombok.Getter;
import lombok.ToString;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
/**
* Order by item segment for column.
@@ -31,13 +32,8 @@ public final class ColumnOrderByItemSegment extends TextOrderByItemSegment {
private final ColumnSegment column;
- public ColumnOrderByItemSegment(final ColumnSegment column, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
- super(column.getStartIndex(), column.getStopIndex(), orderDirection, nullOrderDirection);
- this.column = column;
- }
-
- public ColumnOrderByItemSegment(final ColumnSegment column, final OrderDirection orderDirection) {
- super(column.getStartIndex(), column.getStopIndex(), orderDirection, OrderDirection.ASC);
+ public ColumnOrderByItemSegment(final ColumnSegment column, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection) {
+ super(column.getStartIndex(), column.getStopIndex(), orderDirection, nullsOrderDirection);
this.column = column;
}
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ExpressionOrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ExpressionOrderByItemSegment.java
index d0d144ce650..e1dd746ac7f 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ExpressionOrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/ExpressionOrderByItemSegment.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
import lombok.Getter;
import lombok.ToString;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
@@ -33,20 +34,15 @@ public final class ExpressionOrderByItemSegment extends TextOrderByItemSegment {
private final ExpressionSegment expr;
- public ExpressionOrderByItemSegment(final int startIndex, final int stopIndex, final String expression, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
- super(startIndex, stopIndex, orderDirection, nullOrderDirection);
+ public ExpressionOrderByItemSegment(final int startIndex, final int stopIndex, final String expression, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection) {
+ super(startIndex, stopIndex, orderDirection, nullsOrderDirection);
this.expression = expression;
this.expr = null;
}
- public ExpressionOrderByItemSegment(final int startIndex, final int stopIndex, final String expression, final OrderDirection orderDirection) {
- super(startIndex, stopIndex, orderDirection, OrderDirection.ASC);
- this.expression = expression;
- this.expr = null;
- }
-
- public ExpressionOrderByItemSegment(final int startIndex, final int stopIndex, final String expression, final OrderDirection orderDirection, final ExpressionSegment expr) {
- super(startIndex, stopIndex, orderDirection, OrderDirection.ASC);
+ public ExpressionOrderByItemSegment(final int startIndex, final int stopIndex, final String expression, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection,
+ final ExpressionSegment expr) {
+ super(startIndex, stopIndex, orderDirection, nullsOrderDirection);
this.expression = expression;
this.expr = expr;
}
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/IndexOrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/IndexOrderByItemSegment.java
index eea2a7cc449..0ef100e659b 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/IndexOrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/IndexOrderByItemSegment.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
import lombok.Getter;
import lombok.ToString;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
/**
@@ -30,12 +31,8 @@ public final class IndexOrderByItemSegment extends OrderByItemSegment {
private final int columnIndex;
- public IndexOrderByItemSegment(final int startIndex, final int stopIndex, final int columnIndex, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
- super(startIndex, stopIndex, orderDirection, nullOrderDirection);
+ public IndexOrderByItemSegment(final int startIndex, final int stopIndex, final int columnIndex, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection) {
+ super(startIndex, stopIndex, orderDirection, nullsOrderDirection);
this.columnIndex = columnIndex;
}
-
- public IndexOrderByItemSegment(final int startIndex, final int stopIndex, final int columnIndex, final OrderDirection orderDirection) {
- this(startIndex, stopIndex, columnIndex, orderDirection, OrderDirection.ASC);
- }
}
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/OrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/OrderByItemSegment.java
index a239c5142c6..848f042dd5f 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/OrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/OrderByItemSegment.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
@@ -37,5 +38,5 @@ public abstract class OrderByItemSegment implements SQLSegment {
private final OrderDirection orderDirection;
- private final OrderDirection nullOrderDirection;
+ private final NullsOrderDirection nullsOrderDirection;
}
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java
index df942bd14c6..b53f78a3e8f 100644
--- a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/order/item/TextOrderByItemSegment.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item;
import lombok.ToString;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.NullsOrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
/**
@@ -26,8 +27,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
@ToString
public abstract class TextOrderByItemSegment extends OrderByItemSegment {
- protected TextOrderByItemSegment(final int startIndex, final int stopIndex, final OrderDirection orderDirection, final OrderDirection nullOrderDirection) {
- super(startIndex, stopIndex, orderDirection, nullOrderDirection);
+ protected TextOrderByItemSegment(final int startIndex, final int stopIndex, final OrderDirection orderDirection, final NullsOrderDirection nullsOrderDirection) {
+ super(startIndex, stopIndex, orderDirection, nullsOrderDirection);
}
/**
diff --git a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/asserts/segment/orderby/OrderByItemAssert.java b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/asserts/segment/orderby/OrderByItemAssert.java
index fd643c66100..4b14cdd7f9e 100644
--- a/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/asserts/segment/orderby/OrderByItemAssert.java
+++ b/test/parser/src/main/java/org/apache/shardingsphere/test/sql/parser/internal/asserts/segment/orderby/OrderByItemAssert.java
@@ -86,7 +86,7 @@ public final class OrderByItemAssert {
private static void assertOrderInfo(final SQLCaseAssertContext assertContext, final OrderByItemSegment actual, final ExpectedOrderByItem expected, final String type) {
assertThat(assertContext.getText(String.format("%s item order direction assertion error: ", type)),
- null != actual.getOrderDirection() ? actual.getOrderDirection().name() : actual.getNullOrderDirection().name(), is(expected.getOrderDirection()));
+ null != actual.getOrderDirection() ? actual.getOrderDirection().name() : actual.getNullsOrderDirection().name(), is(expected.getOrderDirection()));
}
private static void assertColumnOrderByItem(final SQLCaseAssertContext assertContext,