Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ class MathFunctionsValidateSuiteAnsiOn extends FunctionsValidateSuite {
}
}

abstract class MathFunctionsValidateSuite extends FunctionsValidateSuite {
class MathFunctionsValidateSuite extends FunctionsValidateSuite {

// Disable ANSI mode: Spark 4 enables it by default, which wraps math functions
// in ANSI check nodes and prevents ProjectExecTransformer from being the top-level
// plan node. ANSI-specific behaviour is tested in MathFunctionsValidateSuiteAnsiOn.
override protected def sparkConf: SparkConf = {
super.sparkConf
.set(SQLConf.ANSI_ENABLED.key, "false")
}

disableFallbackCheck
import testImplicits._
Expand Down Expand Up @@ -295,6 +303,12 @@ abstract class MathFunctionsValidateSuite extends FunctionsValidateSuite {
}
}

test("radians") {
runQueryAndCompare("SELECT radians(l_orderkey) from lineitem limit 1") {
checkGlutenPlan[ProjectExecTransformer]
}
}

test("rint") {
withTempPath {
path =>
Expand Down Expand Up @@ -332,6 +346,24 @@ abstract class MathFunctionsValidateSuite extends FunctionsValidateSuite {
}
}

test("sin") {
runQueryAndCompare("SELECT sin(l_orderkey) from lineitem limit 1") {
checkGlutenPlan[ProjectExecTransformer]
}
}

test("tan") {
runQueryAndCompare("SELECT tan(l_orderkey) from lineitem limit 1") {
checkGlutenPlan[ProjectExecTransformer]
}
}

test("tanh") {
runQueryAndCompare("SELECT tanh(l_orderkey) from lineitem limit 1") {
checkGlutenPlan[ProjectExecTransformer]
}
}

test("try_add") {
runQueryAndCompare(
"select try_add(cast(l_orderkey as int), 1), try_add(cast(l_orderkey as int), 2147483647)" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ package org.apache.gluten.functions
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.execution.{BatchScanExecTransformer, FilterExecTransformer, ProjectExecTransformer}

import org.apache.spark.SparkException
import org.apache.spark.{SparkConf, SparkException}
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.optimizer.NullPropagation
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._

abstract class ScalarFunctionsValidateSuite extends FunctionsValidateSuite {
class ScalarFunctionsValidateSuite extends FunctionsValidateSuite {

// Disable ANSI mode: Spark 4 enables it by default, which wraps scalar functions
// in ANSI check nodes and prevents ProjectExecTransformer from being the top-level
// plan node.
override protected def sparkConf: SparkConf = {
super.sparkConf
.set(SQLConf.ANSI_ENABLED.key, "false")
}

disableFallbackCheck

import testImplicits._
Expand Down
9 changes: 9 additions & 0 deletions cpp/velox/operators/functions/RegistrationAllFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "velox/functions/iceberg/Register.h"
#include "velox/functions/lib/CheckedArithmetic.h"
#include "velox/functions/lib/RegistrationHelpers.h"
#include "velox/functions/prestosql/Arithmetic.h"
#include "velox/functions/prestosql/aggregates/RegisterAggregateFunctions.h"
#include "velox/functions/prestosql/registration/RegistrationFunctions.h"
#include "velox/functions/prestosql/window/WindowFunctionsRegistration.h"
Expand Down Expand Up @@ -76,6 +77,14 @@ void registerFunctionOverwrite() {
kRowConstructorWithAllNull,
std::make_unique<RowConstructorWithNullCallToSpecialForm>(kRowConstructorWithAllNull));

// Register math functions that are present in the prestosql implementation
// but not yet in the sparksql registry. These are semantically identical
// to Spark's behavior for the same names.
velox::registerFunction<velox::functions::RadiansFunction, double, double>({"radians"});
velox::registerFunction<velox::functions::SinFunction, double, double>({"sin"});
velox::registerFunction<velox::functions::TanFunction, double, double>({"tan"});
velox::registerFunction<velox::functions::TanhFunction, double, double>({"tanh"});

velox::functions::registerPrestoVectorFunctions();
}

Expand Down
Loading