Skip to content

[core] Rebuild file index over the correct column after schema evolution - #10122

Open
jackylee-ch wants to merge 2 commits into
apache:masterfrom
jackylee-ch:core-fileindex-projection
Open

jackylee-ch wants to merge 2 commits into
apache:masterfrom
jackylee-ch:core-fileindex-projection

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

FileIndexProcessor (the rewrite_file_index procedure) rebuilds a data file's file index. It computes projectedIndexCols as the index columns' positions in the file schema and builds the writer with fileSchema.project(projectedIndexCols). But the reader used ReadBuilder.withProjection(projectedIndexCols), which ReadBuilderImpl resolves against the current table schema.

For a file whose schemaId differs from current, the spaces diverge once columns shift: [k, a, v] (bloom on v) → drop a, add w leaves v at file-index 2 while current-index 2 is now w. The reader then reads w (null-filled for the old file), so the bloom is rebuilt over nulls and a later v = 100 query silently prunes the file.

Fix: read with withReadType(fileSchema.project(projectedIndexCols)) — the writer's own file-schema projection — so reader and writer share the file's column space. Current-schema files are unchanged.

Tests

testRebuildsIndexOnCorrectColumnAfterColumnDropAndAdd: bloom on v in [k, a, v], write v=100, drop a, add w, rebuild, assert the v bloom still reports 100 present. Fails on master (wrong column → 100 absent); passes here.

FileIndexProcessor computes projectedIndexCols as the index columns' positions
in the file schema, and creates the index writer with
fileSchema.project(projectedIndexCols). The reader, however, was built with
ReadBuilder.withProjection(projectedIndexCols), which resolves the indices
against the current table schema. Once a schema change shifts column positions
(for example dropping a middle column and adding another), the file-schema index
no longer matches the table-schema index, so the reader returns a different
column and the file index is rebuilt over it. A later query on the indexed
column then silently prunes files that actually match.

Read the columns with withReadType(fileSchema.project(projectedIndexCols)), the
same file-schema projection the writer uses, so the reader and writer stay in
the file's own column space. rewrite_file_index reads a single data file whose
committed schema is that file schema, and file indexes are probed at query time
with predicates devolved to the file schema, so the per-file index must be built
in the file's column and type space.

The name-mapping half of schema evolution was added with the rewrite_file_index
procedure in apache#6562, but the reader projection was never aligned to it.
Map<String, String> options = new HashMap<>();
options.put(CoreOptions.BUCKET.key(), "1");
options.put(CoreOptions.FILE_FORMAT.key(), "parquet");
options.put(CoreOptions.FILE_INDEX + ".bloom-filter.columns", "v");

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.

non blocking
Could this test use  file-index.bitmap.columns  instead of a Bloom filter? A Bloom-filter positive is probabilistic, so  remain() == true  does not strictly prove that  100  was indexed from  v ; a false positive could allow the old wrong-column behavior to pass. The bitmap index returns an exact empty result for an absent value, making this regression deterministic while preserving the same schema-evolution scenario.

Switch the schema-evolution regression test from a bloom filter to a bitmap
index. A bloom-filter positive is probabilistic, so remain() == true does not
strictly prove the value was indexed from the correct column - a false positive
could let the old wrong-column behavior pass. A bitmap index returns an exact
empty result for an absent value, so the test now reads the (embedded) index and
asserts the indexed value is present while an absent value is not.
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