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
11 changes: 11 additions & 0 deletions be/src/core/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ class MutableBlock {
DataTypes _data_types;
std::vector<std::string> _names;

void materialize_const_column(size_t position) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Make the row-append APIs const-aware too

This helper is only called by the two merge paths, but MutableBlock::add_row() and both add_rows() overloads still append directly to _columns. Those destinations can also remain ColumnConst: for example, _partition_block() seeds a persistent buffer with in_block->clone_empty(), and ColumnConst::clone_resized(0) preserves the first block's nested value. After the first append, a later valid block with the same type but a different constant value is rejected by ColumnConst::insert_indices_from() (and a full source is also rejected by the sibling append methods). Please extend the shared append handling so both the destination and any const source are materialized, or are otherwise handled without assuming one per-block value persists across later blocks, and cover two add_rows() calls with different constants. Otherwise the same representation mismatch still breaks partitioned-join/local-exchange accumulation.

if (is_column_const(*_columns[position])) {
// ScopedMutableBlock can retain a const destination while merge materializes
// its source, so normalize the destination before appending full columns.
_columns[position] =
IColumn::mutate(_columns[position]->convert_to_full_column_if_const());
}
}

public:
// Build from a consumed Block. This has no restore contract: the source
// Block is left without columns and must not be used as a live output block.
Expand Down Expand Up @@ -587,6 +596,7 @@ class MutableBlock {
dump_names(), dump_types(), block.dump_names(),
block.dump_types());
}
materialize_const_column(i);
_columns[i]->insert_range_from_ignore_overflow(
*block.get_by_position(i).column->convert_to_full_column_if_const().get(), 0,
block.rows());
Expand Down Expand Up @@ -620,6 +630,7 @@ class MutableBlock {
block.dump_names(), block.dump_types());
}
for (int i = 0; i < _columns.size(); ++i) {
materialize_const_column(i);
if (!_data_types[i]->equals(*block.get_by_position(i).type)) {
DCHECK(_data_types[i]->is_nullable())
<< " target type: " << _data_types[i]->get_name()
Expand Down
31 changes: 31 additions & 0 deletions be/test/core/block/block_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,37 @@ TEST(BlockTest, merge_impl) {
EXPECT_ANY_THROW(st = mutable_block.merge_impl(std::move(block2)));
}

TEST(BlockTest, MergeMaterializesConstNullableDestination) {
for (bool ignore_overflow : {false, true}) {
auto nullable_type = make_nullable(std::make_shared<DataTypeInt64>());

auto const_data = nullable_type->create_column();
const_data->insert_default();
Block destination;
destination.insert(
{ColumnConst::create(std::move(const_data), 2), nullable_type, "lineage"});

auto source_column = nullable_type->create_column();
source_column->insert_default();
Block source;
source.insert({std::move(source_column), nullable_type, "lineage"});

{
ScopedMutableBlock scoped_destination(&destination);
auto status = ignore_overflow
? scoped_destination.mutable_block().merge_ignore_overflow(source)
: scoped_destination.mutable_block().merge(source);
ASSERT_TRUE(status.ok()) << status.to_string();
}

ASSERT_EQ(destination.rows(), 3);
EXPECT_FALSE(is_column_const(*destination.get_by_position(0).column));
for (size_t i = 0; i < destination.rows(); ++i) {
EXPECT_TRUE(destination.get_by_position(0).column->is_null_at(i));
}
}
}

TEST(BlockTest, ctor) {
TDescriptorTableBuilder builder;
TTupleDescriptorBuilder tuple_builder;
Expand Down
Loading