Skip to content
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
21 changes: 21 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4433,4 +4433,25 @@ TEST_F(TestDayTimeIntervalBuilder, TestConstructors) {
ASSERT_TRUE(builder3.type()->Equals(type));
}

TEST(ArrayTest, MakeEmptyPreservesDictionaryOrderedFlagInArray) {
auto dict_type = arrow::dictionary(arrow::int32(), arrow::utf8(), /*ordered=*/true);
auto schema = arrow::schema({arrow::field("col", dict_type)});

ASSERT_OK_AND_ASSIGN(auto batch, arrow::RecordBatch::MakeEmpty(schema));

ASSERT_EQ(batch->num_rows(), 0);
ASSERT_EQ(batch->num_columns(), 1);

// Schema should be correct
auto schema_type =
std::static_pointer_cast<arrow::DictionaryType>(batch->schema()->field(0)->type());
// Ensure array type preserves the ordered flag
auto array_type =
std::static_pointer_cast<arrow::DictionaryType>(batch->column(0)->type());

ASSERT_TRUE(schema_type->ordered());
ASSERT_TRUE(array_type->ordered()) << "MakeEmpty() lost ordered flag in array type";
ASSERT_TRUE(array_type->Equals(*schema_type));
}

} // namespace arrow
7 changes: 6 additions & 1 deletion cpp/src/arrow/array/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,12 @@ Result<std::shared_ptr<Array>> MakeEmptyArray(std::shared_ptr<DataType> type,
std::unique_ptr<ArrayBuilder> builder;
RETURN_NOT_OK(MakeBuilder(memory_pool, type, &builder));
RETURN_NOT_OK(builder->Resize(0));
return builder->Finish();
ARROW_ASSIGN_OR_RAISE(auto result, builder->Finish());
// Preserve original DictionaryType (including ordered flag)
if (type->id() == Type::DICTIONARY) {
result->data()->type = type;
}
return result;
}

namespace internal {
Expand Down
Loading