Skip to content

Commit 2d9555c

Browse files
committed
Handle cases where there exist duplicated group keys
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 9dcc2c5 commit 2d9555c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,10 @@ private List<String> getGroupKeyNamesAfterAggregation(List<RexNode> nodes) {
10191019
List<RexNode> reordered = new ArrayList<>();
10201020
List<RexNode> left = new ArrayList<>();
10211021
for (RexNode n : nodes) {
1022+
// The same group-key won't be added twice
1023+
if (reordered.contains(n)) {
1024+
continue;
1025+
}
10221026
if (isInputRef(n)) {
10231027
reordered.add(n);
10241028
} else {

integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/4580.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,20 @@ teardown:
7979
- match: { total: 4 }
8080
- match: { schema: [{"name": "count()", "type": "bigint"}, {"name": "@timestamp", "type": "timestamp"}, {"name": "category", "type": "string"}, {"name": "value", "type": "bigint"}] }
8181
- match: { datarows: [[1, "2024-01-01 00:00:00", "A", 1000], [1, "2024-01-01 00:10:00", "A", 1500], [1, "2024-01-01 00:00:00", "B", 2000], [1, "2024-01-01 00:20:00", "C", 3000]] }
82+
83+
---
84+
"Test span aggregation with duplicated group keys":
85+
- skip:
86+
features:
87+
- headers
88+
- allowed_warnings
89+
- do:
90+
headers:
91+
Content-Type: 'application/json'
92+
ppl:
93+
body:
94+
query: source=time_test | stats count() by value, value, span(@timestamp, 10min) as @timestamp
95+
96+
- match: { total: 4 }
97+
- match: { schema: [{"name": "count()", "type": "bigint"}, {"name": "@timestamp", "type": "timestamp"}, {"name": "value", "type": "bigint"}, {"name": "value0", "type": "bigint"}] }
98+
- match: { datarows: [[1, "2024-01-01 00:00:00", 1000, 1000], [1, "2024-01-01 00:10:00", 1500, 1500], [1, "2024-01-01 00:00:00", 2000, 2000], [1, "2024-01-01 00:20:00", 3000, 3000]] }

0 commit comments

Comments
 (0)