Skip to content

fix(spark): return error from ELT coerce_types when fewer than 2 args#23164

Open
davidlghellin wants to merge 1 commit into
apache:mainfrom
davidlghellin:fix/elt_error
Open

fix(spark): return error from ELT coerce_types when fewer than 2 args#23164
davidlghellin wants to merge 1 commit into
apache:mainfrom
davidlghellin:fix/elt_error

Conversation

@davidlghellin

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes N/A

Rationale for this change

SparkElt::coerce_types validates that ELT receives at least 2 arguments (index + value1), but the error was never returned: it was built with plan_datafusion_err!(...) as an expression statement whose value was discarded. Since DataFusionError is not #[must_use], the compiler didn't warn, so the function fell through and continued with fewer arguments than required instead of failing with a clear plan-time error.

What changes are included in this PR?

In datafusion/spark/src/function/string/elt.rs, the argument-count check is wrapped in return Err(plan_datafusion_err!(...)) so the validation actually short-circuits when fewer than 2 arguments are provided.

Are these changes tested?

This change restores an error path that was previously dropped silently. ELT's normal behavior is already covered by the existing tests in elt.rs. The invalid-arity branch had no coverage because it was never actually exercised.

Are there any user-facing changes?

ELT now returns a plan-time error when invoked with fewer than 2 arguments, instead of silently continuing. No public API changes.

Copilot AI review requested due to automatic review settings June 24, 2026 15:23
@github-actions github-actions Bot added the spark label Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a planning-time validation bug in the Spark elt scalar UDF: when fewer than 2 arguments were provided, an error was constructed but never returned, allowing invalid arities to proceed.

Changes:

  • Return the plan_datafusion_err! result from SparkElt::coerce_types when arg_types.len() < 2, properly short-circuiting invalid calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 70 to 75
let length = arg_types.len();
if length < 2 {
plan_datafusion_err!(
return Err(plan_datafusion_err!(
"ELT function expects at least 2 arguments: index, value1"
);
));
}

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch -- thank you @davidlghellin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants