Skip to content

#768 Add replaceHivePartitionSchema method to support partition-level schema replacement in Hive helpers.#769

Merged
yruslan merged 2 commits into
mainfrom
feature/768-replace-partitoin-schema
Jun 26, 2026
Merged

#768 Add replaceHivePartitionSchema method to support partition-level schema replacement in Hive helpers.#769
yruslan merged 2 commits into
mainfrom
feature/768-replace-partitoin-schema

Conversation

@yruslan

@yruslan yruslan commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Closes #768

Summary by CodeRabbit

  • New Features

    • Added support for updating the schema of a specific Hive partition.
    • Expanded Hive template configuration to include a new partition-schema replacement option, with sensible defaults.
  • Bug Fixes

    • Improved handling of Hive SQL generation so partition schema changes are applied correctly.
    • Updated default and test configurations to stay aligned with the latest Hive template set.

…el schema replacement in Hive helpers.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@yruslan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 36 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73e114b5-e0ca-407b-ba6c-54e2b93adfeb

📥 Commits

Reviewing files that changed from the base of the PR and between 4808532 and 86ac755.

📒 Files selected for processing (3)
  • pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/MetaTableSuite.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/hive/HiveHelperSqlSuite.scala

Walkthrough

Adds Hive support for replacing partition schema, including a new query template and config field, a new helper method, SQL and Spark catalog implementations, and updated tests and fixtures.

Changes

Hive partition schema replacement support

Layer / File(s) Summary
Template config and defaults
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveQueryTemplates.scala, pramen/core/src/main/scala/za/co/absa/pramen/core/metastore/model/HiveConfig.scala, pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala, pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/MetaTableSuite.scala
HiveQueryTemplates gains replacePartitionSchemaTemplate, its config key, and default SQL; HiveConfig threads the value through its constructors, and the config tests update constructor expectations.
Helper API and SQL path
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelper.scala, pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSql.scala, pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/hive/HiveHelperSqlSuite.scala
HiveHelper adds replaceHivePartitionSchema; HiveHelperSql renders ALTER TABLE ... PARTITION (...) REPLACE COLUMNS (...) with @schema substitution and the suite checks the emitted SQL.
Spark catalog path
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSparkCatalog.scala
HiveHelperSparkCatalog adds the same partition-scoped replacement method, validates partition inputs, builds the partition clause, and executes the replacement DDL through Spark SQL.

Sequence Diagram(s)

sequenceDiagram
  participant HiveConfig
  participant HiveHelperSql
  participant QueryExecutor
  HiveConfig->>HiveHelperSql: provide replacePartitionSchemaTemplate
  HiveHelperSql->>HiveHelperSql: validate partitionBy and partitionValues
  HiveHelperSql->>HiveHelperSql: render partitionClause and `@schema`
  HiveHelperSql->>QueryExecutor: execute ALTER TABLE ... PARTITION (...) REPLACE COLUMNS (...)
Loading

Estimated review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • AbsaOSS/pramen#737: Adds the related table-scoped Hive schema replacement path and replaceHiveTableSchema wiring in the same template/helper area.

Poem

I hopped through Hive with a whisker and grin,
New partition schemas now slip neatly in.
@schema twinkled bright in the clover at night,
and the old little columns hopped off into light.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding partition-level schema replacement support.
Linked Issues check ✅ Passed The code adds the new partition schema replacement operation and wiring needed to support issue #768.
Out of Scope Changes check ✅ Passed The changes stay within the feature scope, with only supporting config and test updates around the new Hive operation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/768-replace-partitoin-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala (1)

32-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No assertion covers replacePartitionSchemaTemplate.

The constructor arg lists were extended, but none of these tests assert the new replacePartitionSchemaTemplate is threaded through fromConfigWithDefaults/fromDefaults (default fallback and override). Adding an assertion (e.g. in the "overridden config" case where replace.partition.schema.template is absent and should fall back to "replace_part1") would lock in the new wiring.

Also applies to: 83-83, 112-112

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala`
at line 32, Add test coverage for the new replacePartitionSchemaTemplate wiring
in HiveConfigSuite: the current assertions around fromConfigWithDefaults and
fromDefaults do not verify that the extra constructor arg is propagated. Update
the existing HiveQueryTemplates-based assertions to include
replacePartitionSchemaTemplate, and in the overridden config case assert that
when replace.partition.schema.template is missing it falls back to the expected
default value like "replace_part1".
pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSparkCatalog.scala (1)

107-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No test coverage for the Spark Catalog partition-schema path.

HiveHelperSqlSuite covers only the SQL helper. This HiveHelperSparkCatalog.replaceHivePartitionSchema implementation (which builds the clause and emits DEFAULT_REPLACE_PARTITION_SCHEMA) has no equivalent test, so a regression in clause/DDL construction here would go undetected. Consider adding a catalog-path test analogous to the SQL one.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSparkCatalog.scala`
around lines 107 - 133, Add test coverage for the Spark Catalog path in
HiveHelperSparkCatalog.replaceHivePartitionSchema, since the SQL helper suite
does not exercise this implementation. Create a catalog-path test analogous to
the existing HiveHelperSqlSuite case and assert the generated partition clause
and DEFAULT_REPLACE_PARTITION_SCHEMA SQL are built correctly when
SparkUtils.transformSchemaForCatalog and SparkUtils.escapeColumnsSparkDDL are
used. Focus the test around replaceHivePartitionSchema so regressions in clause
construction, schema filtering, or table-name rendering are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSparkCatalog.scala`:
- Around line 107-133: Add test coverage for the Spark Catalog path in
HiveHelperSparkCatalog.replaceHivePartitionSchema, since the SQL helper suite
does not exercise this implementation. Create a catalog-path test analogous to
the existing HiveHelperSqlSuite case and assert the generated partition clause
and DEFAULT_REPLACE_PARTITION_SCHEMA SQL are built correctly when
SparkUtils.transformSchemaForCatalog and SparkUtils.escapeColumnsSparkDDL are
used. Focus the test around replaceHivePartitionSchema so regressions in clause
construction, schema filtering, or table-name rendering are caught.

In
`@pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala`:
- Line 32: Add test coverage for the new replacePartitionSchemaTemplate wiring
in HiveConfigSuite: the current assertions around fromConfigWithDefaults and
fromDefaults do not verify that the extra constructor arg is propagated. Update
the existing HiveQueryTemplates-based assertions to include
replacePartitionSchemaTemplate, and in the overridden config case assert that
when replace.partition.schema.template is missing it falls back to the expected
default value like "replace_part1".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13b7d731-8282-4deb-9fc9-ec33e1cf039a

📥 Commits

Reviewing files that changed from the base of the PR and between 8e906a0 and 4808532.

📒 Files selected for processing (8)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/metastore/model/HiveConfig.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelper.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSparkCatalog.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSql.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveQueryTemplates.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/MetaTableSuite.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/hive/HiveHelperSqlSuite.scala

@github-actions

Copy link
Copy Markdown

Unit Test Coverage

Overall Project 76.83% -0.11% 🍏
Files changed 55.88%

Module Coverage
pramen:core Jacoco Report 77.81% -0.12%
Files
Module File Coverage
pramen:core Jacoco Report HiveConfig.scala 100% 🍏
HiveQueryTemplates.scala 98.7% -1.73% 🍏
HiveHelper.scala 88.68% 🍏
HiveHelperSql.scala 87.48% -3.55%
HiveHelperSparkCatalog.scala 69.04% -16.87%

@yruslan yruslan merged commit 1a06937 into main Jun 26, 2026
7 checks passed
@yruslan yruslan deleted the feature/768-replace-partitoin-schema branch June 26, 2026 13:13
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.

Add support for replacing partition schema Hive operation

1 participant