← Back to Pull requests

fix: parse_url handles relative references like java.net.URI #7392

Open
unknown opened this pull request with 545 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 01, 2026 23:07 UTC
Author

Which issue does this PR close?

Closes #7385.

Rationale for this change

Native parse_url / try_parse_url return NULL for every part of a URL without a scheme (/p?id=1, ?id=7, //host/p, notaurl). Spark's ParseUrl uses java.net.URI, which parses these as relative references, so with Comet enabled parse_url(page, 'QUERY', 'gclid') on logged page paths silently returns NULL instead of the value.

What changes are included in this PR?

In parse_url_component, the early return Ok(None) for scheme-less values is replaced by the two cases where java.net.URI actually rejects such a value:

  • a leading : (empty scheme name, "Expected scheme name at index 0") → INVALID_URL;

  • an empty authority with nothing after it (//, http://, "Expected authority") → INVALID_URL.
  • Everything else goes through the existing decompose_uri / part extraction, which already splits relative references per RFC 3986 Appendix B.

    Side effects, both matching Spark:

  • :// inside a relative URL's query (/r?to=http://x.com&id=1) no longer raises INVALID_URL.

  • http:// (scheme, empty authority, nothing else) used to return PROTOCOL http; it now raises INVALID_URL (ANSI) / returns NULL, as Spark does.
  • Not in scope: Comet's character validation (has_invalid_uri_chars) is narrower than java.net.URI's (e.g. |, a malformed % escape, a second #), and extract_host doesn't model registry-based authorities (//ex_ample.com/p). Those gaps already exist for absolute URLs and are tracked in #7330; with this change scheme-less inputs reach them too (Spark returns NULL for such inputs, Comet now returns parsed values instead of NULL).

    How are these changes tested?

  • SQL file tests (main coverage, compared against Spark): a table of 17 relative and edge-case URLs queried for every part and a QUERY key in parse_url.sql, plus relative and error cases in parse_url_ansi.sql. CometSqlFileTestSuite parse_url passes locally (Spark 4.1 profile) and fails on main at the new queries.

  • Rust unit tests in parse_url.rs for the changed branch: test_relative_reference (a few relative references per part, expectations from Spark 4.1.1) and test_invalid_relative_reference (:, :foo, ://missing-scheme, //, http://). Both fail on main; all existing spark-expr tests pass, cargo fmt and clippy -D warnings are clean.

  • Differential check (local only, not committed) of the native UDFs against Spark 4.1.1 try_parse_url + java.net.URI validity on ~110k generated URLs and ~40k real-world relative page paths (each also tried with a host prepended): no change in results for absolute URLs except the http://-style inputs above; relative references now match Spark except the inputs covered by #7330.

  • cargo bench --bench parse_url (main vs this branch): existing absolute-URL cases unchanged (all within ±4%). Scheme-less rows now do the normal extraction instead of returning early.
  • 🤖 Generated with Claude Code

    UPD: after review

  • Character validation now matches java.net.URI for relative and absolute URLs: ", \, ^, ` `, |, DEL and non-ASCII control or space characters, a % not followed by two hex digits, [ or ] in a hierarchical path, and a second # give INVALID_URL (ANSI) or NULL. This covers the character rows of #7330, so the "Not in scope" paragraph above no longer applies to them.

  • Scheme names are validated (user_id:5, 1http://… are invalid), and a scheme with nothing after the : (http:, http:#f) is invalid.

  • Opaque URIs (mailto:x, urn:isbn:123, http:p?id=1) return only PROTOCOL and REF, as Spark does.

  • Still not in scope: registry-based authorities in extract_host (//ex_ample.com/p, the host rows of #7330).

  • Tests: new test_parse_url_chars and test_parse_url_schemes tables in parse_url.sql and error cases in parse_url_ansi.sql. test_relative_reference and test_invalid_relative_reference were replaced by test_invisible_chars`, since the SQL files cover the rest. The differential run was repeated. All ~40k real relative paths, with and without a host prepended, match Spark 4.1.1. On the ~110k generated URLs, no row that matched before stops matching, and matching rows go from 61k to 96k. The remaining differences are in the authority, which is #7330.
  • Diff: 545 lines (+408 / -137) across 6 files Reviewer: comphead Review duration: 4358m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.48) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 545 lines diff across 6 files
    0.48
    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%
    42%
    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.377
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7392"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 48% (MEDIUM) · Higher = larger blast radius
    48%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 27.4% · Safe to merge
    27.4%