From 4b353ee996562b0084be74d22f92b6851e2333ba Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 25 Jul 2023 17:25:42 -0700 Subject: [PATCH] Statically init `typeActionMap` in `OpenSearchExprValueFactory`. (#310) (#1897) Signed-off-by: Yury-Fridlyand Signed-off-by: Mitchell Gale --- .../data/value/OpenSearchExprValueFactory.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java index 22a43d3444..95815d5c38 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java @@ -105,7 +105,7 @@ public void extendTypeMapping(Map typeMapping) { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private final Map> typeActionMap = + private static final Map> typeActionMap = new ImmutableMap.Builder>() .put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Integer), (c, dt) -> new ExprIntegerValue(c.intValue())) @@ -126,10 +126,12 @@ public void extendTypeMapping(Map 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), @@ -222,7 +224,7 @@ private Optional 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 formatters = dataType.getAllNamedFormatters(); formatters.addAll(dataType.getAllCustomFormatters()); ExprCoreType returnFormat = (ExprCoreType) dataType.getExprType(); @@ -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();