← Back to Pull requests

feat(spark): add Spark-compatible json_array_length function #71

Closed
unknown closed this pull request without merging on Nov 16, 2026 12:31 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 15:12 UTC
Author

Part of #242.

Summary


  • Adds Spark's json_array_length(jsonArray), ported from DataFusion Comet's json_funcs/json_array_length.rs.

  • Returns the number of elements in the outermost JSON array. NULL for a NULL input, empty string, invalid or truncated JSON, and valid JSON that is not an array. Anything after the closing bracket is ignored, as in Spark.

  • Accepts Utf8, LargeUtf8 and Utf8View. Like Spark, other types such as integers are rejected at planning time.

  • Adds serde as a direct dependency (already in the graph through serde_json) for the streaming array counter.

  • Documents the function with #[user_doc] and implements documentation(), following the guidelines in CONTRIBUTING.md (as in #58).
  • Known gaps


    Spark parses with a Jackson factory that enables single-quoted strings and unescaped control characters (JsonExpressionEvalUtils.SharedFactory, for Hive compatibility). serde_json rejects both, so json_array_length("['a','b']") is NULL here and 2 in Spark.

    Jackson (Spark 3.5+) also has stream limits that are not emulated here:

  • Nesting deeper than 1000 levels returns NULL in Spark. This implementation counts arrays of any depth.

  • A number literal longer than 1000 digits returns NULL in Spark. This implementation counts it.
  • These cases are commented-out queries in the .slt file with Spark's results. They stay open in #242.

    Testing


  • json/json_array_length.slt covers scalar and column input, all three string types, malformed nested elements, leading zeros, NaN, comments, trailing commas, multi-byte UTF-8, trailing content, and ANSI mode on and off. Expected values come from Spark's json-functions.sql.out or were checked against PySpark 4.2.0; the PySpark runner passes on the file.

  • cargo clippy --all-targets --all-features -- -D warnings, cargo test -p datafusion-spark and cargo test -p datafusion-spark-sqllogictest pass.
  • 🤖 Generated with Claude Code

    Diff: 247 lines (+185 / -62) across 3 files Reviewer: kosiew Review duration: 5599m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 247 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.330
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #71"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 38.9% (MEDIUM) · Higher = larger blast radius
    38.9%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.4% · Safe to merge
    15.4%