Skip to content

Commit 1c27a6d

Browse files
authored
Grouping key field type can only be overwritten when the ExprCoreType are different (#4850)
Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent ede63cb commit 1c27a6d

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
@@ -79,13 +79,20 @@ public class OpenSearchExprValueFactory {
7979
private final boolean fieldTypeTolerance;
8080

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

9198
@Getter @Setter private OpenSearchAggregationResponseParser parser;

0 commit comments

Comments
 (0)