Skip to content

Commit 018fc59

Browse files
authored
Use table scan rowType in filter pushdown could fix rename issue (#4670)
1 parent c6a3a70 commit 018fc59

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test
5+
- do:
6+
query.settings:
7+
body:
8+
transient:
9+
plugins.calcite.enabled : true
10+
11+
- do:
12+
bulk:
13+
index: test
14+
refresh: true
15+
body:
16+
- '{"index": {}}'
17+
- '{"status":"200","service":"api","value":100,"time":"2025-01-01T00:00:00Z"}'
18+
- '{"index": {}}'
19+
- '{"status":"500","service":"web","value":200,"time":"2025-01-02T00:00:00Z"}'
20+
- '{"index": {}}'
21+
- '{"status":"200","service":"db","value":150,"time":"2025-01-03T00:00:00Z"}'
22+
- '{"index": {}}'
23+
- '{"status":"404","service":"api","value":50,"time":"2025-01-03T00:01:00Z"}'
24+
25+
---
26+
teardown:
27+
- do:
28+
query.settings:
29+
body:
30+
transient:
31+
plugins.calcite.enabled : false
32+
33+
---
34+
"4563: Test rename then dedup":
35+
- skip:
36+
features:
37+
- headers
38+
- do:
39+
headers:
40+
Content-Type: 'application/json'
41+
ppl:
42+
body:
43+
query: source=test | rename status as http_status | dedup http_status | fields http_status
44+
45+
- match: { total: 3 }
46+
- match: { schema: [{"name": "http_status", "type": "string"}] }
47+
- match: { datarows: [["200"], ["500"], ["404"]] }
48+
49+
---
50+
"4664: Test rename then filter":
51+
- skip:
52+
features:
53+
- headers
54+
- do:
55+
headers:
56+
Content-Type: 'application/json'
57+
ppl:
58+
body:
59+
query: source=test | rename status as http_status | where http_status = '404' | fields http_status
60+
61+
- match: { total: 1 }
62+
- match: { schema: [{"name": "http_status", "type": "string"}] }
63+
- match: { datarows: [["404"]] }

opensearch/src/main/java/org/opensearch/sql/opensearch/storage/scan/CalciteLogicalIndexScan.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ protected AbstractCalciteIndexScan buildScan(
102102
cluster, traitSet, hints, table, osIndex, schema, pushDownContext);
103103
}
104104

105+
public CalciteLogicalIndexScan copy() {
106+
return new CalciteLogicalIndexScan(
107+
getCluster(), traitSet, hints, table, osIndex, schema, pushDownContext.clone());
108+
}
109+
105110
public CalciteLogicalIndexScan copyWithNewSchema(RelDataType schema) {
106111
// Do shallow copy for requestBuilder, thus requestBuilder among different plans produced in the
107112
// optimization process won't affect each other.
@@ -131,8 +136,7 @@ public void register(RelOptPlanner planner) {
131136

132137
public AbstractRelNode pushDownFilter(Filter filter) {
133138
try {
134-
RelDataType rowType = filter.getRowType();
135-
CalciteLogicalIndexScan newScan = this.copyWithNewSchema(filter.getRowType());
139+
RelDataType rowType = this.getRowType();
136140
List<String> schema = this.getRowType().getFieldNames();
137141
Map<String, ExprType> fieldTypes =
138142
this.osIndex.getAllFieldTypes().entrySet().stream()
@@ -142,6 +146,7 @@ public AbstractRelNode pushDownFilter(Filter filter) {
142146
PredicateAnalyzer.analyzeExpression(
143147
filter.getCondition(), schema, fieldTypes, rowType, getCluster());
144148
// TODO: handle the case where condition contains a score function
149+
CalciteLogicalIndexScan newScan = this.copy();
145150
newScan.pushDownContext.add(
146151
queryExpression.getScriptCount() > 0 ? PushDownType.SCRIPT : PushDownType.FILTER,
147152
new FilterDigest(

0 commit comments

Comments
 (0)