← Back to Pull requests

feat(spark): support optional and variadic arguments in SparkInputTypes #421

Open
unknown opened this pull request with 425 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 26, 2026 08:11 UTC
Author

Which issue does this PR close?

  • Closes #385.
  • Rationale for this change

    SparkInputTypes takes exactly one type per argument, so a function with optional trailing arguments (round(expr[, scale])) or a variadic tail (concat_ws, elt) can't use it yet. #353 lists elt and concat_ws as waiting on this.

    What changes are included in this PR?

  • Optional trailing arguments. SparkInputTypes::optional(required, optional, volatility), so round can be declared as [Numeric] plus an optional [Integer]. coerce returns types only for the arguments that were given, and the function supplies the default for an omitted one itself.

  • Variadic tail. SparkInputTypes::variadic(fixed, repeated, min_args, volatility): the fixed types, then repeated for every remaining argument, with a minimum total count. The fixed arguments are always required. An invalid argument in the tail is reported by its own position, like any other argument.

  • Spark's WRONG_NUM_ARGS text for each case, formatted the way QueryCompilationErrors.wrongNumArgsError does it: 2 for one accepted count (unchanged), [1, 2] when several counts are accepted, and > 1 / > 0 for a variadic minimum, as elt and concat_ws raise it.

  • A short note in CONTRIBUTING.md and the module docs pointing to the two new constructors.
  • No function is moved onto them here, so there are no user-visible changes yet. concat_ws can use these constructors as they stand. elt can use the count check, but it still needs its own type checks (the index must already be INT, and every remaining argument must be STRING or BINARY), and check-only mode cannot yet be combined with a variadic tail. Moving the functions is left to #353.

    Are these changes tested?

    Yes, with unit tests in implicit_cast.rs:

  • optional arguments omitted and given, a wrong type in a given optional argument, and the [1, 2] / [0, 1, 2, 3] messages

  • a concat_ws-shaped variadic declaration (casts across the tail, separator only, an invalid tail argument reported by position, and the > 0 message), plus the > 1 message for elt

  • fixed arguments staying required when min_args is smaller, a variadic tail with no minimum, and ANSI mode applying to the tail
  • I checked the expected messages against Spark 4.2.0: wrongNumArgsError, the > 0 check in ConcatWs, the > 1 check in Elt, and to_json's [1, 2] in the json-functions.sql.out golden file. I didn't use the PySpark runner, since nothing reaches SQL yet.

    cargo fmt, cargo clippy --all-targets --all-features -- -D warnings, cargo test -p datafusion-spark, cargo test -p datafusion-spark-sqllogictest and cargo doc all pass locally.

    Are there any user-facing changes?

    No. The new constructors are crate-internal, and no function's behavior changes.

    Diff: 425 lines (+318 / -107) across 5 files Reviewer: andygrove Review duration: 7859m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 425 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #421"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24% · Safe to merge
    24%