Skip to content
Merged
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
195 changes: 74 additions & 121 deletions .claude/skills/wire-datafusion-function/SKILL.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion docs/source/contributor-guide/spark_expressions_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@
- [ ] e
- [x] exp
- [x] expm1
- [ ] factorial
- [x] factorial
- 3.4.3 (audited 2026-05-15): identical to v3.5.8.
- 3.5.8 (audited 2026-05-15): canonical reference; `extends UnaryExpression with ImplicitCastInputTypes with NullIntolerant`. Returns NULL for NULL input or values outside `[0, 20]`.
- 4.0.1 (audited 2026-05-15): `NullIntolerant` trait replaced by `nullIntolerant: Boolean` method override; behavior unchanged.
- [x] floor
- [x] greatest
- [x] hex
Expand Down
1 change: 1 addition & 0 deletions docs/source/user-guide/latest/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ of expressions that be disabled.
| Divide | `/` |
| Exp | `exp` |
| Expm1 | `expm1` |
| Factorial | `factorial` |
| Floor | `floor` |
| Hex | `hex` |
| IntegralDivide | `div` |
Expand Down
2 changes: 2 additions & 0 deletions native/core/src/execution/jni_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use datafusion_spark::function::hash::sha2::SparkSha2;
use datafusion_spark::function::map::map_from_entries::MapFromEntries;
use datafusion_spark::function::map::str_to_map::SparkStrToMap;
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::trigonometry::SparkCsc;
use datafusion_spark::function::math::width_bucket::SparkWidthBucket;
Expand Down Expand Up @@ -597,6 +598,7 @@ fn register_datafusion_spark_function(session_ctx: &SessionContext) {
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkUrlEncode::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkTryUrlDecode::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkCsc::default()));
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkFactorial::default()));
}

/// Prepares arrow arrays for output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ object QueryPlanSerde extends Logging with CometExprShim with CometTypeShim {
classOf[Divide] -> CometDivide,
classOf[Exp] -> CometScalarFunction("exp"),
classOf[Expm1] -> CometScalarFunction("expm1"),
classOf[Factorial] -> CometScalarFunction("factorial"),
classOf[Floor] -> CometFloor,
classOf[Greatest] -> CometScalarFunction("greatest"),
classOf[Hex] -> CometHex,
Expand Down
39 changes: 39 additions & 0 deletions spark/src/test/resources/sql-tests/expressions/math/factorial.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

-- ConfigMatrix: parquet.enable.dictionary=false,true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: all values in the table are distinct so there will not be any dictionary-encoding. This matrix is running the test twice for no good reason.

Suggested change
-- ConfigMatrix: parquet.enable.dictionary=false,true


statement
CREATE TABLE test_factorial(i int) USING parquet

statement
INSERT INTO test_factorial VALUES
(0),
(1),
(5),
(12),
(20),
(21),
(-1),
(-5),
(100),
(NULL),
(2147483647),
(-2147483648)

query
SELECT i, factorial(i) FROM test_factorial
Loading