-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for large string columns to Parquet reader and writer (#1…
…5632) Part of #13733. Adds support for reading and writing cuDF string columns where the string data exceeds 2GB. This is accomplished by skipping the final offsets calculation in the string decoding kernel when the 2GB threshold is exceeded, and instead uses `cudf::strings::detail::make_offsets_child_column()`. This could lead to increased overhead with many columns (see #13024), so this will need some more benchmarking. But if there are many columns that exceed the 2GB limit, it's likely reads will have to be chunked to stay within the memory budget. Authors: - Ed Seidl (https://github.com/etseidl) - Vukasin Milovanovic (https://github.com/vuule) Approvers: - Bradley Dice (https://github.com/bdice) - Muhammad Haseeb (https://github.com/mhaseeb123) - David Wendt (https://github.com/davidwendt) - Vukasin Milovanovic (https://github.com/vuule) URL: #15632
- Loading branch information
Showing
11 changed files
with
200 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "column_buffer.hpp" | ||
|
||
#include <cudf/strings/detail/strings_children.cuh> | ||
#include <cudf/strings/detail/utilities.hpp> | ||
#include <cudf/utilities/error.hpp> | ||
|
||
namespace cudf::io::detail { | ||
|
||
std::unique_ptr<column> cudf::io::detail::inline_column_buffer::make_string_column_impl( | ||
rmm::cuda_stream_view stream) | ||
{ | ||
// if the size of _string_data is over the threshold for 64bit size_type, _data will contain | ||
// sizes rather than offsets. need special handling for that case. | ||
auto const threshold = static_cast<size_t>(strings::detail::get_offset64_threshold()); | ||
if (_string_data.size() > threshold) { | ||
if (not strings::detail::is_large_strings_enabled()) { | ||
CUDF_FAIL("String column exceeds the column size limit", std::overflow_error); | ||
} | ||
// create new offsets | ||
auto const offsets_ptr = static_cast<size_type*>(_data.data()); | ||
auto offsets_col = make_numeric_column( | ||
data_type{type_id::INT64}, size + 1, mask_state::UNALLOCATED, stream, _mr); | ||
auto d_offsets64 = offsets_col->mutable_view().template data<int64_t>(); | ||
// it's safe to call with size + 1 because _data is also sized that large | ||
cudf::detail::sizes_to_offsets(offsets_ptr, offsets_ptr + size + 1, d_offsets64, stream); | ||
return make_strings_column( | ||
size, std::move(offsets_col), std::move(_string_data), null_count(), std::move(_null_mask)); | ||
} else { | ||
// no need for copies, just transfer ownership of the data_buffers to the columns | ||
auto offsets_col = std::make_unique<column>( | ||
data_type{type_to_id<size_type>()}, size + 1, std::move(_data), rmm::device_buffer{}, 0); | ||
return make_strings_column( | ||
size, std::move(offsets_col), std::move(_string_data), null_count(), std::move(_null_mask)); | ||
} | ||
} | ||
|
||
} // namespace cudf::io::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "large_strings_fixture.hpp" | ||
|
||
#include <cudf_test/column_utilities.hpp> | ||
#include <cudf_test/column_wrapper.hpp> | ||
#include <cudf_test/table_utilities.hpp> | ||
|
||
#include <cudf/io/parquet.hpp> | ||
#include <cudf/io/types.hpp> | ||
#include <cudf/table/table_view.hpp> | ||
|
||
namespace { | ||
|
||
cudf::test::TempDirTestEnvironment* const g_temp_env = | ||
static_cast<cudf::test::TempDirTestEnvironment*>( | ||
::testing::AddGlobalTestEnvironment(new cudf::test::TempDirTestEnvironment)); | ||
|
||
} // namespace | ||
|
||
struct ParquetStringsTest : public cudf::test::StringsLargeTest {}; | ||
|
||
TEST_F(ParquetStringsTest, ReadLargeStrings) | ||
{ | ||
// need to create a string column larger than `threshold` | ||
auto const col0 = this->long_column(); | ||
auto const column_size = cudf::strings_column_view(col0).chars_size(cudf::get_default_stream()); | ||
auto const threshold = column_size - 1; | ||
auto const expected = cudf::table_view{{col0, col0, col0}}; | ||
|
||
auto expected_metadata = cudf::io::table_input_metadata{expected}; | ||
expected_metadata.column_metadata[1].set_encoding( | ||
cudf::io::column_encoding::DELTA_LENGTH_BYTE_ARRAY); | ||
expected_metadata.column_metadata[2].set_encoding(cudf::io::column_encoding::DELTA_BYTE_ARRAY); | ||
|
||
// set smaller threshold to reduce file size and execution time | ||
setenv("LIBCUDF_LARGE_STRINGS_THRESHOLD", std::to_string(threshold).c_str(), 1); | ||
|
||
auto const filepath = g_temp_env->get_temp_filepath("ReadLargeStrings.parquet"); | ||
cudf::io::parquet_writer_options out_opts = | ||
cudf::io::parquet_writer_options::builder(cudf::io::sink_info{filepath}, expected) | ||
.compression(cudf::io::compression_type::ZSTD) | ||
.stats_level(cudf::io::STATISTICS_NONE) | ||
.metadata(expected_metadata); | ||
cudf::io::write_parquet(out_opts); | ||
|
||
cudf::io::parquet_reader_options default_in_opts = | ||
cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}); | ||
auto const result = cudf::io::read_parquet(default_in_opts); | ||
auto const result_view = result.tbl->view(); | ||
for (auto cv : result_view) { | ||
auto const offsets = cudf::strings_column_view(cv).offsets(); | ||
EXPECT_EQ(offsets.type(), cudf::data_type{cudf::type_id::INT64}); | ||
} | ||
CUDF_TEST_EXPECT_TABLES_EQUAL(result_view, expected); | ||
|
||
// go back to normal threshold | ||
unsetenv("LIBCUDF_LARGE_STRINGS_THRESHOLD"); | ||
} |