Skip to content

[GH-2983] Box3D SQL parser keyword + Geometry→Box3D cast resolution#3016

Open
jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-cast-resolution
Open

[GH-2983] Box3D SQL parser keyword + Geometry→Box3D cast resolution#3016
jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:feature/box3d-cast-resolution

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

  • Yes — closes #2983; follow-up to the Box3D Phase 1 epic (#2973).

What changes were proposed in this PR?

Adds the parser keyword and analyzer rule that let CAST(... AS box3d) resolve, mirroring the Box2D parser/cast support landed in #2927.

  • SedonaSqlAstBuilder.visitPrimitiveDataType recognises BOX3D alongside the existing GEOMETRY and BOX2D keywords, returning Box3DUDT. Applied uniformly to the spark-3.4 / 3.5 / 4.0 / 4.1 parser variants.
  • Box3DCastResolutionRule rewrites Cast(geom, Box3DUDT)ST_Box3D(geom) during analysis (before CheckAnalysis), since Spark's stock Cast.canCast refuses arbitrary UDT-to-UDT casts. Registered from SedonaSqlExtensions.injectResolutionRule.
  • Only the forward direction (CAST(geom AS box3d)) is wired. The inverse cast (CAST(box3d AS geometry)) is deferred until Box3D has an ST_GeomFromBox3D counterpart driven by a concrete consumer — Box2D shipped both directions because ST_GeomFromBox2D already existed, which is not the case here. The issue tracks this rationale.

How was this patch tested?

  • Box3DCastResolutionRuleSuite (rule unit test in spark/common) — verifies the forward rewrite, that the inverse Cast(box3d, Geometry) is left untouched (out of scope), and that unrelated casts are not affected.
  • Box3DCastSuite added per spark-3.4 / 3.5 / 4.0 / 4.1 — DataFrame .cast(Box3DUDT) plus SQL CAST(... AS box3d) end-to-end, gated on the parser-extension probe (matches the existing Box2DCastSuite pattern across the same four matrix cells).
  • All tests pass locally on spark-3.5 (3 rule + 6 cast).

Did this PR include necessary documentation updates?

…tion

Adds the parser keyword and analyzer rule that let `CAST(... AS box3d)`
resolve, mirroring the Box2D parser/cast support landed in apache#2927.

- `SedonaSqlAstBuilder.visitPrimitiveDataType` recognises `BOX3D`
  alongside the existing `GEOMETRY` and `BOX2D` keywords, returning
  `Box3DUDT`. Applied uniformly to the spark-3.4 / 3.5 / 4.0 / 4.1
  parser variants.
- `Box3DCastResolutionRule` rewrites `Cast(geom, Box3DUDT)` →
  `ST_Box3D(geom)` during analysis (before `CheckAnalysis`), since
  Spark's stock `Cast.canCast` refuses arbitrary UDT-to-UDT casts.
  Registered from `SedonaSqlExtensions.injectResolutionRule`.
- Only the forward direction (`CAST(geom AS box3d)`) is wired. The
  inverse cast (`CAST(box3d AS geometry)`) is deferred until Box3D
  has an `ST_GeomFromBox3D` counterpart driven by a concrete consumer
  — Box2D shipped both directions because `ST_GeomFromBox2D` already
  existed, which is not the case here.

Tests:
- `Box3DCastResolutionRuleSuite` (rule unit test) — covers the
  forward rewrite, leaves the inverse Cast untouched (out of scope),
  and leaves unrelated casts alone.
- `Box3DCastSuite` per spark-3.4 / 3.5 / 4.0 / 4.1 — DataFrame
  `.cast(Box3DUDT)` plus SQL `CAST(... AS box3d)` end-to-end,
  gated on the parser-extension probe (matches `Box2DCastSuite`'s
  pattern across the same four matrix cells).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant