Skip to content
Closed
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
16 changes: 16 additions & 0 deletions cpp/src/parquet/arrow/arrow_reader_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,22 @@ TEST(TestArrowReadWrite, DictionaryIndexBitwidthRoundtrip) {
}
}

TEST(TestArrowReadWrite, DictionaryValueTypeRoundtrip) {
// GH-37875: the binary layout of dictionary values should be preserved
for (const auto& value_type : {::arrow::utf8(), ::arrow::large_utf8(),
::arrow::binary(), ::arrow::large_binary()}) {
ARROW_SCOPED_TRACE("value_type = ", *value_type);
auto dict_type = ::arrow::dictionary(::arrow::int32(), value_type);
auto schema = ::arrow::schema({field("dictionary", dict_type)});
auto array = DictArrayFromJSON(dict_type, R"([0, 1, null, 0])", R"(["foo", "bar"])");
auto table = Table::Make(schema, {array});
auto arrow_writer_props =
parquet::ArrowWriterProperties::Builder().store_schema()->build();

CheckSimpleRoundtrip(table, table->num_rows(), arrow_writer_props);
}
}

TEST(TestArrowWrite, CheckChunkSize) {
const int num_columns = 2;
const int num_rows = 128;
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/parquet/arrow/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,17 @@ Result<bool> ApplyOriginalStorageMetadata(const Field& origin_field,
// so no need to recurse on value types.
const auto& dict_origin_type =
checked_cast<const ::arrow::DictionaryType&>(*origin_type);
auto value_type = inferred_type;
const auto& origin_value_type = dict_origin_type.value_type();
// Restore large dictionary values (GH-37875)
if ((origin_value_type->id() == ::arrow::Type::LARGE_STRING &&
inferred_type->id() == ::arrow::Type::STRING) ||
(origin_value_type->id() == ::arrow::Type::LARGE_BINARY &&
inferred_type->id() == ::arrow::Type::BINARY)) {
value_type = origin_value_type;
}
inferred->field = inferred->field->WithType(::arrow::dictionary(
dict_origin_type.index_type(), inferred_type, dict_origin_type.ordered()));
dict_origin_type.index_type(), value_type, dict_origin_type.ordered()));
modified = true;
}

Expand Down
Loading