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

Fix make_column_from_scalar for all-null strings column #11807

Merged
15 changes: 6 additions & 9 deletions cpp/src/column/column_factories.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ std::unique_ptr<cudf::column> column_from_scalar_dispatch::operator()<cudf::stri
rmm::mr::device_memory_resource* mr) const
{
if (size == 0) return make_empty_column(value.type());
auto null_mask = detail::create_null_mask(size, mask_state::ALL_NULL, stream, mr);

if (!value.is_valid(stream))
return std::make_unique<column>(
value.type(), size, rmm::device_buffer{}, std::move(null_mask), size);

// Create a strings column_view with all nulls and no children.
// Since we are setting every row to the scalar, the fill() never needs to access
// any of the children in the strings column which would otherwise cause an exception.
column_view sc{
data_type{type_id::STRING}, size, nullptr, static_cast<bitmask_type*>(null_mask.data()), size};
column_view sc{value.type(), size, nullptr};
davidwendt marked this conversation as resolved.
Show resolved Hide resolved
auto& sv = static_cast<scalar_type_t<cudf::string_view> const&>(value);

// fill the column with the scalar
auto output = strings::detail::fill(strings_column_view(sc), 0, size, sv, stream, mr);
output->set_null_mask(rmm::device_buffer{}, 0); // should be no nulls

// remove the null-mask if the scalar is valid
davidwendt marked this conversation as resolved.
Show resolved Hide resolved
if (value.is_valid(stream)) { output->set_null_mask(rmm::device_buffer{}, 0); }

return output;
}

Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/column/factories_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ TEST_F(ColumnFactoryTest, FromStringScalar)
EXPECT_EQ(0, column->null_count());
EXPECT_FALSE(column->nullable());
EXPECT_FALSE(column->has_nulls());
EXPECT_TRUE(column->num_children() > 0);
}

TEST_F(ColumnFactoryTest, FromNullStringScalar)
Expand All @@ -434,6 +435,7 @@ TEST_F(ColumnFactoryTest, FromNullStringScalar)
EXPECT_EQ(2, column->null_count());
EXPECT_TRUE(column->nullable());
EXPECT_TRUE(column->has_nulls());
EXPECT_TRUE(column->num_children() > 0);
}

TEST_F(ColumnFactoryTest, FromStringScalarWithZeroSize)
Expand Down