Skip to content

Commit

Permalink
Fix tests; remove polymorphic division function that breaks backward …
Browse files Browse the repository at this point in the history
…compatibility
  • Loading branch information
yashmayya committed Sep 26, 2024
1 parent 15330eb commit 223bb2e
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public class ArithmeticFunctions {
private ArithmeticFunctions() {
}

@ScalarFunction(names = {"div", "divide"})
public static double divide(double a, double b) {
return a / b;
}

@ScalarFunction(names = {"div", "divide"})
public static double divide(double a, double b, double defaultValue) {
return (b == 0) ? defaultValue : a / b;
}

@ScalarFunction
public static double mod(double a, double b) {
return a % b;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.pinot.common.function.FunctionInfo;
import org.apache.pinot.common.function.sql.PinotSqlFunction;
import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
import org.apache.pinot.spi.annotations.ScalarFunction;

Expand All @@ -43,6 +47,12 @@ public class MinusScalarFunction extends PolymorphicBinaryArithmeticScalarFuncti
}
}

@Override
@Nullable
public PinotSqlFunction toPinotSqlFunction() {
return new PinotSqlFunction(getName(), ReturnTypes.NULLABLE_SUM, OperandTypes.NUMERIC_NUMERIC);
}

@Override
protected FunctionInfo functionInfoForType(ColumnDataType argumentType) {
FunctionInfo functionInfo = TYPE_FUNCTION_INFO_MAP.get(argumentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.pinot.common.function.FunctionInfo;
import org.apache.pinot.common.function.sql.PinotSqlFunction;
import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
import org.apache.pinot.spi.annotations.ScalarFunction;

Expand All @@ -43,6 +47,12 @@ public class MultScalarFunction extends PolymorphicBinaryArithmeticScalarFunctio
}
}

@Override
@Nullable
public PinotSqlFunction toPinotSqlFunction() {
return new PinotSqlFunction(getName(), ReturnTypes.PRODUCT_NULLABLE, OperandTypes.NUMERIC_NUMERIC);
}

@Override
protected FunctionInfo functionInfoForType(ColumnDataType argumentType) {
FunctionInfo functionInfo = TYPE_FUNCTION_INFO_MAP.get(argumentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.pinot.common.function.FunctionInfo;
import org.apache.pinot.common.function.sql.PinotSqlFunction;
import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
import org.apache.pinot.spi.annotations.ScalarFunction;

Expand All @@ -43,6 +47,12 @@ public class PlusScalarFunction extends PolymorphicBinaryArithmeticScalarFunctio
}
}

@Override
@Nullable
public PinotSqlFunction toPinotSqlFunction() {
return new PinotSqlFunction(getName(), ReturnTypes.NULLABLE_SUM, OperandTypes.NUMERIC_NUMERIC);
}

@Override
protected FunctionInfo functionInfoForType(ColumnDataType argumentType) {
FunctionInfo functionInfo = TYPE_FUNCTION_INFO_MAP.get(argumentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,14 +2363,6 @@ public void testCompileTimeExpression() {
result = expression.getLiteral().getLongValue();
Assert.assertTrue(result >= lowerBound && result <= upperBound);

expression = compileToExpression("now() / 1");
Assert.assertNotNull(expression.getFunctionCall());
expression = CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(expression);
Assert.assertNotNull(expression.getLiteral());
upperBound = System.currentTimeMillis();
result = expression.getLiteral().getLongValue();
Assert.assertTrue(result >= lowerBound && result <= upperBound);

lowerBound = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis()) + 1;
expression = compileToExpression("to_epoch_hours(now() + 3600000)");
Assert.assertNotNull(expression.getFunctionCall());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void testPostAggregationFunction() {
// Plus
PostAggregationFunction function =
new PostAggregationFunction("plus", new ColumnDataType[]{ColumnDataType.INT, ColumnDataType.LONG});
assertEquals(function.getResultType(), ColumnDataType.DOUBLE);
assertEquals(function.invoke(new Object[]{1, 2L}), 3.0);
assertEquals(function.getResultType(), ColumnDataType.LONG);
assertEquals(function.invoke(new Object[]{1, 2L}), 3L);

// Minus
function = new PostAggregationFunction("MINUS", new ColumnDataType[]{ColumnDataType.FLOAT, ColumnDataType.DOUBLE});
Expand Down
Loading

0 comments on commit 223bb2e

Please sign in to comment.