Skip to content

Commit eccd238

Browse files
Statically init typeActionMap in OpenSearchExprValueFactory. (#310)
Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent f4883c9 commit eccd238

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void extendTypeMapping(Map<String, OpenSearchDataType> typeMapping) {
105105

106106
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
107107

108-
private final Map<ExprType, BiFunction<Content, ExprType, ExprValue>> typeActionMap =
108+
private static final Map<ExprType, BiFunction<Content, ExprType, ExprValue>> typeActionMap =
109109
new ImmutableMap.Builder<ExprType, BiFunction<Content, ExprType, ExprValue>>()
110110
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Integer),
111111
(c, dt) -> new ExprIntegerValue(c.intValue()))
@@ -126,10 +126,12 @@ public void extendTypeMapping(Map<String, OpenSearchDataType> typeMapping) {
126126
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Boolean),
127127
(c, dt) -> ExprBooleanValue.of(c.booleanValue()))
128128
//Handles the creation of DATE, TIME & DATETIME
129-
.put(OpenSearchDateType.of(TIME), this::createOpenSearchDateType)
130-
.put(OpenSearchDateType.of(DATE), this::createOpenSearchDateType)
131-
.put(OpenSearchDateType.of(TIMESTAMP), this::createOpenSearchDateType)
132-
.put(OpenSearchDateType.of(DATETIME), this::createOpenSearchDateType)
129+
.put(OpenSearchDateType.of(TIME), OpenSearchExprValueFactory::createOpenSearchDateType)
130+
.put(OpenSearchDateType.of(DATE), OpenSearchExprValueFactory::createOpenSearchDateType)
131+
.put(OpenSearchDateType.of(TIMESTAMP),
132+
OpenSearchExprValueFactory::createOpenSearchDateType)
133+
.put(OpenSearchDateType.of(DATETIME),
134+
OpenSearchExprValueFactory::createOpenSearchDateType)
133135
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Ip),
134136
(c, dt) -> new OpenSearchExprIpValue(c.stringValue()))
135137
.put(OpenSearchDataType.of(OpenSearchDataType.MappingType.GeoPoint),
@@ -222,7 +224,7 @@ private Optional<ExprType> type(String field) {
222224
* @param dataType - field data type
223225
* @return Parsed value
224226
*/
225-
private ExprValue parseDateTimeString(String value, OpenSearchDateType dataType) {
227+
private static ExprValue parseDateTimeString(String value, OpenSearchDateType dataType) {
226228
List<DateFormatter> formatters = dataType.getAllNamedFormatters();
227229
formatters.addAll(dataType.getAllCustomFormatters());
228230
ExprCoreType returnFormat = (ExprCoreType) dataType.getExprType();
@@ -262,7 +264,7 @@ private ExprValue parseDateTimeString(String value, OpenSearchDateType dataType)
262264
"Construct %s from \"%s\" failed, unsupported format.", returnFormat, value));
263265
}
264266

265-
private ExprValue createOpenSearchDateType(Content value, ExprType type) {
267+
private static ExprValue createOpenSearchDateType(Content value, ExprType type) {
266268
OpenSearchDateType dt = (OpenSearchDateType) type;
267269
ExprType returnFormat = dt.getExprType();
268270

0 commit comments

Comments
 (0)