Skip to content

Commit

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

Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
(cherry picked from commit c8d42a7)
  • Loading branch information
Yury-Fridlyand authored and github-actions[bot] committed Jul 26, 2023
1 parent d14cce1 commit bd482e2
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 bd482e2

Please sign in to comment.