Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-44714: [C++] Keep field metadata for keys and values when importing a map type via the C data interface #44715

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1310,13 +1310,13 @@ struct SchemaImporter {
}

bool keys_sorted = (c_struct_->flags & ARROW_FLAG_MAP_KEYS_SORTED);
bool values_nullable = value_type->field(1)->nullable();

// Some implementations of Arrow (such as Rust) use a non-standard field name
// for key ("keys") and value ("values") fields. For simplicity, we override
// them on import.
auto values_field =
::arrow::field("value", value_type->field(1)->type(), values_nullable);
type_ = map(value_type->field(0)->type(), values_field, keys_sorted);
type_ =
std::make_shared<MapType>(value_type->field(0)->WithName("key"),
value_type->field(1)->WithName("value"), keys_sorted);
return Status::OK();
}

Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/c/bridge_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,10 @@ TEST_F(TestSchemaRoundtrip, RegisteredExtension) {
TEST_F(TestSchemaRoundtrip, Map) {
TestWithTypeFactory([&]() { return map(utf8(), int32()); });
TestWithTypeFactory([&]() { return map(utf8(), field("value", int32(), false)); });
TestWithTypeFactory([&]() {
return map(utf8(), field("value", int32(), false,
KeyValueMetadata::Make({"meta key"}, {"meta value"})));
});
// Field names are brought in line with the spec on import.
TestWithTypeFactory(
[&]() {
Expand Down
Loading