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
3 changes: 2 additions & 1 deletion cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,9 @@ class FormatStringParser {

template <typename IntType = int32_t>
Result<std::vector<IntType>> ParseInts(std::string_view v) {
auto parts = Split(v);
std::vector<IntType> result;
if (v.empty()) return result;
auto parts = Split(v);
result.reserve(parts.size());
for (const auto& p : parts) {
ARROW_ASSIGN_OR_RAISE(auto i, ParseInt<IntType>(p));
Expand Down
24 changes: 24 additions & 0 deletions cpp/src/arrow/c/bridge_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,16 @@ TEST_F(TestSchemaExport, Union) {
auto type = dense_union({field_a, field_b}, {42, 43});
TestNested(type, {"+ud:42,43", "c", "b"}, {"", "a", "b"},
{ARROW_FLAG_NULLABLE, ARROW_FLAG_NULLABLE, 0});
TestNested(dense_union(arrow::FieldVector{}, std::vector<int8_t>{}), {"+ud:"}, {""},
{ARROW_FLAG_NULLABLE});
// Sparse
field_a = field("a", int8(), /*nullable=*/false);
field_b = field("b", boolean());
type = sparse_union({field_a, field_b}, {42, 43});
TestNested(type, {"+us:42,43", "c", "b"}, {"", "a", "b"},
{ARROW_FLAG_NULLABLE, 0, ARROW_FLAG_NULLABLE});
TestNested(sparse_union(arrow::FieldVector{}, std::vector<int8_t>{}), {"+us:"}, {""},
{ARROW_FLAG_NULLABLE});
}

std::string GetIndexFormat(Type::type type_id) {
Expand Down Expand Up @@ -2625,13 +2629,18 @@ TEST_F(TestSchemaRoundtrip, Struct) {
TestWithTypeFactory([&]() { return struct_({f1, f2}); });
f2 = f2->WithMetadata(key_value_metadata(kMetadataKeys2, kMetadataValues2));
TestWithTypeFactory([&]() { return struct_({f1, f2}); });
TestWithTypeFactory([&]() { return struct_(arrow::FieldVector{}); });
}

TEST_F(TestSchemaRoundtrip, Union) {
auto f1 = field("f1", utf8(), /*nullable=*/false);
auto f2 = field("f2", list(decimal(19, 4)));
auto type_codes = std::vector<int8_t>{42, 43};

TestWithTypeFactory(
[&]() { return dense_union(arrow::FieldVector{}, std::vector<int8_t>{}); });
TestWithTypeFactory(
[&]() { return sparse_union(arrow::FieldVector{}, std::vector<int8_t>{}); });
TestWithTypeFactory([&]() { return sparse_union({f1, f2}, type_codes); });
f2 = f2->WithMetadata(key_value_metadata(kMetadataKeys2, kMetadataValues2));
TestWithTypeFactory([&]() { return dense_union({f1, f2}, type_codes); });
Expand Down Expand Up @@ -2871,6 +2880,12 @@ TEST_F(TestArrayRoundtrip, Struct) {
TestWithJSON(type, "[[4, true], [5, null]]");

TestWithJSONSliced(type, "[[4, true], [5, null], [6, false]]");

// With no fields
type = struct_({});
TestWithJSON(type, "[]");
TestWithJSON(type, "[[], null, [], null, []]");
TestWithJSONSliced(type, "[[], null, [], null, []]");
}

TEST_F(TestArrayRoundtrip, Map) {
Expand Down Expand Up @@ -2898,6 +2913,15 @@ TEST_F(TestArrayRoundtrip, Union) {
TestWithJSON(type, json);
TestWithJSONSliced(type, json);
}

// With no fields
fields = {};
type_codes = {};
union_types = {sparse_union(fields, type_codes), dense_union(fields, type_codes)};

for (const auto& type : union_types) {
TestWithJSON(type, "[]");
}
}

TEST_F(TestArrayRoundtrip, Dictionary) {
Expand Down