Skip to content

Spark: enforce Hive layout for LOCATION and disable iceberg table rename#1

Open
anandnalya wants to merge 3 commits into
1.10.1from
feat/spark-location-allowlist
Open

Spark: enforce Hive layout for LOCATION and disable iceberg table rename#1
anandnalya wants to merge 3 commits into
1.10.1from
feat/spark-location-allowlist

Conversation

@anandnalya

@anandnalya anandnalya commented Apr 29, 2026

Copy link
Copy Markdown

Summary

  • Validate user-supplied LOCATION on CREATE TABLE, CTAS, RTAS, stage variants, and ALTER TABLE SET LOCATION: for table <db>.<table> the path must end with <db>.db/<base> or <db>.db/<base>_new, where <base> is the identifier name with any trailing _new suffix stripped. Null/empty pass through so the catalog default applies.
  • The _new allowance supports swap-via-rename rebuild workflows in both directions: a sibling <table>_new staging directory next to <table>, or an Iceberg table named <table>_new that already points at the canonical <table> location and is later renamed in the catalog (the pattern used by Proteus's IcebergFullReplacePartitioned.handleSchemaEvolution).
  • Disable iceberg table renames in SparkSessionCatalog since renames would invalidate the layout invariant.
  • Applied to spark/v3.4, v3.5, v4.0. Based on apache-iceberg-1.10.1.

Test plan

  • TestLocationLayoutValidator (17 unit tests, including 3 covering the canonical/_new/_new_new cases for _new-suffixed identifiers) passes on v3.4/v3.5/v4.0
  • TestSparkCatalogLocationLayout (6 integration tests covering CREATE/CTAS/RTAS/ALTER reject paths, the _new-identifier reject message, and null pass-through) passes on v3.5/v4.0
  • TestSparkSessionCatalogRename (1 integration test for rename rejection) passes on v3.5/v4.0
  • v3.4 integration tests not run locally due to a pre-existing Spark 3.4 + JDK 21 incompatibility (DirectByteBuffer.<init>(long, int)) that affects every TestBase-derived test in v3.4 — unrelated to these changes; runs cleanly on JDK 11/17.
  • Smoke test in a real Spark + HMS deployment before promoting.

For tables of the form `<db>.<table>`, validate that any user-supplied LOCATION ends with `<db>.db/<table>`. Validation runs on CREATE TABLE, CTAS, RTAS, stage variants, and ALTER TABLE SET LOCATION; null/empty pass through so the catalog default applies. Also disable iceberg table renames in SparkSessionCatalog since renames invalidate the layout invariant. Applied to spark/v3.4, v3.5, v4.0.
Accept '<db>.db/<table>_new' alongside '<db>.db/<table>' to support rebuild/swap workflows where a replacement table is staged under a sibling directory before being promoted. Applied to spark/v3.4, v3.5, v4.0.
…nLayoutValidator

Strip a trailing _new suffix from the identifier name to derive a canonical base, then accept locations ending in <db>.db/<base> or <db>.db/<base>_new. This supports swap-via-rename rebuild workflows where the staging table is named <table>_new but already points at the canonical <table> location before being renamed in the catalog. Existing Hive layout and sibling-directory rebuild allowances are unchanged.
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