Skip to content

Commit 040fb3e

Browse files
Grouping key field type can only be overwritten when the ExprCoreType are different (#4850)
Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit 1c27a6d) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 2afc04a commit 040fb3e

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
setup:
2+
- do:
3+
query.settings:
4+
body:
5+
transient:
6+
plugins.calcite.enabled: true
7+
- do:
8+
indices.create:
9+
index: test
10+
body:
11+
mappings:
12+
properties:
13+
"EventDate":
14+
type: date
15+
format: yyyy-MM-dd HH:mm:ss||strict_date_optional_time||epoch_millis
16+
- do:
17+
bulk:
18+
index: test
19+
refresh: true
20+
body:
21+
- '{"index": {"_id": "1"}}'
22+
- '{"EventDate": "2013-07-15 10:47:34"}'
23+
24+
---
25+
teardown:
26+
- do:
27+
query.settings:
28+
body:
29+
transient:
30+
plugins.calcite.enabled : false
31+
32+
---
33+
"handle custom format field with pushdown":
34+
- skip:
35+
features:
36+
- headers
37+
- allowed_warnings
38+
- do:
39+
allowed_warnings:
40+
- 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled'
41+
headers:
42+
Content-Type: 'application/json'
43+
ppl:
44+
body:
45+
query: source=test | stats count() by EventDate
46+
47+
- match: { total: 1 }
48+
- match: {"schema": [{"name": "count()", "type": "bigint"},{"name": "EventDate", "type": "timestamp"}]}
49+
- match: {"datarows": [[1, "2013-07-15 10:47:34"]]}

opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ public class OpenSearchExprValueFactory {
8181
private final boolean fieldTypeTolerance;
8282

8383
/**
84-
* Extend existing mapping by new data without overwrite. Called from aggregation only {@see
85-
* AggregationQueryBuilder#buildTypeMapping}.
84+
* Extend existing mapping by new data. Overwrite only when the ExprCoreType of them are
85+
* different. Called from aggregation only {@see AggregationQueryBuilder#buildTypeMapping}.
8686
*
8787
* @param typeMapping A data type mapping produced by aggregation.
8888
*/
8989
public void extendTypeMapping(Map<String, OpenSearchDataType> typeMapping) {
90-
this.typeMapping.putAll(typeMapping);
90+
typeMapping.forEach(
91+
(groupKey, extendedType) -> {
92+
OpenSearchDataType existedType = this.typeMapping.get(groupKey);
93+
if (existedType == null
94+
|| !existedType.getExprCoreType().equals(extendedType.getExprCoreType())) {
95+
this.typeMapping.put(groupKey, extendedType);
96+
}
97+
});
9198
}
9299

93100
@Getter @Setter private OpenSearchAggregationResponseParser parser;

0 commit comments

Comments
 (0)