Skip to content

HIVE-29265: Columns failed stats computation still marked as COLUMN_STATS_ACCURATE#6576

Open
cyanzheng2926 wants to merge 5 commits into
apache:masterfrom
cyanzheng2926:HIVE-29265_stale_stats_marked_accurate
Open

HIVE-29265: Columns failed stats computation still marked as COLUMN_STATS_ACCURATE#6576
cyanzheng2926 wants to merge 5 commits into
apache:masterfrom
cyanzheng2926:HIVE-29265_stale_stats_marked_accurate

Conversation

@cyanzheng2926

@cyanzheng2926 cyanzheng2926 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

/<!--
Thanks for sending a pull request! Here are some tips for you:

  1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
  2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
  3. Ensure you have added or run the appropriate tests for your PR:
  4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
  5. Be sure to keep the PR description updated to reflect all changes.
  6. Please write your PR title to summarize what this PR proposes.
  7. If possible, provide a concise example to reproduce the issue for a faster review.

-->

What changes were proposed in this pull request?

When stats collection is skipped for some columns with hive.stats.reliable=false, no stats are written to the metastore, but COLUMN_STATS_ACCURATE still remains "true" for these columns.
Updated ColStatsProcessor to track for columns that failed stats gathering due to such errors, and remove the stale accurate markers for these columns.

Note on limitations:

  • Non-native partitioned tables (e.g. Iceberg) only table-level cleanup is done, since currently there is no storage-handler API to clear partition-level COLUMN_STATS_ACCURATE.

Why are the changes needed?

Column stats collection can fail for individual columns (e.g. UnsupportedDoubleException with Infinity/NaN). With hive.stats.reliable=false the failure is logged and skipped, but still leaves COLUMN_STATS_ACCURATE claiming those columns are accurate even though no stats were stored. The optimizer may use non-existent stats and produce suboptimal or incorrect plans as a result.

Does this PR introduce any user-facing change?

Yes.
Before: After a partial or total column-stats failure, DESCRIBE FORMATTED

could show COLUMN_STATS_ACCURATE with "column":"true" even when COLUMN_STATS was missing for that column.

After: Failed columns are removed from COLUMN_STATS_ACCURATE. Only columns with successfully collected stats remain marked accurate.

How was this patch tested?

Added qtest: stats_col_stats_inaccurate.q and corresponding golden, test for multiple cases when certain columns of partitioned/non-partitioned tables fail at stats gathering with Infinity/NaN, and desc formatted output should not return COLUMN_STATS_ACCURATE markers for these columns

…ats collection fails

When column stats collection is skipped (e.g. UnsupportedDoubleException for
Inf/NaN in float/double min/max stats), failed columns were still makred as true in COLUMN_STATS_ACCURATE even though stats are not present.

Track per-table/partition column failures in ColStatsProcessor and remove incorrect accurate markers via alterTable and alterPartitions.
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

Copilot AI 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.

Pull request overview

This PR addresses a correctness bug in Hive column statistics collection where columns that fail stats gathering (when hive.stats.reliable=false) could remain marked as accurate in COLUMN_STATS_ACCURATE, causing the optimizer to treat missing/invalid stats as usable.

Changes:

  • Track per-column stats-collection failures during ColStatsProcessor execution and remove stale COLUMN_STATS_ACCURATE markers for failed columns (table-level and native HMS partitions).
  • Add a new qtest (stats_col_stats_inaccurate.q) and golden output validating COLUMN_STATS_ACCURATE cleanup for Infinity/NaN-induced failures.
  • Update existing qtest output (columnstats_infinity.q.out) to reflect the corrected COLUMN_STATS_ACCURATE contents.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
ql/src/java/org/apache/hadoop/hive/ql/stats/ColStatsProcessor.java Tracks failed columns and clears stale COLUMN_STATS_ACCURATE markers (table/partition where supported).
ql/src/test/queries/clientpositive/stats_col_stats_inaccurate.q New test query covering partial/total column-stats failures across partitioned/non-partitioned tables.
ql/src/test/results/clientpositive/llap/stats_col_stats_inaccurate.q.out New golden output validating corrected DESCRIBE FORMATTED/COLUMN_STATS_ACCURATE behavior.
ql/src/test/results/clientpositive/llap/columnstats_infinity.q.out Adjust golden output to match corrected COLUMN_STATS_ACCURATE after failure cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

describe formatted stats_t1 partition(p=1);


-- Check non-partitioned tables on flout/double columns with Infinity/NaN on inaccurate stats.
Comment on lines +247 to +251
if (tbl.isNonNative() && tbl.getStorageHandler().canSetColStatistics(tbl)) {
if (!(tbl.isMaterializedView() || tbl.isView() || tbl.isTemporary())) {
setOrRemoveColumnStatsAccurateProperty(db, tbl, failedColumns, false);
}
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants