Skip to content

#774 Make Hive table existence check configurable#775

Merged
yruslan merged 4 commits into
mainfrom
feature/774-configure-existence-check
Jul 9, 2026
Merged

#774 Make Hive table existence check configurable#775
yruslan merged 4 commits into
mainfrom
feature/774-configure-existence-check

Conversation

@yruslan

@yruslan yruslan commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added table.existence.check.strategy to choose how Hive checks table existence (metadata-based, describe-based, combined fallback, or SQL-query-based), with defaults applied when unset.
    • Existing Hive existence-check behavior now uses the selected strategy end-to-end, with fallback to the previous boolean setting if no strategy is provided.
  • Bug Fixes

    • Ensured the same existence-check strategy is consistently used across Hive JDBC execution paths.
  • Tests

    • Added/updated test coverage for strategy parsing, default/override behavior, and executor wiring.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f195000-f3ea-4b2e-a5c4-f3037d3b7bf7

📥 Commits

Reviewing files that changed from the base of the PR and between cc47dff and dc23a7a.

📒 Files selected for processing (4)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/runner/task/ThreadClosableRegistry.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/ExistenceCheckStrategy.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/metastore/model/HiveConfigSuite.scala
💤 Files with no reviewable changes (1)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/HiveHelperSql.scala
✅ Files skipped from review due to trivial changes (1)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/runner/task/ThreadClosableRegistry.scala
🚧 Files skipped from review as they are similar to previous changes (2)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/ExistenceCheckStrategy.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala

Walkthrough

Replaces boolean Hive existence-check flags with ExistenceCheckStrategy, threads the new strategy through Hive config parsing and JDBC execution, and updates the affected call sites and tests to use explicit strategy values.

Changes

ExistenceCheckStrategy migration

Layer / File(s) Summary
ExistenceCheckStrategy type and parser
pramen/core/.../hive/ExistenceCheckStrategy.scala, pramen/core/.../tests/utils/hive/ExistenceCheckStrategySuite.scala
Defines four existence-check strategies and a fromString parser; tests cover supported values and invalid input.
Hive config strategy wiring
pramen/core/.../metastore/model/HiveConfig.scala, HiveDefaultConfig.scala, pramen/core/.../metastore/model/HiveConfigSuite.scala
Moves Hive config from boolean existence-check flags to strategy fields, adds the new config key, resolves strategy values from config/defaults/fallbacks, and updates the config tests.
QueryExecutorJdbc strategy dispatch
pramen/core/.../utils/hive/QueryExecutorJdbc.scala, pramen/core/.../tests/utils/hive/QueryExecutorJdbcSuite.scala
Changes JDBC existence checking to pattern-match on ExistenceCheckStrategy and updates the executor tests to instantiate explicit strategies.
Downstream caller updates
pramen/core/.../utils/hive/HiveHelper.scala, pramen/extras/.../sink/StandardizationSink.scala
Passes the resolved strategy into QueryExecutorJdbc from Hive helper code and standardization sink code.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • AbsaOSS/pramen#721: Both PRs change Hive table-existence checking behavior in QueryExecutorJdbc and its wiring.
  • AbsaOSS/pramen#745: Both PRs update QueryExecutorJdbc existence checking to use Hive metadata with a DESCRIBE TABLE fallback.

Poem

Hoppity-hop, I bring a strategy basket,
Metadata, describe, or select—just ask it.
The old boolean flag has gone out of sight,
And Hive checks now choose their path just right. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, so the required Overview, Release Notes, and Related sections are missing. Add the repository template sections: Overview, Release Notes, and Related, with a brief summary and the linked issue number.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making Hive table existence checks configurable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/774-configure-existence-check

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/main/scala/za/co/absa/pramen/core/utils/hive/ExistenceCheckStrategy.scala (1)

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

Make ExistenceCheckStrategy a sealed trait for compile-time exhaustiveness.

All four case objects are defined in this same file, so sealing the trait is trivial. Without sealed, the pattern match in QueryExecutorJdbc.doesTableExist (lines 40–53) is not exhaustiveness-checked — adding a new strategy elsewhere would cause a runtime MatchError instead of a compile-time error.

♻️ Proposed change
-sealed trait ExistenceCheckStrategy
+sealed trait ExistenceCheckStrategy
🤖 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/ExistenceCheckStrategy.scala`
around lines 19 - 40, Make ExistenceCheckStrategy a sealed trait so the compiler
can verify exhaustiveness across the case objects defined in
ExistenceCheckStrategy and the pattern match in
QueryExecutorJdbc.doesTableExist. Update the trait declaration to sealed,
keeping the existing case objects and fromString logic unchanged, so any future
strategy additions must be handled at compile time instead of risking a
MatchError at runtime.
pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala (1)

56-110: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a test for the optimize.exist.query = falseSelectQuery fallback path.

The existing "overridden config" test sets both optimize.exist.query = false and table.existence.check.strategy = "describe_table", which verifies strategy-over-boolean precedence. However, no test covers the case where only optimize.exist.query = false is set without a strategy — the key backward-compatibility path that should yield SelectQuery.

🧪 Suggested test case
"return SelectQuery when optimize.exist.query is false and no strategy is specified" in {
  val conf = ConfigFactory.parseString(
    """conf {
      |   optimize.exist.query = false
      |}
      |""".stripMargin)

  val defaultConfig = HiveDefaultConfig(
    HiveApi.Sql,
    Some("mydb1"),
    Map("parquet" -> HiveQueryTemplates("create1", "create_only1", "replace1", "replace_part1", "repair1", "add_partition1", "drop1")),
    None,
    ignoreFailures = false,
    alwaysEscapeColumnNames = false,
    optimizeExistQuery = true,
    tableExistenceCheckStrategy = None
  )

  val hiveConfig = HiveConfig.fromConfigWithDefaults(conf, defaultConfig, DataFormat.Parquet("dummy"))

  assert(hiveConfig.existenceCheckStrategy == ExistenceCheckStrategy.SelectQuery)
}
🤖 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`
around lines 56 - 110, Add a focused test in HiveConfigSuite for the
backward-compatibility path where only conf.optimize.exist.query is set to false
and no table.existence.check.strategy is provided; use
HiveConfig.fromConfigWithDefaults and assert that the resulting
existenceCheckStrategy resolves to ExistenceCheckStrategy.SelectQuery. Keep the
existing overridden config test as-is since it already covers strategy
precedence, and add a separate test case near it so the fallback behavior is
explicitly validated.
🤖 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/ExistenceCheckStrategy.scala`:
- Around line 19-40: Make ExistenceCheckStrategy a sealed trait so the compiler
can verify exhaustiveness across the case objects defined in
ExistenceCheckStrategy and the pattern match in
QueryExecutorJdbc.doesTableExist. Update the trait declaration to sealed,
keeping the existing case objects and fromString logic unchanged, so any future
strategy additions must be handled at compile time instead of risking a
MatchError at runtime.

In
`@pramen/core/src/test/scala/za/co/absa/pramen/core/metastore/model/HiveConfigSuite.scala`:
- Around line 56-110: Add a focused test in HiveConfigSuite for the
backward-compatibility path where only conf.optimize.exist.query is set to false
and no table.existence.check.strategy is provided; use
HiveConfig.fromConfigWithDefaults and assert that the resulting
existenceCheckStrategy resolves to ExistenceCheckStrategy.SelectQuery. Keep the
existing overridden config test as-is since it already covers strategy
precedence, and add a separate test case near it so the fallback behavior is
explicitly validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96125971-3132-4b92-9013-3e50e46600cd

📥 Commits

Reviewing files that changed from the base of the PR and between de2a314 and cc47dff.

📒 Files selected for processing (10)
  • pramen/core/src/main/scala/za/co/absa/pramen/core/metastore/model/HiveConfig.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/metastore/model/HiveDefaultConfig.scala
  • pramen/core/src/main/scala/za/co/absa/pramen/core/utils/hive/ExistenceCheckStrategy.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/QueryExecutorJdbc.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/ExistenceCheckStrategySuite.scala
  • pramen/core/src/test/scala/za/co/absa/pramen/core/tests/utils/hive/QueryExecutorJdbcSuite.scala
  • pramen/extras/src/main/scala/za/co/absa/pramen/extras/sink/StandardizationSink.scala

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Unit Test Coverage

Overall Project 76.84% -0.14% 🍏
Files changed 66.29%

Module Coverage
pramen:core Jacoco Report 77.82% -0.14%
pramen-extras Jacoco Report 66.07% -0.14%
Files
Module File Coverage
pramen:core Jacoco Report HiveDefaultConfig.scala 100% -4.55% 🍏
ExistenceCheckStrategy.scala 100%
HiveConfig.scala 98.48% -1.52% 🍏
HiveHelper.scala 88.68% 🍏
ThreadClosableRegistry.scala 87.5% 🍏
HiveHelperSql.scala 87.48% 🍏
QueryExecutorJdbc.scala 78.48% -2.67%
pramen-extras Jacoco Report StandardizationSink.scala 82.98% -1.25%

@yruslan
yruslan merged commit 61e85d7 into main Jul 9, 2026
7 checks passed
@yruslan
yruslan deleted the feature/774-configure-existence-check branch July 9, 2026 11:57
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