Skip to content

Commit

Permalink
Update spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Kwok <[email protected]>
  • Loading branch information
andy-k-improving committed Jan 28, 2025
1 parent 1b41d5f commit 694b08c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,16 @@ public String toString() {
}

/**
* Static class to identify functional Expression which specifically designed for OpenSearch storage runtime
* Static class to identify functional Expression which specifically designed for OpenSearch
* storage runtime
*/
public static class OpenSearchExecutableFunction extends FunctionExpression {
private final FunctionName functionName;
private final List<Expression> arguments;
private final ExprType returnType;

public OpenSearchExecutableFunction(
FunctionName functionName, List<Expression> arguments, ExprType returnType) {
FunctionName functionName, List<Expression> arguments, ExprType returnType) {
super(functionName, arguments);
this.functionName = functionName;
this.arguments = arguments;
Expand All @@ -193,9 +194,9 @@ public OpenSearchExecutableFunction(
@Override
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
throw new UnsupportedOperationException(
String.format(
"OpenSearch defined function [%s] is only supported in Eval operation.",
functionName));
String.format(
"OpenSearch defined function [%s] is only supported in Eval operation.",
functionName));
}

@Override
Expand All @@ -206,14 +207,14 @@ public ExprType type() {
@Override
public String toString() {
List<String> args =
arguments.stream()
.map(
arg ->
String.format(
"%s=%s",
((NamedArgumentExpression) arg).getArgName(),
((NamedArgumentExpression) arg).getValue().toString()))
.collect(Collectors.toList());
arguments.stream()
.map(
arg ->
String.format(
"%s=%s",
((NamedArgumentExpression) arg).getArgName(),
((NamedArgumentExpression) arg).getValue().toString()))
.collect(Collectors.toList());
return String.format("%s(%s)", functionName, String.join(", ", args));
}

Expand All @@ -225,12 +226,13 @@ public String toString() {
* @return Binary Function Implementation.
*/
public static SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>>
openSearchImpl(ExprType returnType, List<ExprType> args) {
openSearchImpl(ExprType returnType, List<ExprType> args) {
return functionName -> {
FunctionSignature functionSignature = new FunctionSignature(functionName, args);
FunctionBuilder functionBuilder =
(functionProperties, arguments) ->
new OpenSearchFunctions.OpenSearchExecutableFunction(functionName, arguments, returnType);
(functionProperties, arguments) ->
new OpenSearchFunctions.OpenSearchExecutableFunction(
functionName, arguments, returnType);
return Pair.of(functionSignature, functionBuilder);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@

import inet.ipaddr.IPAddress;
import java.util.Arrays;
import java.util.List;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.tuple.Pair;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.model.ExprValueUtils;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.function.BuiltinFunctionName;
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
import org.opensearch.sql.expression.function.DefaultFunctionResolver;
import org.opensearch.sql.expression.function.FunctionBuilder;
import org.opensearch.sql.expression.function.FunctionName;
import org.opensearch.sql.expression.function.FunctionSignature;
import org.opensearch.sql.expression.function.OpenSearchFunctions;
import org.opensearch.sql.expression.function.SerializableFunction;
import org.opensearch.sql.utils.IPUtils;

/** Utility class that defines and registers IP functions. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,33 @@ public void testGeoIpEnrichment() {
public void testGeoIpEnrichmentWithSingleOption() {

JSONObject resultGeoIp =
executeQuery(
String.format(
"search source=%s | eval enrichmentResult = geoip(\\\"%s\\\",%s,\\\"%s\\\")",
TEST_INDEX_GEOIP, "dummycityindex", "ip", "city"));
executeQuery(
String.format(
"search source=%s | eval enrichmentResult = geoip(\\\"%s\\\",%s,\\\"%s\\\")",
TEST_INDEX_GEOIP, "dummycityindex", "ip", "city"));

verifyColumn(resultGeoIp, columnName("name"), columnName("ip"), columnName("enrichmentResult"));
verifyDataRows(
resultGeoIp,
rows("Test user - USA", "10.1.1.1", Map.of( "city", "Seattle")),
rows("Test user - Canada", "127.1.1.1", Map.of( "city", "Vancouver")));
resultGeoIp,
rows("Test user - USA", "10.1.1.1", Map.of("city", "Seattle")),
rows("Test user - Canada", "127.1.1.1", Map.of("city", "Vancouver")));
}

@SneakyThrows
@Test
public void testGeoIpEnrichmentWithSpaceSeparatedMultipleOptions() {

JSONObject resultGeoIp =
executeQuery(
String.format(
"search source=%s | eval enrichmentResult = geoip(\\\"%s\\\",%s,\\\"%s\\\")",
TEST_INDEX_GEOIP, "dummycityindex", "ip", "city, country"));
executeQuery(
String.format(
"search source=%s | eval enrichmentResult = geoip(\\\"%s\\\",%s,\\\"%s\\\")",
TEST_INDEX_GEOIP, "dummycityindex", "ip", "city , country"));

verifyColumn(resultGeoIp, columnName("name"), columnName("ip"), columnName("enrichmentResult"));
verifyDataRows(
resultGeoIp,
rows("Test user - USA", "10.1.1.1", Map.of("country", "USA", "city", "Seattle")),
rows("Test user - Canada", "127.1.1.1", Map.of("country", "Canada", "city", "Vancouver")));
resultGeoIp,
rows("Test user - USA", "10.1.1.1", Map.of("country", "USA", "city", "Seattle")),
rows("Test user - Canada", "127.1.1.1", Map.of("country", "Canada", "city", "Vancouver")));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protected Map<String, ExprValue> eval(Environment<Expression, ExprValue> env) {
Map<String, ExprValue> evalResultMap = new LinkedHashMap<>();
for (Pair<ReferenceExpression, Expression> pair : this.getExpressionList()) {
ExprValue value;
if (pair.getValue() instanceof OpenSearchFunctions.OpenSearchExecutableFunction openSearchExpr) {
if (pair.getValue()
instanceof OpenSearchFunctions.OpenSearchExecutableFunction openSearchExpr) {
value = OpenSearchEvalProcessor.process(openSearchExpr, env, nodeClient);
} else {
value = pair.getValue().valueOf(env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ private static ExprValue fetchIpEnrichment(
String option = StringUtils.unquoteText(arguments.get(2).toString());
// Convert the option into a set.
options.addAll(
Arrays.stream(option.split(","))
.map(String::trim)
.collect(Collectors.toSet()));
Arrays.stream(option.split(",")).map(String::trim).collect(Collectors.toSet()));
}
try {
Map<String, Object> geoLocationData = ipClient.getGeoLocationData(ipAddress, dataSource);
Expand Down

0 comments on commit 694b08c

Please sign in to comment.