Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions native/core/src/execution/jni_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ use datafusion_spark::function::hash::sha1::SparkSha1;
use datafusion_spark::function::hash::sha2::SparkSha2;
use datafusion_spark::function::map::map_from_entries::MapFromEntries;
use datafusion_spark::function::math::expm1::SparkExpm1;
use datafusion_spark::function::math::factorial::SparkFactorial;
use datafusion_spark::function::math::hex::SparkHex;
use datafusion_spark::function::math::modulus::SparkPmod;
use datafusion_spark::function::math::rint::SparkRint;
use datafusion_spark::function::math::width_bucket::SparkWidthBucket;
use datafusion_spark::function::string::char::CharFunc;
use datafusion_spark::function::string::concat::SparkConcat;
Expand Down Expand Up @@ -400,6 +403,9 @@ fn register_datafusion_spark_function(session_ctx: &SessionContext) {
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkWidthBucket::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(MapFromEntries::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkCrc32::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkFactorial::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkPmod::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkRint::default()));
}

/// Prepares arrow arrays for output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object QueryPlanSerde extends Logging with CometExprShim {
classOf[Divide] -> CometDivide,
classOf[Exp] -> CometScalarFunction("exp"),
classOf[Expm1] -> CometScalarFunction("expm1"),
classOf[Factorial] -> CometScalarFunction("factorial"),
classOf[Floor] -> CometFloor,
classOf[Hex] -> CometHex,
classOf[IntegralDivide] -> CometIntegralDivide,
Expand All @@ -104,10 +105,12 @@ object QueryPlanSerde extends Logging with CometExprShim {
classOf[Log2] -> CometLog2,
classOf[Log10] -> CometLog10,
classOf[Multiply] -> CometMultiply,
classOf[Pmod] -> CometScalarFunction("pmod"),
classOf[Pow] -> CometScalarFunction("pow"),
classOf[Rand] -> CometRand,
classOf[Randn] -> CometRandn,
classOf[Remainder] -> CometRemainder,
classOf[Rint] -> CometScalarFunction("rint"),
classOf[Round] -> CometRound,
classOf[Signum] -> CometScalarFunction("signum"),
classOf[Sin] -> CometScalarFunction("sin"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ class CometMathExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelpe
"SELECT id, width_bucket(value, 0.0, 10.0, 5) FROM width_bucket_range ORDER BY id")
}
}

test("factorial") {
withParquetTable(Seq((0, 1), (1, 5), (2, 10), (3, 20), (4, -1)).map(Tuple1(_)), "tbl") {
checkSparkAnswerAndOperator("SELECT factorial(_1._1) FROM tbl")
checkSparkAnswerAndOperator("SELECT factorial(_1._2) FROM tbl")
checkSparkAnswerAndOperator("SELECT factorial(NULL) FROM tbl")
}
}

test("pmod") {
withParquetTable(Seq((10, 3), (7, -2), (-7, 2), (-7, -2), (0, 5)), "tbl") {
checkSparkAnswerAndOperator("SELECT pmod(_1, _2) FROM tbl")
checkSparkAnswerAndOperator("SELECT pmod(NULL, _2) FROM tbl")
}
}

test("rint") {
withParquetTable(
Seq[java.lang.Double](1.5, 2.5, -1.5, 0.0, 3.7, null).map(Tuple1(_)),
"tbl") {
checkSparkAnswerAndOperator("SELECT rint(_1) FROM tbl")
checkSparkAnswerAndOperator("SELECT rint(NULL) FROM tbl")
}
}
}
Loading