Skip to content

Commit

Permalink
Added Arithmetic functions to V2 engine (#1416) (#1448)
Browse files Browse the repository at this point in the history
* Updated Arithmetic functions from old engine to new engine (#235)

* Updated ADD, SUBTRACT, MULTIPLY, DIVIDE, MODULUS to V2 engine

Signed-off-by: Matthew Wells <[email protected]>
(cherry picked from commit bc39346)

Co-authored-by: Matthew Wells <[email protected]>
  • Loading branch information
1 parent 5d01207 commit c286846
Show file tree
Hide file tree
Showing 12 changed files with 832 additions and 445 deletions.
59 changes: 39 additions & 20 deletions core/src/main/java/org/opensearch/sql/expression/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public static FunctionExpression abs(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.ABS, expressions);
}

public static FunctionExpression add(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.ADD, expressions);
}

public static FunctionExpression addFunction(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.ADDFUNCTION, expressions);
}

public static FunctionExpression ceil(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.CEIL, expressions);
}
Expand All @@ -166,6 +174,14 @@ public static FunctionExpression crc32(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.CRC32, expressions);
}

public static FunctionExpression divide(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.DIVIDE, expressions);
}

public static FunctionExpression divideFunction(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.DIVIDEFUNCTION, expressions);
}

public static FunctionExpression euler(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.E, expressions);
}
Expand Down Expand Up @@ -202,6 +218,22 @@ public static FunctionExpression mod(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MOD, expressions);
}

public static FunctionExpression modulus(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MODULUS, expressions);
}

public static FunctionExpression modulusFunction(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MODULUSFUNCTION, expressions);
}

public static FunctionExpression multiply(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MULTIPLY, expressions);
}

public static FunctionExpression multiplyFunction(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MULTIPLYFUNCTION, expressions);
}

public static FunctionExpression pi(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.PI, expressions);
}
Expand Down Expand Up @@ -286,20 +318,16 @@ public static FunctionExpression sin(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.SIN, expressions);
}

public static FunctionExpression tan(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.TAN, expressions);
}

public static FunctionExpression add(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.ADD, expressions);
}

public static FunctionExpression subtract(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.SUBTRACT, expressions);
}

public static FunctionExpression multiply(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MULTIPLY, expressions);
public static FunctionExpression subtractFunction(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.SUBTRACTFUNCTION, expressions);
}

public static FunctionExpression tan(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.TAN, expressions);
}

public static FunctionExpression convert_tz(Expression... expressions) {
Expand Down Expand Up @@ -494,20 +522,11 @@ public static FunctionExpression yearweek(
return compile(functionProperties, BuiltinFunctionName.YEARWEEK, expressions);
}

public static FunctionExpression divide(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.DIVIDE, expressions);
}

public static FunctionExpression module(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.MODULES, expressions);
}


public static FunctionExpression str_to_date(FunctionProperties functionProperties,
Expression... expressions) {
return compile(functionProperties, BuiltinFunctionName.STR_TO_DATE, expressions);
}

public static FunctionExpression sec_to_time(Expression... expressions) {
return compile(FunctionProperties.None, BuiltinFunctionName.SEC_TO_TIME, expressions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public enum BuiltinFunctionName {
LOG(FunctionName.of("log")),
LOG10(FunctionName.of("log10")),
LOG2(FunctionName.of("log2")),
MOD(FunctionName.of("mod")),
PI(FunctionName.of("pi")),
POW(FunctionName.of("pow")),
POWER(FunctionName.of("power")),
Expand Down Expand Up @@ -139,10 +138,16 @@ public enum BuiltinFunctionName {
* Arithmetic Operators.
*/
ADD(FunctionName.of("+")),
SUBTRACT(FunctionName.of("-")),
MULTIPLY(FunctionName.of("*")),
ADDFUNCTION(FunctionName.of("add")),
DIVIDE(FunctionName.of("/")),
MODULES(FunctionName.of("%")),
DIVIDEFUNCTION(FunctionName.of("divide")),
MOD(FunctionName.of("mod")),
MODULUS(FunctionName.of("%")),
MODULUSFUNCTION(FunctionName.of("modulus")),
MULTIPLY(FunctionName.of("*")),
MULTIPLYFUNCTION(FunctionName.of("multiply")),
SUBTRACT(FunctionName.of("-")),
SUBTRACTFUNCTION(FunctionName.of("subtract")),

/**
* Boolean Operators.
Expand Down
Loading

0 comments on commit c286846

Please sign in to comment.