Skip to content

Commit 12bd0e9

Browse files
Use table scan rowType in filter pushdown could fix rename issue (#4670) (#4674)
1 parent b3863fc commit 12bd0e9

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
@@ -103,6 +103,11 @@ protected AbstractCalciteIndexScan buildScan(
103103
cluster, traitSet, hints, table, osIndex, schema, pushDownContext);
104104
}
105105

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

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

0 commit comments

Comments
 (0)