Skip to content

Commit

Permalink
Set the flag of Arrow MapVector to not-nullable in Bridge.cpp
Browse files Browse the repository at this point in the history
Verify MapVector schema is not null in ArrowBridgeSchemaTest.cpp
  • Loading branch information
whutjs committed Oct 15, 2024
1 parent acd5717 commit 244462e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion velox/vector/arrow/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace {
// and one for offsets (2).
static constexpr size_t kMaxBuffers{3};

void clearNullableFlag(int64_t& flags) {
flags = flags & (~ARROW_FLAG_NULLABLE);
}

// Structure that will hold the buffers needed by ArrowArray. This is opaquely
// carried by ArrowArray.private_data
class VeloxToArrowBridgeHolder {
Expand Down Expand Up @@ -1384,7 +1388,7 @@ void exportToArrow(
// No additional metadata for now.
arrowSchema.metadata = nullptr;

// All supported types are semantically nullable.
// All supported types except map are semantically nullable.
arrowSchema.flags = ARROW_FLAG_NULLABLE;

// Allocate private data buffer holder and recurse down to children types.
Expand Down Expand Up @@ -1447,6 +1451,10 @@ void exportToArrow(
maps.getNullCount());
exportToArrow(rows, *child, options);
child->name = "entries";
// Map data should be a non-nullable struct type
clearNullableFlag(child->flags);
// Map data key type should be a non-nullable
clearNullableFlag(child->children[0]->flags);
bridgeHolder->setChildAtIndex(0, std::move(child), arrowSchema);

} else if (type->kind() == TypeKind::ARRAY) {
Expand Down
5 changes: 5 additions & 0 deletions velox/vector/arrow/tests/ArrowBridgeSchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class ArrowBridgeSchemaExportTest : public testing::Test {
EXPECT_STREQ("+m", schema->format);
ASSERT_EQ(schema->n_children, 1);
schema = schema->children[0];
// Map data should be a non-nullable struct type
ASSERT_EQ(schema->flags & ARROW_FLAG_NULLABLE, 0);
ASSERT_EQ(schema->n_children, 2);
// Map data key type should be a non-nullable
ASSERT_EQ(schema->children[0]->flags & ARROW_FLAG_NULLABLE, 0);
} else if (type->kind() == TypeKind::ROW) {
EXPECT_STREQ("+s", schema->format);
}
Expand Down

0 comments on commit 244462e

Please sign in to comment.