Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/paimon/core/io/field_mapping_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ FieldMappingReader::FieldMappingReader(int32_t field_count,
if (non_partition_info_.cast_executors[i] != nullptr) {
need_casting_ = true;
}
// Field name change (RENAME COLUMN) also requires mapping: data schema
// carries the file's physical name while read schema carries the
// post-rename logical name. If we skipped mapping, the inner reader's
// batch would be passed through with the old physical name and the
// consumer's name-based lookup against the read schema would fail.
if (non_partition_info_.non_partition_data_schema[i].Name() !=
non_partition_info_.non_partition_read_schema[i].Name()) {
need_mapping_ = true;
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/paimon/core/io/field_mapping_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,47 @@ TEST_F(FieldMappingReaderTest, TestReadWithSchemaEvolutionWithRenameAndModifyTyp
CheckResult(read_schema, /*predicate=*/nullptr, expect_data);
}

TEST_F(FieldMappingReaderTest, TestReadWithSchemaEvolutionPureRename) {
// Regression: pure RENAME (same field ids, same types, identity order, no
// partition / non-exist) used to leave need_mapping_ false, taking the
// FieldMappingReader PASSTHRU path. The inner reader's batch was emitted
// unchanged carrying the file's physical column names, so a consumer that
// looked columns up by name against the read schema (post-rename logical
// names) failed to find them.

// File schema: physical names f0, f1
std::vector<DataField> data_fields = {DataField(0, arrow::field("f0", arrow::utf8())),
DataField(1, arrow::field("f1", arrow::int32()))};
auto data_schema = DataField::ConvertDataFieldsToArrowSchema(data_fields);
auto data_array = std::dynamic_pointer_cast<arrow::StructArray>(
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_({data_schema->fields()}),
R"([
["Alice", 1],
["Bob", 2],
["Carol", 3]
])")
.ValueOrDie());

// Read schema: same field ids, RENAMED names, same types, identity order
std::vector<DataField> read_fields = {DataField(0, arrow::field("name_new", arrow::utf8())),
DataField(1, arrow::field("age_new", arrow::int32()))};
auto read_schema = DataField::ConvertDataFieldsToArrowSchema(read_fields);

// Expected output uses the post-rename names; verifies mapping actually
// ran (PASSTHRU would keep f0/f1 and Equals would fail).
auto expected = std::dynamic_pointer_cast<arrow::StructArray>(
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_({read_schema->fields()}),
R"([
["Alice", 1],
["Bob", 2],
["Carol", 3]
])")
.ValueOrDie());

CheckResult(data_schema, data_array, read_schema, /*predicate=*/nullptr,
/*partition_keys=*/{}, BinaryRow::EmptyRow(), expected);
}

TEST_F(FieldMappingReaderTest, TestReadWithSchemaEvolutionWithRenameAndModifyTypeAndPredicate) {
// field_0 and field_3 are rename and modify type
// result is not filtered by predicate, as DOUBLE->STRING alter table does not support predicate
Expand Down
Loading