Skip to content

Commit 647e927

Browse files
qianheng-awsexpani
authored andcommitted
Support access to nested field of struct after fields command (opensearch-project#4719)
Signed-off-by: Heng Qian <[email protected]>
1 parent 9657a6a commit 647e927

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

core/src/main/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ public static RelDataType convertExprTypeToRelDataType(ExprType fieldType, boole
184184
return TYPE_FACTORY.createArrayType(
185185
TYPE_FACTORY.createSqlType(SqlTypeName.ANY, nullable), -1);
186186
case STRUCT:
187-
// TODO: should use RelRecordType instead of MapSqlType here
188-
// https://github.com/opensearch-project/sql/issues/3459
189187
final RelDataType relKey = TYPE_FACTORY.createSqlType(SqlTypeName.VARCHAR);
188+
// TODO: should we provide more precise type here?
190189
return TYPE_FACTORY.createMapType(
191-
relKey, TYPE_FACTORY.createSqlType(SqlTypeName.BINARY), nullable);
190+
relKey, TYPE_FACTORY.createSqlType(SqlTypeName.ANY), nullable);
192191
case UNKNOWN:
193192
default:
194193
throw new IllegalArgumentException(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
setup:
2+
- do:
3+
query.settings:
4+
body:
5+
transient:
6+
plugins.calcite.enabled : true
7+
8+
- do:
9+
indices.create:
10+
index: test
11+
body:
12+
mappings:
13+
properties:
14+
parent_field:
15+
properties:
16+
child_field:
17+
type: integer
18+
19+
- do:
20+
bulk:
21+
index: test
22+
refresh: true
23+
body:
24+
- '{"index": {}}'
25+
- '{ "parent_field": { "child_field": 4 } }'
26+
- '{"index": {}}'
27+
- '{ "parent_field": { "child_field": 3 } }'
28+
- '{"index": {}}'
29+
- '{ "parent_field": { "child_field": 2 } }'
30+
- '{"index": {}}'
31+
- '{ "parent_field": { "child_field": 1 } }'
32+
- '{"index": {}}'
33+
- '{ "parent_field": { "child_field": 5 } }'
34+
35+
---
36+
teardown:
37+
- do:
38+
query.settings:
39+
body:
40+
transient:
41+
plugins.calcite.enabled : false
42+
43+
---
44+
"Access to nested field after field command":
45+
- skip:
46+
features:
47+
- headers
48+
- allowed_warnings
49+
50+
- do:
51+
headers:
52+
Content-Type: 'application/json'
53+
ppl:
54+
body:
55+
query: source=test | fields parent_field | sort parent_field.child_field | head 3
56+
57+
- match: { total: 3 }
58+
- match: { schema: [ { "name": "parent_field", "type": "struct" } ] }
59+
- match: { datarows: [ [ {"child_field": 1} ], [ {"child_field": 2} ], [ {"child_field": 3} ] ] }

0 commit comments

Comments
 (0)