Skip to content

[core][flink][spark] Drop selected column stats during manifest compaction - #11654

Open
zhoulii wants to merge 4 commits into
apache:masterfrom
zhoulii:compact-manifest-drop-stats
Open

zhoulii wants to merge 4 commits into
apache:masterfrom
zhoulii:compact-manifest-drop-stats

Conversation

@zhoulii

@zhoulii zhoulii commented Dec 3, 2026

Copy link
Copy Markdown
Member

Purpose

Wide tables can accumulate large column statistics in manifests, making metadata scans such as $partitions expensive. Changing stats-collection settings does not remove existing statistics.

Add optional drop_stats_columns to compact_manifest for Flink/Spark and the Flink action. It removes selected value statistics without rewriting data files, using streaming reads/writes and the existing statistics format.

CALL sys.compact_manifest(
  `table` => 'default.T',
  drop_stats_columns => 'payload,raw_text');

Key/partition statistics and historical snapshots/tags are preserved. Default behavior is unchanged; removing statistics may reduce file pruning.

In a local synthetic sample with 8,000 files and 300 STRING stats columns, removing 290 columns reduced current-snapshot manifests from 6.286 MiB to 0.255 MiB (95.9%).

Tests

42 related tests passed, covering append, primary-key, and Data Evolution tables, schema evolution, failure cleanup, and removal beyond the sort rewrite limit. Formatting, license, and repository checks passed.

@JingsongLi JingsongLi 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.

Two inline comments on TTL validation and row-tracked append files.

checkArgument(
!SpecialFields.isSystemField(field.id()), "Cannot drop system column stats.");
checkArgument(
!name.equals(options.recordLevelTimeField()),

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.

Protect the persisted TTL field

This guard uses the options for the current call. On a primary-key table configured with record-level.time-field=event_time, passing options => 'record-level.time-field=ingest_time' and drop_stats_columns => 'event_time' removes the stats for the table's TTL field. A later full compaction with the persisted options can skip max-level files containing expired rows because RecordLevelExpire.isExpireFile returns false when the minimum is missing. Please validate against the target branch's latest persisted TTL field in both the rewrite and the dry run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. Both rewrite and dry run now protect the target branch’s latest persisted TTL field. Added regression tests for option overrides, stale table instances, and branch-specific settings.

key ->
schemaLoader
.apply(key.getLeft())
.dataFileSchema(key.getRight())

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.

Resolve row-tracking columns in the physical file schema

On a regular append table with row-tracking.enabled=true, data compaction can produce files whose writeCols include _ROW_ID and _SEQUENCE_NUMBER. Projecting those names from the historical table schema throws ArrayIndexOutOfBoundsException during the stats probe, so compact_manifest fails even when dropping stats for a user column. Please resolve the stats positions against the historical physical file schema, including the stored row-tracking fields.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. Stats projection now includes stored row-tracking fields in the historical file schema. Added dense/sparse regression tests covering append compaction and column renaming, verifying retained stats and row-tracking values are preserved.

@zhoulii
zhoulii force-pushed the compact-manifest-drop-stats branch from 35756aa to 4942c41 Compare December 3, 2026 06:06
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.

2 participants