Skip to content

Commit 2c586da

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

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ private List<String> getGroupKeyNamesAfterAggregation(List<RexNode> nodes) {
10221022
List<RexNode> reordered = new ArrayList<>();
10231023
List<RexNode> left = new ArrayList<>();
10241024
for (RexNode n : nodes) {
1025+
// The same group-key won't be added twice
1026+
if (reordered.contains(n) || left.contains(n)) {
1027+
continue;
1028+
}
10251029
if (isInputRef(n)) {
10261030
reordered.add(n);
10271031
} 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)