Skip to content

Commit

Permalink
Rename "function" and "operator" utility classes to be plural.
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 2, 2024
1 parent 23219cb commit d3be058
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* <em>count</em> accepts values of all types.
*/
@UtilityClass
public class AggregatorFunction {
public class AggregatorFunctions {
/**
* Register Aggregation Function.
*
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.exception.ExpressionEvaluationException;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.aggregation.AggregatorFunction;
import org.opensearch.sql.expression.datetime.DateTimeFunction;
import org.opensearch.sql.expression.aggregation.AggregatorFunctions;
import org.opensearch.sql.expression.datetime.DateTimeFunctions;
import org.opensearch.sql.expression.datetime.IntervalClause;
import org.opensearch.sql.expression.ip.IPFunction;
import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunction;
import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunction;
import org.opensearch.sql.expression.operator.convert.TypeCastOperator;
import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator;
import org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperator;
import org.opensearch.sql.expression.ip.IPFunctions;
import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunctions;
import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunctions;
import org.opensearch.sql.expression.operator.convert.TypeCastOperators;
import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperators;
import org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperators;
import org.opensearch.sql.expression.system.SystemFunctions;
import org.opensearch.sql.expression.text.TextFunction;
import org.opensearch.sql.expression.text.TextFunctions;
import org.opensearch.sql.expression.window.WindowFunctions;
import org.opensearch.sql.storage.StorageEngine;

Expand Down Expand Up @@ -70,19 +70,19 @@ public static synchronized BuiltinFunctionRepository getInstance() {
instance = new BuiltinFunctionRepository(new HashMap<>());

// Register all built-in functions
ArithmeticFunction.register(instance);
BinaryPredicateOperator.register(instance);
MathematicalFunction.register(instance);
UnaryPredicateOperator.register(instance);
AggregatorFunction.register(instance);
DateTimeFunction.register(instance);
ArithmeticFunctions.register(instance);
BinaryPredicateOperators.register(instance);
MathematicalFunctions.register(instance);
UnaryPredicateOperators.register(instance);
AggregatorFunctions.register(instance);
DateTimeFunctions.register(instance);
IntervalClause.register(instance);
WindowFunctions.register(instance);
TextFunction.register(instance);
TypeCastOperator.register(instance);
TextFunctions.register(instance);
TypeCastOperators.register(instance);
SystemFunctions.register(instance);
OpenSearchFunctions.register(instance);
IPFunction.register(instance);
IPFunctions.register(instance);
}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

public void register(BuiltinFunctionRepository repository) {
repository.register(cidrmatch());
Expand All @@ -35,7 +35,7 @@ private DefaultFunctionResolver cidrmatch() {
// TODO #3145: Add support for IP address data type.
return define(
BuiltinFunctionName.CIDRMATCH.getName(),
impl(nullMissingHandling(IPFunction::exprCidrMatch), BOOLEAN, STRING, STRING));
impl(nullMissingHandling(IPFunctions::exprCidrMatch), BOOLEAN, STRING, STRING));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* module, Accepts two numbers and produces a number.
*/
@UtilityClass
public class ArithmeticFunction {
public class ArithmeticFunctions {
/**
* Register Arithmetic Function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.opensearch.sql.expression.function.SerializableFunction;

@UtilityClass
public class MathematicalFunction {
public class MathematicalFunctions {
/**
* Register Mathematical Functions.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import org.opensearch.sql.expression.function.FunctionDSL;

@UtilityClass
public class TypeCastOperator {
public class TypeCastOperators {

/** Register Type Cast Operator. */
public static void register(BuiltinFunctionRepository repository) {
repository.register(castToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* equalTo, Compare the left expression and right expression and produces a Boolean.
*/
@UtilityClass
public class BinaryPredicateOperator {
public class BinaryPredicateOperators {
/**
* Register Binary Predicate Function.
*
Expand Down Expand Up @@ -401,7 +401,7 @@ private static DefaultFunctionResolver notLike() {
BuiltinFunctionName.NOT_LIKE.getName(),
impl(
nullMissingHandling(
(v1, v2) -> UnaryPredicateOperator.not(OperatorUtils.matches(v1, v2))),
(v1, v2) -> UnaryPredicateOperators.not(OperatorUtils.matches(v1, v2))),
BOOLEAN,
STRING,
STRING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
* The definition of unary predicate function not, Accepts one Boolean value and produces a Boolean.
*/
@UtilityClass
public class UnaryPredicateOperator {
public class UnaryPredicateOperators {

/** Register Unary Predicate Function. */
public static void register(BuiltinFunctionRepository repository) {
repository.register(not());
Expand All @@ -45,7 +46,7 @@ public static void register(BuiltinFunctionRepository repository) {
private static DefaultFunctionResolver not() {
return FunctionDSL.define(
BuiltinFunctionName.NOT.getName(),
FunctionDSL.impl(UnaryPredicateOperator::not, BOOLEAN, BOOLEAN));
FunctionDSL.impl(UnaryPredicateOperators::not, BOOLEAN, BOOLEAN));
}

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ private static DefaultFunctionResolver ifFunction() {
org.apache.commons.lang3.tuple.Pair<FunctionSignature, FunctionBuilder>>>
functionsOne =
typeList.stream()
.map(v -> impl((UnaryPredicateOperator::exprIf), v, BOOLEAN, v, v))
.map(v -> impl((UnaryPredicateOperators::exprIf), v, BOOLEAN, v, v))
.collect(Collectors.toList());

return FunctionDSL.define(functionName, functionsOne);
Expand All @@ -124,7 +125,7 @@ private static DefaultFunctionResolver ifNull() {
org.apache.commons.lang3.tuple.Pair<FunctionSignature, FunctionBuilder>>>
functionsOne =
typeList.stream()
.map(v -> impl((UnaryPredicateOperator::exprIfNull), v, v, v))
.map(v -> impl((UnaryPredicateOperators::exprIfNull), v, v, v))
.collect(Collectors.toList());

return FunctionDSL.define(functionName, functionsOne);
Expand All @@ -137,7 +138,7 @@ private static DefaultFunctionResolver nullIf() {
return FunctionDSL.define(
functionName,
typeList.stream()
.map(v -> impl((UnaryPredicateOperator::exprNullIf), v, v, v))
.map(v -> impl((UnaryPredicateOperators::exprNullIf), v, v, v))
.collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* implementation should rely on ExprValue.
*/
@UtilityClass
public class TextFunction {
public class TextFunctions {
private static String EMPTY_STRING = "";

/**
Expand Down Expand Up @@ -76,9 +76,9 @@ public void register(BuiltinFunctionRepository repository) {
private DefaultFunctionResolver substringSubstr(FunctionName functionName) {
return define(
functionName,
impl(nullMissingHandling(TextFunction::exprSubstrStart), STRING, STRING, INTEGER),
impl(nullMissingHandling(TextFunctions::exprSubstrStart), STRING, STRING, INTEGER),
impl(
nullMissingHandling(TextFunction::exprSubstrStartLength),
nullMissingHandling(TextFunctions::exprSubstrStartLength),
STRING,
STRING,
INTEGER,
Expand Down Expand Up @@ -267,7 +267,7 @@ private DefaultFunctionResolver strcmp() {
private DefaultFunctionResolver right() {
return define(
BuiltinFunctionName.RIGHT.getName(),
impl(nullMissingHandling(TextFunction::exprRight), STRING, STRING, INTEGER));
impl(nullMissingHandling(TextFunctions::exprRight), STRING, STRING, INTEGER));
}

/**
Expand All @@ -279,7 +279,7 @@ private DefaultFunctionResolver right() {
private DefaultFunctionResolver left() {
return define(
BuiltinFunctionName.LEFT.getName(),
impl(nullMissingHandling(TextFunction::exprLeft), STRING, STRING, INTEGER));
impl(nullMissingHandling(TextFunctions::exprLeft), STRING, STRING, INTEGER));
}

/**
Expand All @@ -292,7 +292,7 @@ private DefaultFunctionResolver left() {
private DefaultFunctionResolver ascii() {
return define(
BuiltinFunctionName.ASCII.getName(),
impl(nullMissingHandling(TextFunction::exprAscii), INTEGER, STRING));
impl(nullMissingHandling(TextFunctions::exprAscii), INTEGER, STRING));
}

/**
Expand All @@ -310,14 +310,14 @@ private DefaultFunctionResolver locate() {
BuiltinFunctionName.LOCATE.getName(),
impl(
nullMissingHandling(
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunction::exprLocate),
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunctions::exprLocate),
INTEGER,
STRING,
STRING),
impl(
nullMissingHandling(
(SerializableTriFunction<ExprValue, ExprValue, ExprValue, ExprValue>)
TextFunction::exprLocate),
TextFunctions::exprLocate),
INTEGER,
STRING,
STRING,
Expand All @@ -337,7 +337,7 @@ private DefaultFunctionResolver position() {
BuiltinFunctionName.POSITION.getName(),
impl(
nullMissingHandling(
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunction::exprLocate),
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunctions::exprLocate),
INTEGER,
STRING,
STRING));
Expand All @@ -353,7 +353,7 @@ private DefaultFunctionResolver position() {
private DefaultFunctionResolver replace() {
return define(
BuiltinFunctionName.REPLACE.getName(),
impl(nullMissingHandling(TextFunction::exprReplace), STRING, STRING, STRING, STRING));
impl(nullMissingHandling(TextFunctions::exprReplace), STRING, STRING, STRING, STRING));
}

/**
Expand All @@ -365,7 +365,7 @@ private DefaultFunctionResolver replace() {
private DefaultFunctionResolver reverse() {
return define(
BuiltinFunctionName.REVERSE.getName(),
impl(nullMissingHandling(TextFunction::exprReverse), STRING, STRING));
impl(nullMissingHandling(TextFunctions::exprReverse), STRING, STRING));
}

private static ExprValue exprSubstrStart(ExprValue exprValue, ExprValue start) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import lombok.ToString;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator;
import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperators;
import org.opensearch.sql.storage.bindingtuple.BindingTuple;

/**
* The Filter operator represents WHERE clause and uses the conditions to evaluate the input {@link
* BindingTuple}. The Filter operator only returns the results that evaluated to true. The NULL and
* MISSING are handled by the logic defined in {@link BinaryPredicateOperator}.
* MISSING are handled by the logic defined in {@link BinaryPredicateOperators}.
*/
@EqualsAndHashCode(callSuper = false)
@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.type.ExprCoreType.LONG;
import static org.opensearch.sql.expression.datetime.DateTimeFunction.SECONDS_PER_DAY;
import static org.opensearch.sql.expression.datetime.DateTimeFunctions.SECONDS_PER_DAY;

import java.time.Duration;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ public void test_if_predicate(Expression v1, Expression v2, Expression v3, Expre
@ParameterizedTest
@MethodSource("exprIfNullArguments")
public void test_exprIfNull_predicate(ExprValue v1, ExprValue v2, ExprValue expected) {
assertEquals(expected.value(), UnaryPredicateOperator.exprIfNull(v1, v2).value());
assertEquals(expected.value(), UnaryPredicateOperators.exprIfNull(v1, v2).value());
}

@ParameterizedTest
@MethodSource("exprNullIfArguments")
public void test_exprNullIf_predicate(ExprValue v1, ExprValue v2, ExprValue expected) {
assertEquals(expected.value(), UnaryPredicateOperator.exprNullIf(v1, v2).value());
assertEquals(expected.value(), UnaryPredicateOperators.exprNullIf(v1, v2).value());
}
}

0 comments on commit d3be058

Please sign in to comment.