Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Statically init typeActionMap in OpenSearchExprValueFactory. #1901

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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