Skip to content

Commit f725141

Browse files
Reduce RelCompositeTrait of RelCollation to a single collation when creating LogicalSystemLimit (#4758) (#4808)
(cherry picked from commit 7b30c9b) Signed-off-by: Yuanchun Shen <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3662ec4 commit f725141

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

core/src/main/java/org/opensearch/sql/calcite/plan/LogicalSystemLimit.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ private LogicalSystemLimit(
6565
}
6666

6767
public static LogicalSystemLimit create(SystemLimitType type, RelNode input, RexNode fetch) {
68-
return create(type, input, input.getTraitSet().getCollation(), null, fetch);
68+
return create(type, input, null, fetch);
6969
}
7070

7171
public static LogicalSystemLimit create(
72-
SystemLimitType type,
73-
RelNode input,
74-
RelCollation collation,
75-
@Nullable RexNode offset,
76-
@Nullable RexNode fetch) {
72+
SystemLimitType type, RelNode input, @Nullable RexNode offset, @Nullable RexNode fetch) {
7773
RelOptCluster cluster = input.getCluster();
74+
List<RelCollation> collations = input.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE);
75+
// When there exists multiple sets of equivalent collations, we randomly select one
76+
RelCollation collation = collations == null ? null : collations.get(0);
7877
collation = RelCollationTraitDef.INSTANCE.canonize(collation);
7978
RelTraitSet traitSet = input.getTraitSet().replace(Convention.NONE).replace(collation);
8079
return new LogicalSystemLimit(type, cluster, traitSet, input, collation, offset, fetch);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: timechart-eval-bug
5+
body:
6+
mappings:
7+
properties:
8+
"@timestamp":
9+
type: date
10+
"user":
11+
type: keyword
12+
- do:
13+
bulk:
14+
index: timechart-eval-bug
15+
refresh: true
16+
body:
17+
- '{"index":{}}'
18+
- '{"@timestamp":"2024-05-01T00:15:00Z","user":"alice"}'
19+
- '{"index":{}}'
20+
- '{"@timestamp":"2024-05-01T00:30:00Z","user":"bob"}'
21+
- '{"index":{}}'
22+
- '{"@timestamp":"2024-05-02T00:45:00Z","user":"alice"}'
23+
- '{"index":{}}'
24+
- '{"@timestamp":"2024-05-03T00:20:00Z","user":"bob"}'
25+
26+
---
27+
"timechart with eval on @timestamp field":
28+
- skip:
29+
features:
30+
- headers
31+
- do:
32+
headers:
33+
Content-Type: 'application/json'
34+
ppl:
35+
body:
36+
query: source=timechart-eval-bug | where HOUR(@timestamp) = 0 | timechart span=1d COUNT() by user | eval copyTimestamp = @timestamp
37+
38+
- match: { total: 4 }
39+
- match: { "schema": [ { "name": "@timestamp", "type": "timestamp" }, { "name": "user", "type": "string" }, { "name": "COUNT()", "type": "bigint" }, { "name": "copyTimestamp", "type": "timestamp" }] }
40+
- match: {"datarows": [["2024-05-01 00:00:00", "alice", 1, "2024-05-01 00:00:00"], ["2024-05-01 00:00:00", "bob", 1, "2024-05-01 00:00:00"], ["2024-05-02 00:00:00", "alice", 1, "2024-05-02 00:00:00"], ["2024-05-03 00:00:00", "bob", 1, "2024-05-03 00:00:00"]]}
41+
42+
---
43+
"timechart with eval on by field":
44+
- skip:
45+
features:
46+
- headers
47+
- do:
48+
headers:
49+
Content-Type: 'application/json'
50+
ppl:
51+
body:
52+
query: source=timechart-eval-bug | where HOUR(@timestamp) = 0 | timechart span=1d COUNT() by user | eval copyUser = user
53+
54+
- match: { total: 4 }
55+
- match: { "schema": [ { "name": "@timestamp", "type": "timestamp" }, { "name": "user", "type": "string" }, { "name": "COUNT()", "type": "bigint" }, { "name": "copyUser", "type": "string" }] }
56+
- match: {"datarows": [["2024-05-01 00:00:00", "alice", 1, "alice"], ["2024-05-01 00:00:00", "bob", 1, "bob"], ["2024-05-02 00:00:00", "alice", 1, "alice"], ["2024-05-03 00:00:00", "bob", 1, "bob"]]}
57+
58+
---
59+
"timechart with eval on aggregated field":
60+
- skip:
61+
features:
62+
- headers
63+
- do:
64+
headers:
65+
Content-Type: 'application/json'
66+
ppl:
67+
body:
68+
query: source=timechart-eval-bug | where HOUR(@timestamp) = 0 | timechart span=1d COUNT() by user | eval doubleCount = `COUNT()` * 2
69+
70+
- match: { total: 4 }
71+
- match: { "schema": [ { "name": "@timestamp", "type": "timestamp" }, { "name": "user", "type": "string" }, { "name": "COUNT()", "type": "bigint" }, { "name": "doubleCount", "type": "bigint" }] }
72+
- match: {"datarows": [["2024-05-01 00:00:00", "alice", 1, 2], ["2024-05-01 00:00:00", "bob", 1, 2], ["2024-05-02 00:00:00", "alice", 1, 2], ["2024-05-03 00:00:00", "bob", 1, 2]]}
73+
74+
---
75+
"timechart with DATE_FORMAT on @timestamp":
76+
- skip:
77+
features:
78+
- headers
79+
- do:
80+
headers:
81+
Content-Type: 'application/json'
82+
ppl:
83+
body:
84+
query: source=timechart-eval-bug | where HOUR(@timestamp) = 0 | timechart span=1d COUNT() by user | eval formatted_date = DATE_FORMAT(@timestamp, 'yyyy-MM-dd')
85+
86+
- match: { total: 4 }
87+
- match: { "schema": [ { "name": "@timestamp", "type": "timestamp" }, { "name": "user", "type": "string" }, { "name": "COUNT()", "type": "bigint" }, { "name": "formatted_date", "type": "string" }] }
88+
- match: {"datarows": [["2024-05-01 00:00:00", "alice", 1, "2024-05-01"], ["2024-05-01 00:00:00", "bob", 1, "2024-05-01"], ["2024-05-02 00:00:00", "alice", 1, "2024-05-02"], ["2024-05-03 00:00:00", "bob", 1, "2024-05-03"]]}

0 commit comments

Comments
 (0)