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 cudf::strings::findall error with empty input #16928

Merged
merged 1 commit into from
Sep 26, 2024
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
10 changes: 7 additions & 3 deletions cpp/src/strings/search/findall.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/offsets_iterator_factory.cuh>
#include <cudf/lists/detail/lists_column_factories.hpp>
#include <cudf/strings/detail/strings_column_factories.cuh>
#include <cudf/strings/findall.hpp>
#include <cudf/strings/string_view.cuh>
Expand Down Expand Up @@ -97,8 +98,11 @@ std::unique_ptr<column> findall(strings_column_view const& input,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
auto const strings_count = input.size();
auto const d_strings = column_device_view::create(input.parent(), stream);
if (input.is_empty()) {
return cudf::lists::detail::make_empty_lists_column(input.parent().type(), stream, mr);
}

auto const d_strings = column_device_view::create(input.parent(), stream);

// create device object from regex_program
auto d_prog = regex_device_builder::create_prog_device(prog, stream);
Expand All @@ -113,7 +117,7 @@ std::unique_ptr<column> findall(strings_column_view const& input,
auto strings_output = findall_util(*d_strings, *d_prog, total_matches, d_offsets, stream, mr);

// Build the lists column from the offsets and the strings
return make_lists_column(strings_count,
return make_lists_column(input.size(),
std::move(offsets),
std::move(strings_output),
input.null_count(),
Expand Down
28 changes: 28 additions & 0 deletions cpp/tests/strings/findall_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,31 @@ TEST_F(StringsFindallTests, LargeRegex)
LCW expected({LCW{large_regex.c_str()}, LCW{}, LCW{}});
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(results->view(), expected);
}

TEST_F(StringsFindallTests, NoMatches)
{
cudf::test::strings_column_wrapper input({"abc\nfff\nabc", "fff\nabc\nlll", "abc", "", "abc\n"});
auto sv = cudf::strings_column_view(input);

auto pattern = std::string("(^zzz$)");
using LCW = cudf::test::lists_column_wrapper<cudf::string_view>;
LCW expected({LCW{}, LCW{}, LCW{}, LCW{}, LCW{}});
auto prog = cudf::strings::regex_program::create(pattern);
auto results = cudf::strings::findall(sv, *prog);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(results->view(), expected);
}

TEST_F(StringsFindallTests, EmptyTest)
{
std::string pattern = R"(\w+)";

auto prog = cudf::strings::regex_program::create(pattern);

cudf::test::strings_column_wrapper input;
auto sv = cudf::strings_column_view(input);
auto results = cudf::strings::findall(sv, *prog);

using LCW = cudf::test::lists_column_wrapper<cudf::string_view>;
LCW expected;
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(results->view(), expected);
}
Loading