Skip to content

Commit 856b83e

Browse files
committed
Replace sqrt udf with a call to calcite's power(x, 0.5)
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 7bcc800 commit 856b83e

3 files changed

Lines changed: 10 additions & 44 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/PPLBuiltinOperators.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.opensearch.sql.expression.function.udf.math.DivideFunction;
5252
import org.opensearch.sql.expression.function.udf.math.EulerFunction;
5353
import org.opensearch.sql.expression.function.udf.math.ModFunction;
54-
import org.opensearch.sql.expression.function.udf.math.SqrtFunction;
5554
import org.opensearch.sql.expression.function.udf.text.LocateFunction;
5655

5756
/** Defines functions and operators that are implemented only by PPL */
@@ -60,7 +59,6 @@ public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable {
6059
// Math functions
6160
public static final SqlOperator SPAN = new SpanFunctionImpl().toUDF("SPAN");
6261
public static final SqlOperator E = new EulerFunction().toUDF("E");
63-
public static final SqlOperator SQRT = new SqrtFunction().toUDF("SQRT");
6462
public static final SqlOperator CONV = new ConvFunction().toUDF("CONVERT");
6563
public static final SqlOperator MOD = new ModFunction().toUDF("MOD");
6664
public static final SqlOperator CRC32 = new CRC32Function().toUDF("CRC32");

core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ void populate() {
218218
// Register PPL UDF operator
219219
registerOperator(SPAN, PPLBuiltinOperators.SPAN);
220220
registerOperator(E, PPLBuiltinOperators.E);
221-
222-
// SqlStdOperatorTable.SQRT is declared but not implemented, therefore we use a custom
223-
// implementation.
224-
registerOperator(SQRT, PPLBuiltinOperators.SQRT);
225221
registerOperator(CONV, PPLBuiltinOperators.CONV);
226222
registerOperator(MOD, PPLBuiltinOperators.MOD);
227223
registerOperator(MODULUS, PPLBuiltinOperators.MOD);
@@ -347,6 +343,16 @@ void populate() {
347343
SqlLibraryOperators.LOG,
348344
arg,
349345
builder.makeApproxLiteral(BigDecimal.valueOf(Math.E)))));
346+
// SqlStdOperatorTable.SQRT is declared but not implemented. The call to SQRT in Calcite is
347+
// converted to POWER(x, 0.5).
348+
register(
349+
SQRT,
350+
((FunctionImp1)
351+
(builder, arg) ->
352+
builder.makeCall(
353+
SqlStdOperatorTable.POWER,
354+
arg,
355+
builder.makeApproxLiteral(BigDecimal.valueOf(0.5)))));
350356
register(
351357
TYPEOF,
352358
(FunctionImp1)

core/src/main/java/org/opensearch/sql/expression/function/udf/math/SqrtFunction.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)