Skip to content

Commit 7e4ca2c

Browse files
committed
fix: support for spark-compatible null seed
1 parent c5c80e2 commit 7e4ca2c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

native/spark-expr/src/rand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl RandExpr {
8787
}
8888

8989
fn extract_init_state(seed: ScalarValue) -> Result<i64> {
90-
if let ScalarValue::Int64(Some(init_seed)) = seed.cast_to(&DataType::Int64)? {
91-
Ok(init_seed)
90+
if let ScalarValue::Int64(seed_opt) = seed.cast_to(&DataType::Int64)? {
91+
Ok(seed_opt.unwrap_or(0))
9292
} else {
9393
Err(DataFusionError::Internal(
9494
"unexpected execution branch".to_string(),

spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala

+3
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,9 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
25312531
val dfWithOverflowSeed =
25322532
df.repartition(partitionsNumber).withColumn("rnd", rand(Long.MaxValue))
25332533
checkSparkAnswer(dfWithOverflowSeed)
2534+
val dfWithNullSeed =
2535+
df.repartition(partitionsNumber).selectExpr("_1", "rand(null) as rnd")
2536+
checkSparkAnswer(dfWithNullSeed)
25342537
}
25352538
}
25362539
}

0 commit comments

Comments
 (0)