Skip to content

Commit

Permalink
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 Dec 31, 2024
1 parent ce7146e commit 746fd14
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public T visitEqualTo(EqualTo node, C context) {
return visitChildren(node, context);
}


public T visitGeoIp(Node node, C context) {
return visitChildren(node, context);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/opensearch/sql/expression/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public static FunctionExpression utc_timestamp(
}

public static FunctionExpression geoip(
FunctionProperties functionProperties, Expression... args) {
FunctionProperties functionProperties, Expression... args) {
return compile(functionProperties, BuiltinFunctionName.GEOIP, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

package org.opensearch.sql.expression.ip;

import inet.ipaddr.AddressStringException;
import inet.ipaddr.IPAddressString;
import inet.ipaddr.IPAddressStringParameters;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.expression.function.FunctionDSL.define;

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;
Expand All @@ -22,29 +22,19 @@
import org.opensearch.sql.expression.function.FunctionSignature;
import org.opensearch.sql.expression.function.SerializableFunction;

import java.util.Arrays;
import java.util.List;

import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.expression.function.FunctionDSL.define;
import static org.opensearch.sql.expression.function.FunctionDSL.impl;
import static org.opensearch.sql.expression.function.FunctionDSL.nullMissingHandling;

/** Utility class that defines and registers IP functions. */
@UtilityClass
public class GeoIPFunctions {

public void register(BuiltinFunctionRepository repository) {
repository.register(geoIp());

}

private DefaultFunctionResolver geoIp() {
return define(
BuiltinFunctionName.GEOIP.getName(),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING)),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING, STRING)));
BuiltinFunctionName.GEOIP.getName(),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING)),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING, STRING)));
}

/**
Expand All @@ -53,16 +43,14 @@ private DefaultFunctionResolver geoIp() {
* @param returnType return type.
* @return Binary Function Implementation.
*/
public static SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>> openSearchImpl(
ExprType returnType,
List<ExprType> args) {
public static SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>>
openSearchImpl(ExprType returnType, List<ExprType> args) {
return functionName -> {
FunctionSignature functionSignature = new FunctionSignature(functionName, args);
FunctionBuilder functionBuilder =
(functionProperties, arguments) ->
new OpenSearchFunctionExpression(functionName, arguments, returnType);
(functionProperties, arguments) ->
new OpenSearchFunctionExpression(functionName, arguments, returnType);
return Pair.of(functionSignature, functionBuilder);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import inet.ipaddr.AddressStringException;
import inet.ipaddr.IPAddressString;
import inet.ipaddr.IPAddressStringParameters;
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;
Expand All @@ -28,17 +30,13 @@
import org.opensearch.sql.expression.function.FunctionSignature;
import org.opensearch.sql.expression.function.SerializableFunction;

import java.util.Arrays;
import java.util.List;

/** Utility class that defines and registers IP functions. */
@UtilityClass
public class IPFunctions {

public void register(BuiltinFunctionRepository repository) {
repository.register(cidrmatch());
repository.register(geoIp());

}

private DefaultFunctionResolver cidrmatch() {
Expand All @@ -52,9 +50,9 @@ private DefaultFunctionResolver cidrmatch() {
private DefaultFunctionResolver geoIp() {

return define(
BuiltinFunctionName.GEOIP.getName(),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING)),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING, STRING)));
BuiltinFunctionName.GEOIP.getName(),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING)),
openSearchImpl(BOOLEAN, Arrays.asList(STRING, STRING, STRING)));
}

/**
Expand Down Expand Up @@ -128,16 +126,14 @@ private ExprValue exprCidrMatch(ExprValue addressExprValue, ExprValue rangeExprV
* @param returnType return type.
* @return Binary Function Implementation.
*/
public static SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>> openSearchImpl(
ExprType returnType,
List<ExprType> args) {
public static SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>>
openSearchImpl(ExprType returnType, List<ExprType> args) {
return functionName -> {
FunctionSignature functionSignature = new FunctionSignature(functionName, args);
FunctionBuilder functionBuilder =
(functionProperties, arguments) ->
new OpenSearchFunctionExpression(functionName, arguments, returnType);
(functionProperties, arguments) ->
new OpenSearchFunctionExpression(functionName, arguments, returnType);
return Pair.of(functionSignature, functionBuilder);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,41 @@

package org.opensearch.sql.expression.ip;

import java.util.List;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.FunctionExpression;
import org.opensearch.sql.expression.env.Environment;
import org.opensearch.sql.expression.function.FunctionName;

import java.util.List;

/**
* Marker interface to identify functions compatible when OpenSearch is being used as storage engine.
* Marker interface to identify functions compatible when OpenSearch is being used as storage
* engine.
*/
public class OpenSearchFunctionExpression extends FunctionExpression {

private final ExprType returnType;

public OpenSearchFunctionExpression(FunctionName functionName, List<Expression> arguments, ExprType returnType) {
super(functionName, arguments);
this.returnType = returnType;
}

@Override
public ExprValue valueOf() {
return null;
}

@Override
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
throw new UnsupportedOperationException(
"OpenSearch runtime specific function, no default implementation available");
}

@Override
public ExprType type() {
return returnType;
}
private final ExprType returnType;

public OpenSearchFunctionExpression(
FunctionName functionName, List<Expression> arguments, ExprType returnType) {
super(functionName, arguments);
this.returnType = returnType;
}

@Override
public ExprValue valueOf() {
return null;
}

@Override
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
throw new UnsupportedOperationException(
"OpenSearch runtime specific function, no default implementation available");
}

@Override
public ExprType type() {
return returnType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ public PhysicalPlan visitRemove(RemoveOperator node, Object context) {
public PhysicalPlan visitEval(EvalOperator node, Object context) {
OpenSearchEvalOperator evalOperator = (OpenSearchEvalOperator) node;
return doProtect(
new OpenSearchEvalOperator(
visitInput(evalOperator.getInput(), context),
evalOperator.getExpressionList(),
evalOperator.getNodeClient()
)
);
new OpenSearchEvalOperator(
visitInput(evalOperator.getInput(), context),
evalOperator.getExpressionList(),
evalOperator.getNodeClient()));
}

@Override
Expand Down
Loading

0 comments on commit 746fd14

Please sign in to comment.