From 51e066316738ea4438fa55cfa902fe716a7b4fd6 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Tue, 29 Oct 2024 11:39:20 +0800 Subject: [PATCH 1/2] Fix avg, sum, min, max function return empty data when no query result --- .../groupby/GroupByMemoryMergedResult.java | 8 +++--- .../cases/dql/e2e-dql-select-group-by.xml | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java index 6c456bfca7b63..226f48fab8f3d 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResult.java @@ -17,18 +17,18 @@ package org.apache.shardingsphere.sharding.merge.dql.groupby; -import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException; import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection; import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.AggregationDistinctProjection; import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.AggregationProjection; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult; import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.sharding.exception.data.NotImplementComparableValueException; import org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnit; import org.apache.shardingsphere.sharding.merge.dql.groupby.aggregation.AggregationUnitFactory; @@ -38,14 +38,12 @@ import java.sql.SQLException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; @@ -144,7 +142,7 @@ private List getMemoryResultSetRows(final SelectStatementC final Map dataMap, final List valueCaseSensitive) { if (dataMap.isEmpty()) { Object[] data = generateReturnData(selectStatementContext); - return Arrays.stream(data).anyMatch(Objects::nonNull) ? Collections.singletonList(new MemoryQueryResultRow(data)) : Collections.emptyList(); + return selectStatementContext.getProjectionsContext().getAggregationProjections().isEmpty() ? Collections.emptyList() : Collections.singletonList(new MemoryQueryResultRow(data)); } List result = new ArrayList<>(dataMap.values()); result.sort(new GroupByRowComparator(selectStatementContext, valueCaseSensitive)); diff --git a/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-group-by.xml b/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-group-by.xml index aa525aeb344f5..0a12d650c70c0 100644 --- a/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-group-by.xml +++ b/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-group-by.xml @@ -52,4 +52,29 @@ scenario-comments="Test single table's LIKE operator underscore wildcard in select group by statement when use sharding feature.|Test encrypt table's LIKE operator underscore wildcard in select group by statement when use encrypt feature."> + + + + + + + + + + + + + + + + + + + + From 4b5aad09e16d97ee4cf56dab24b4b97c8154485b Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Tue, 29 Oct 2024 11:42:56 +0800 Subject: [PATCH 2/2] Update release note --- RELEASE-NOTES.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index dc1a84afae79b..3a3108766e8eb 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -12,8 +12,8 @@ 1. SQL Federation: Upgrade calcite version to 1.38.0 and update all license info in LICENSE file - [#33279](https://github.com/apache/shardingsphere/pull/33279) 1. SQL Parser: Support parsing Doris INSTR - [#33289](https://github.com/apache/shardingsphere/pull/33289) 1. Agent: Simplify the use of Agent's Docker Image - [#33356](https://github.com/apache/shardingsphere/pull/33356) -1. Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382) -1. Add index columns not empty judgement for IndexColumnTokenGenerator - [#33384](https://github.com/apache/shardingsphere/pull/33384) +1. Kernel: Add arguments not null check when creating RouteUnit - [#33382](https://github.com/apache/shardingsphere/pull/33382) +1. Kernel: Add index columns not empty judgement for IndexColumnTokenGenerator - [#33384](https://github.com/apache/shardingsphere/pull/33384) 1. SQL Parser: Support parsing Doris STRRIGHT - [#33393](https://github.com/apache/shardingsphere/pull/33393) 1. JDBC: Add show database name for JDBC when execute SHOW COMPUTE NODES - [#33437](https://github.com/apache/shardingsphere/pull/33437) @@ -25,7 +25,8 @@ 1. SQL Binder: Fix SQL performance issues caused by repeated subquery fetches - [#33361](https://github.com/apache/shardingsphere/pull/33361) 1. Sharding: Remove ShardingRouteAlgorithmException check logic temporarily to support different actual table name config - [#33367](https://github.com/apache/shardingsphere/pull/33367) 1. SQL Binder: Fix table does not exist exception when use HintManager#setDatabaseName to transparent - [#33370](https://github.com/apache/shardingsphere/pull/33370) -1. Fix LiteralExpressionSegment cast exception in sql parser. - [#33332](https://github.com/apache/shardingsphere/pull/33332) +1. SQL Parser: Fix LiteralExpressionSegment cast exception in sql parser. - [#33332](https://github.com/apache/shardingsphere/pull/33332) +1. Sharding: Fix avg, sum, min, max function return empty data when no query result return - [#33449](https://github.com/apache/shardingsphere/pull/33449) ### Change Logs