Skip to content

Commit

Permalink
Statically init typeActionMap in OpenSearchExprValueFactory. (#310)…
Browse files Browse the repository at this point in the history
… (opensearch-project#1897)

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
Yury-Fridlyand authored and MitchellGale committed Jul 28, 2023
1 parent 1e10f5c commit 4b353ee
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void extendTypeMapping(Map<String, OpenSearchDataType> typeMapping) {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private final Map<ExprType, BiFunction<Content, ExprType, ExprValue>> typeActionMap =
private static final Map<ExprType, BiFunction<Content, ExprType, ExprValue>> typeActionMap =
new ImmutableMap.Builder<ExprType, BiFunction<Content, ExprType, ExprValue>>()
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Integer),
(c, dt) -> new ExprIntegerValue(c.intValue()))
Expand All @@ -126,10 +126,12 @@ public void extendTypeMapping(Map<String, OpenSearchDataType> typeMapping) {
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Boolean),
(c, dt) -> ExprBooleanValue.of(c.booleanValue()))
//Handles the creation of DATE, TIME & DATETIME
.put(OpenSearchDateType.of(TIME), this::createOpenSearchDateType)
.put(OpenSearchDateType.of(DATE), this::createOpenSearchDateType)
.put(OpenSearchDateType.of(TIMESTAMP), this::createOpenSearchDateType)
.put(OpenSearchDateType.of(DATETIME), this::createOpenSearchDateType)
.put(OpenSearchDateType.of(TIME), OpenSearchExprValueFactory::createOpenSearchDateType)
.put(OpenSearchDateType.of(DATE), OpenSearchExprValueFactory::createOpenSearchDateType)
.put(OpenSearchDateType.of(TIMESTAMP),
OpenSearchExprValueFactory::createOpenSearchDateType)
.put(OpenSearchDateType.of(DATETIME),
OpenSearchExprValueFactory::createOpenSearchDateType)
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Ip),
(c, dt) -> new OpenSearchExprIpValue(c.stringValue()))
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.GeoPoint),
Expand Down Expand Up @@ -222,7 +224,7 @@ private Optional<ExprType> type(String field) {
* @param dataType - field data type
* @return Parsed value
*/
private ExprValue parseDateTimeString(String value, OpenSearchDateType dataType) {
private static ExprValue parseDateTimeString(String value, OpenSearchDateType dataType) {
List<DateFormatter> formatters = dataType.getAllNamedFormatters();
formatters.addAll(dataType.getAllCustomFormatters());
ExprCoreType returnFormat = (ExprCoreType) dataType.getExprType();
Expand Down Expand Up @@ -262,7 +264,7 @@ private ExprValue parseDateTimeString(String value, OpenSearchDateType dataType)
"Construct %s from \"%s\" failed, unsupported format.", returnFormat, value));
}

private ExprValue createOpenSearchDateType(Content value, ExprType type) {
private static ExprValue createOpenSearchDateType(Content value, ExprType type) {
OpenSearchDateType dt = (OpenSearchDateType) type;
ExprType returnFormat = dt.getExprType();

Expand Down

0 comments on commit 4b353ee

Please sign in to comment.