You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2023/04/14 14:57:19 UTC
[iotdb] branch rel/1.1 updated: [To rel/1.1] Fix Group By Tag with empty grouped timeseries
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch rel/1.1
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.1 by this push:
new 51161c0afd [To rel/1.1] Fix Group By Tag with empty grouped timeseries
51161c0afd is described below
commit 51161c0afdcd6a45ed57733b51288428ee6f9454
Author: Weihao Li <60...@users.noreply.github.com>
AuthorDate: Fri Apr 14 22:57:10 2023 +0800
[To rel/1.1] Fix Group By Tag with empty grouped timeseries
---
.../db/it/aggregation/IoTDBTagAggregationIT.java | 13 +++++++++
.../db/mpp/plan/planner/LogicalPlanBuilder.java | 34 +++++++++++-----------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBTagAggregationIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBTagAggregationIT.java
index ed0a1c66c4..bb7a2645b0 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBTagAggregationIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBTagAggregationIT.java
@@ -42,6 +42,8 @@ import java.util.List;
import java.util.Set;
import static org.apache.iotdb.db.it.utils.TestUtils.assertTestFail;
+import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
+import static org.apache.iotdb.itbase.constant.TestConstant.count;
import static org.junit.Assert.fail;
@RunWith(IoTDBTestRunner.class)
@@ -87,6 +89,10 @@ public class IoTDBTagAggregationIT {
"insert into root.case2.d2(time, s1) values(10, 7.7);",
"insert into root.case2.d1(time, s2) values(10, 6.6);",
"insert into root.case2.d3(time, s1) values(10, 9.9);",
+ "create timeseries root.test.g_0.tab1.s_0 with datatype=int32;",
+ "create timeseries root.test.g_0.tab1.s_1 with datatype=int32;",
+ "insert into root.test.g_0.tab1(time,s_0,s_1) values (1,1,1);",
+ "alter timeseries root.test.g_0.tab1.s_0 add tags city=beijing;"
};
protected static final double DELTA = 0.001D;
@@ -581,6 +587,13 @@ public class IoTDBTagAggregationIT {
e.printStackTrace();
fail(e.getMessage());
}
+
+ String[] expectedHeader = new String[] {"city", count("s_0"), count("s_1")};
+ String[] retArray = new String[] {"beijing,1,null,", "NULL,null,1,"};
+ resultSetEqualTest(
+ "select count(s_0) ,count(s_1) from root.test.g_0.tab1 group by tags(city)",
+ expectedHeader,
+ retArray);
}
@Test
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
index f2ba699208..84d121be41 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
@@ -104,7 +104,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -737,24 +736,25 @@ public class LogicalPlanBuilder {
tagValuesToGroupedTimeseriesOperands.get(tagValues);
List<CrossSeriesAggregationDescriptor> aggregationDescriptors = new ArrayList<>();
- Iterator<Expression> iter = groupedTimeseriesOperands.keySet().iterator();
+ // Bind an AggregationDescriptor for each GroupByTagOutputExpression
for (Expression groupByTagOutputExpression : groupByTagOutputExpressions) {
- if (!iter.hasNext()) {
- aggregationDescriptors.add(null);
- continue;
+ boolean added = false;
+ for (Expression expression : groupedTimeseriesOperands.keySet()) {
+ if (expression.equals(groupByTagOutputExpression)) {
+ String functionName = ((FunctionExpression) expression).getFunctionName();
+ CrossSeriesAggregationDescriptor aggregationDescriptor =
+ new CrossSeriesAggregationDescriptor(
+ functionName,
+ curStep,
+ groupedTimeseriesOperands.get(expression),
+ ((FunctionExpression) expression).getFunctionAttributes(),
+ expression.getExpressions().get(0));
+ aggregationDescriptors.add(aggregationDescriptor);
+ added = true;
+ break;
+ }
}
- Expression next = iter.next();
- if (next.equals(groupByTagOutputExpression)) {
- String functionName = ((FunctionExpression) next).getFunctionName();
- CrossSeriesAggregationDescriptor aggregationDescriptor =
- new CrossSeriesAggregationDescriptor(
- functionName,
- curStep,
- groupedTimeseriesOperands.get(next),
- ((FunctionExpression) next).getFunctionAttributes(),
- next.getExpressions().get(0));
- aggregationDescriptors.add(aggregationDescriptor);
- } else {
+ if (!added) {
aggregationDescriptors.add(null);
}
}