You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mapleFU (via GitHub)" <gi...@apache.org> on 2023/06/29 11:53:57 UTC
[GitHub] [arrow] mapleFU opened a new pull request, #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
mapleFU opened a new pull request, #36377:
URL: https://github.com/apache/arrow/pull/36377
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Allow a buffered `WriteTable`
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
add `use_buffering` in `WriteTable`
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Yes
### Are there any user-facing changes?
User can write table with buffered row-group
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268131813
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5057,23 +5092,123 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
TYPED_TEST_SUITE(TestBufferedParquetIO, TestTypes);
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteSmall) {
- constexpr int64_t batch_size = SMALL_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = SMALL_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
}
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
- constexpr int64_t batch_size = LARGE_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = LARGE_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(LARGE_SIZE, /*num_nulls=*/100, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableSmall) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
Review Comment:
Can you also void repeating yourself in the tests below?
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -488,6 +458,59 @@ class FileWriterImpl : public FileWriter {
std::vector<ArrowWriteContext> parallel_column_write_contexts_;
};
+template <typename T>
+Status FileWriterImpl::WriteBuffered(const T& batch, int64_t max_row_group_length) {
+ if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
+ row_group_writer_->num_rows() >= max_row_group_length) {
+ RETURN_NOT_OK(NewBufferedRowGroup());
+ }
+
+ auto WriteBatch = [&](int64_t offset, int64_t size) {
+ std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
+ int column_index_start = 0;
+
+ for (int i = 0; i < batch.num_columns(); i++) {
+ std::shared_ptr<ChunkedArray> chunked_array = GetColumnChunkedArray(batch, i);
Review Comment:
It is a bit wasteful to call this for each chunk. Why not use a `RecordBatchReader` instead?
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5057,23 +5092,123 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
TYPED_TEST_SUITE(TestBufferedParquetIO, TestTypes);
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteSmall) {
- constexpr int64_t batch_size = SMALL_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = SMALL_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
}
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
- constexpr int64_t batch_size = LARGE_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = LARGE_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(LARGE_SIZE, /*num_nulls=*/100, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableSmall) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
Review Comment:
Are there tests with more than one column somewhere?
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5024,6 +5024,41 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
ASSERT_OK_NO_THROW(writer->Close());
}
+ void WriteBufferedTable(const std::shared_ptr<Array>& values,
Review Comment:
Can you please refactor this with `WriteBufferedFile` to avoid copy-pasting entire chunks of code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268187930
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5057,23 +5092,123 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
TYPED_TEST_SUITE(TestBufferedParquetIO, TestTypes);
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteSmall) {
- constexpr int64_t batch_size = SMALL_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = SMALL_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
}
TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
- constexpr int64_t batch_size = LARGE_SIZE / 4;
+ constexpr size_t NUM_BATCHES = 4;
+ constexpr int64_t batch_size = LARGE_SIZE / NUM_BATCHES;
std::shared_ptr<Array> values;
- ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ ASSERT_OK(
+ NullableArray<TypeParam>(LARGE_SIZE, /*num_nulls=*/100, kDefaultSeed, &values));
int num_row_groups = 0;
this->WriteBufferedFile(values, batch_size, &num_row_groups);
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableSmall) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(
+ NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
Review Comment:
No. I'll add it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268175537
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5024,6 +5024,41 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
ASSERT_OK_NO_THROW(writer->Close());
}
+ void WriteBufferedTable(const std::shared_ptr<Array>& values,
Review Comment:
Hmmm I guess I use some different logic here, I'll try to unify them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268164298
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -488,6 +458,59 @@ class FileWriterImpl : public FileWriter {
std::vector<ArrowWriteContext> parallel_column_write_contexts_;
};
+template <typename T>
+Status FileWriterImpl::WriteBuffered(const T& batch, int64_t max_row_group_length) {
+ if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
+ row_group_writer_->num_rows() >= max_row_group_length) {
+ RETURN_NOT_OK(NewBufferedRowGroup());
+ }
+
+ auto WriteBatch = [&](int64_t offset, int64_t size) {
+ std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
+ int column_index_start = 0;
+
+ for (int i = 0; i < batch.num_columns(); i++) {
+ std::shared_ptr<ChunkedArray> chunked_array = GetColumnChunkedArray(batch, i);
Review Comment:
```c++
std::shared_ptr<ChunkedArray> GetColumnChunkedArray(const ::arrow::RecordBatch& value,
int column_id) {
return std::make_shared<::arrow::ChunkedArray>(value.column(column_id));
}
std::shared_ptr<ChunkedArray> GetColumnChunkedArray(const ::arrow::Table& value,
int column_id) {
return value.column(column_id);
}
```
Seems that here I want to call `ArrowColumnWriterV2::Make`, which requires a `ChunkedArray`, so maybe I'm not sure why this is expensive, and how `RecordBatch` can handling this...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wgtmac commented on a diff in pull request #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1251740661
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -274,6 +274,16 @@ class ArrowColumnWriterV2 {
RowGroupWriter* row_group_writer_;
};
+std::shared_ptr<ChunkedArray> getColumnChunkedArray(const ::arrow::RecordBatch& value,
+ int column_id) {
+ return std::make_shared<::arrow::ChunkedArray>(value.column(column_id));
+}
+
+std::shared_ptr<ChunkedArray> getColumnChunkedArray(const ::arrow::Table& value,
Review Comment:
```suggestion
std::shared_ptr<ChunkedArray> GetColumnChunkedArray(const ::arrow::Table& value,
```
##########
cpp/src/parquet/arrow/writer.h:
##########
@@ -91,10 +91,21 @@ class PARQUET_EXPORT FileWriter {
/// \brief Write a Table to Parquet.
///
+ /// If `use_buffering` is false, then any pending row group is closed
+ /// at the beginning and at the end of this call.
+ /// If `use_buffering` is true, this function reuses an existing
+ /// buffered row group until the chunk size is met, and leaves
+ /// the last row group open for further writes.
+ /// It is recommended to set `use_buffering` to true to minimize
+ /// the number of row groups, especially when calling `WriteTable`
+ /// with small tables.
+ ///
/// \param table Arrow table to write.
/// \param chunk_size maximum number of rows to write per row group.
- virtual ::arrow::Status WriteTable(
- const ::arrow::Table& table, int64_t chunk_size = DEFAULT_MAX_ROW_GROUP_LENGTH) = 0;
+ /// \param use_buffering Whether to potentially buffer data.
+ virtual ::arrow::Status WriteTable(const ::arrow::Table& table,
Review Comment:
How about adding a separate `WriteBufferedTable(const ::arrow::Table& table)` function?
My rationales are:
- `chunk_size` would be confusing since the `WriterProperties::max_row_group_length()` serves the same purpose.
- Adding a new `use_buffering` parameter complicates the handling of `WriteTable` to deal with previous state.
- In most cases, we don't expect users to mix calls of `use_buffering=true` and `use_buffering=false`.
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -356,7 +366,10 @@ class FileWriterImpl : public FileWriter {
std::shared_ptr<::arrow::Schema> schema() const override { return schema_; }
- Status WriteTable(const Table& table, int64_t chunk_size) override {
+ template <typename T>
+ Status WriteBuffered(const T& batch, int64_t max_row_group_length);
Review Comment:
```suggestion
Status WriteBufferedRowGroup(const T& batch, int64_t max_row_group_length);
```
##########
cpp/src/parquet/arrow/writer.h:
##########
@@ -91,10 +91,21 @@ class PARQUET_EXPORT FileWriter {
/// \brief Write a Table to Parquet.
///
+ /// If `use_buffering` is false, then any pending row group is closed
+ /// at the beginning and at the end of this call.
+ /// If `use_buffering` is true, this function reuses an existing
+ /// buffered row group until the chunk size is met, and leaves
+ /// the last row group open for further writes.
+ /// It is recommended to set `use_buffering` to true to minimize
+ /// the number of row groups, especially when calling `WriteTable`
+ /// with small tables.
+ ///
/// \param table Arrow table to write.
/// \param chunk_size maximum number of rows to write per row group.
- virtual ::arrow::Status WriteTable(
- const ::arrow::Table& table, int64_t chunk_size = DEFAULT_MAX_ROW_GROUP_LENGTH) = 0;
+ /// \param use_buffering Whether to potentially buffer data.
+ virtual ::arrow::Status WriteTable(const ::arrow::Table& table,
Review Comment:
IIUC, the use case of `WriteTable()` and `WriteRecordBatch()` should be:
- A single RecordBatch object should not be large, so `WriteRecordBatch()` is implemented to write in the buffered mode to avoid small row groups.
- A single Table usually holds a large number of records, so it makes sense to see `WriteTable()` breaks the table into row groups and does not use the buffered mode.
The current PR is addressing the issue when a Table object is small which should copy the same behavior of `WriteRecordBatch`.
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -469,6 +415,30 @@ class FileWriterImpl : public FileWriter {
return writer_->metadata();
}
+ Status WriteTableUnbuffered(const Table& table, int64_t chunk_size) {
Review Comment:
```suggestion
Status WriteNonBufferedRowGroup(const Table& table, int64_t chunk_size) {
```
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -274,6 +274,16 @@ class ArrowColumnWriterV2 {
RowGroupWriter* row_group_writer_;
};
+std::shared_ptr<ChunkedArray> getColumnChunkedArray(const ::arrow::RecordBatch& value,
Review Comment:
```suggestion
std::shared_ptr<ChunkedArray> GetColumnChunkedArray(const ::arrow::RecordBatch& value,
```
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -406,57 +402,7 @@ class FileWriterImpl : public FileWriter {
}
// Max number of rows allowed in a row group.
- const int64_t max_row_group_length = this->properties().max_row_group_length();
-
- if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
- row_group_writer_->num_rows() >= max_row_group_length) {
- RETURN_NOT_OK(NewBufferedRowGroup());
- }
-
- auto WriteBatch = [&](int64_t offset, int64_t size) {
- std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
- int column_index_start = 0;
-
- for (int i = 0; i < batch.num_columns(); i++) {
- ChunkedArray chunked_array{batch.column(i)};
- ARROW_ASSIGN_OR_RAISE(
- std::unique_ptr<ArrowColumnWriterV2> writer,
- ArrowColumnWriterV2::Make(chunked_array, offset, size, schema_manifest_,
- row_group_writer_, column_index_start));
- column_index_start += writer->leaf_count();
- if (arrow_properties_->use_threads()) {
- writers.emplace_back(std::move(writer));
- } else {
- RETURN_NOT_OK(writer->Write(&column_write_context_));
- }
- }
-
- if (arrow_properties_->use_threads()) {
Review Comment:
Moving the async logic into `WriteTable` may cause a potential concurrent issue mentioned by @westonpace in this [comment](https://github.com/apache/arrow/pull/33656#pullrequestreview-1250353638).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1251854179
##########
cpp/src/parquet/arrow/writer.h:
##########
@@ -91,10 +91,21 @@ class PARQUET_EXPORT FileWriter {
/// \brief Write a Table to Parquet.
///
+ /// If `use_buffering` is false, then any pending row group is closed
+ /// at the beginning and at the end of this call.
+ /// If `use_buffering` is true, this function reuses an existing
+ /// buffered row group until the chunk size is met, and leaves
+ /// the last row group open for further writes.
+ /// It is recommended to set `use_buffering` to true to minimize
+ /// the number of row groups, especially when calling `WriteTable`
+ /// with small tables.
+ ///
/// \param table Arrow table to write.
/// \param chunk_size maximum number of rows to write per row group.
- virtual ::arrow::Status WriteTable(
- const ::arrow::Table& table, int64_t chunk_size = DEFAULT_MAX_ROW_GROUP_LENGTH) = 0;
+ /// \param use_buffering Whether to potentially buffer data.
+ virtual ::arrow::Status WriteTable(const ::arrow::Table& table,
Review Comment:
Yes we can. However, this is mentioned here: https://github.com/apache/arrow/pull/36286#issuecomment-1611332862
And I think that `RecordBatch` reuses Array, `Table` may uses `ChunkedArray`, so supporting a `WriteTable` with buffered is ok here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #36377:
URL: https://github.com/apache/arrow/pull/36377#issuecomment-1634329418
@pitrou would you mind take a look at this? This add a buffering mode for `WriteTable`, and later can benefits Python side `write_table` without flush a chunk during every write
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #36377:
URL: https://github.com/apache/arrow/pull/36377#issuecomment-3547074403
Thank you for your contribution. Unfortunately, this pull request has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this PR will be closed in 14 days. Feel free to re-open this if it has been closed in error. If you do not have repository permissions to reopen the PR, please tag a maintainer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on pull request #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #36377:
URL: https://github.com/apache/arrow/pull/36377#issuecomment-1614334673
@jorisvandenbossche @pitrou Mind take a look? WriteTable with buffering is added now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268122535
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -469,6 +415,30 @@ class FileWriterImpl : public FileWriter {
return writer_->metadata();
}
+ Status WriteTableUnbuffered(const Table& table, int64_t chunk_size) {
+ auto WriteRowGroup = [&](int64_t offset, int64_t size) {
+ RETURN_NOT_OK(NewRowGroup(size));
+ for (int i = 0; i < table.num_columns(); i++) {
+ RETURN_NOT_OK(WriteColumnChunk(table.column(i), offset, size));
+ }
+ return Status::OK();
+ };
+
+ if (table.num_rows() == 0) {
+ // Append a row group with 0 rows
+ RETURN_NOT_OK_ELSE(WriteRowGroup(0, 0), PARQUET_IGNORE_NOT_OK(Close()));
+ return Status::OK();
+ }
+
+ for (int chunk = 0; chunk * chunk_size < table.num_rows(); chunk++) {
+ int64_t offset = chunk * chunk_size;
+ RETURN_NOT_OK_ELSE(
+ WriteRowGroup(offset, std::min(chunk_size, table.num_rows() - offset)),
+ PARQUET_IGNORE_NOT_OK(Close()));
Review Comment:
`RETURN_NOT_OK_ELSE` will do `Close` when `WriteRowGroup` failed. These code is written in 2019, I don't know why they do like this, but I Close when having error is ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wgtmac commented on a diff in pull request #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1252544285
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
Review Comment:
```suggestion
TYPED_TEST(TestBufferedParquetIO, WriteTableSmall) {
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
Review Comment:
```suggestion
ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, /*num_nulls=*/100, kDefaultSeed, &values));
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
Review Comment:
```suggestion
TYPED_TEST(TestBufferedParquetIO, WriteTableInBatches) {
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
Review Comment:
```suggestion
// Write all table in one batch with a small max_row_group_size.
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -4980,6 +4980,40 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
ASSERT_OK_NO_THROW(writer->Close());
}
+ void WriteBufferedTable(const std::shared_ptr<Array>& values,
+ int64_t write_table_batch_size,
+ int64_t parquet_writer_max_row_group_size,
+ int64_t write_table_max_row_group_size, int* num_row_groups) {
+ std::shared_ptr<GroupNode> schema =
+ MakeSimpleSchema(*values->type(), Repetition::OPTIONAL);
+ SchemaDescriptor descriptor;
+ ASSERT_NO_THROW(descriptor.Init(schema));
+ std::shared_ptr<::arrow::Schema> arrow_schema;
+ ArrowReaderProperties props;
+ ASSERT_OK_NO_THROW(FromParquetSchema(&descriptor, props, &arrow_schema));
+
+ parquet::WriterProperties::Builder props_builder;
+ props_builder.max_row_group_length(parquet_writer_max_row_group_size);
+
+ this->sink_ = CreateOutputStream();
+ auto low_level_writer =
+ ParquetFileWriter::Open(this->sink_, schema, props_builder.build());
+ std::unique_ptr<FileWriter> writer;
+ ASSERT_OK_NO_THROW(FileWriter::Make(::arrow::default_memory_pool(),
+ std::move(low_level_writer), arrow_schema,
+ default_arrow_writer_properties(), &writer));
+ for (int i = 0; i * write_table_batch_size < values->length(); i++) {
Review Comment:
Add a DCHECK for `values->length() % write_table_batch_size == 0`?
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
Review Comment:
constexpr int num_batches = 4;
##########
cpp/src/parquet/arrow/writer.h:
##########
@@ -91,10 +91,21 @@ class PARQUET_EXPORT FileWriter {
/// \brief Write a Table to Parquet.
///
+ /// If `use_buffering` is false, then any pending row group is closed
+ /// at the beginning and at the end of this call.
+ /// If `use_buffering` is true, this function reuses an existing
+ /// buffered row group until the chunk size is met, and leaves
+ /// the last row group open for further writes.
+ /// It is recommended to set `use_buffering` to true to minimize
+ /// the number of row groups, especially when calling `WriteTable`
+ /// with small tables.
+ ///
/// \param table Arrow table to write.
/// \param chunk_size maximum number of rows to write per row group.
- virtual ::arrow::Status WriteTable(
- const ::arrow::Table& table, int64_t chunk_size = DEFAULT_MAX_ROW_GROUP_LENGTH) = 0;
+ /// \param use_buffering Whether to potentially buffer data.
+ virtual ::arrow::Status WriteTable(const ::arrow::Table& table,
Review Comment:
Sorry that I have missed the discussion. Since the conclusion is to extend the `WriteTable`, I will resolve this comment.
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
+ {
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE / 4;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+ }
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit2) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE;
+ int64_t write_max_row_group_size = SMALL_SIZE / 4;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatchesLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
Review Comment:
```suggestion
ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
+ {
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE / 4;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+ }
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit2) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE;
+ int64_t write_max_row_group_size = SMALL_SIZE / 4;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatchesLimit) {
Review Comment:
```suggestion
TYPED_TEST(TestBufferedParquetIO, WriteTableInBatchesForMultiRowGroups) {
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
Review Comment:
```suggestion
ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
+ {
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE / 4;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+ }
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit2) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
Review Comment:
```suggestion
ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
+ {
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE / 4;
Review Comment:
Ditto for the magic number 4
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
Review Comment:
```suggestion
ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, /*num_nulls=*/10, kDefaultSeed, &values));
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
Review Comment:
```suggestion
TYPED_TEST(TestBufferedParquetIO, WriteTableWithRowGroupSizeLimit) {
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -4980,6 +4980,40 @@ class TestBufferedParquetIO : public TestParquetIO<TestType> {
ASSERT_OK_NO_THROW(writer->Close());
}
+ void WriteBufferedTable(const std::shared_ptr<Array>& values,
+ int64_t write_table_batch_size,
+ int64_t parquet_writer_max_row_group_size,
Review Comment:
```suggestion
int64_t writer_properties_max_row_group_size,
```
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -406,57 +402,7 @@ class FileWriterImpl : public FileWriter {
}
// Max number of rows allowed in a row group.
- const int64_t max_row_group_length = this->properties().max_row_group_length();
-
- if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
- row_group_writer_->num_rows() >= max_row_group_length) {
- RETURN_NOT_OK(NewBufferedRowGroup());
- }
-
- auto WriteBatch = [&](int64_t offset, int64_t size) {
- std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
- int column_index_start = 0;
-
- for (int i = 0; i < batch.num_columns(); i++) {
- ChunkedArray chunked_array{batch.column(i)};
- ARROW_ASSIGN_OR_RAISE(
- std::unique_ptr<ArrowColumnWriterV2> writer,
- ArrowColumnWriterV2::Make(chunked_array, offset, size, schema_manifest_,
- row_group_writer_, column_index_start));
- column_index_start += writer->leaf_count();
- if (arrow_properties_->use_threads()) {
- writers.emplace_back(std::move(writer));
- } else {
- RETURN_NOT_OK(writer->Write(&column_write_context_));
- }
- }
-
- if (arrow_properties_->use_threads()) {
Review Comment:
You may also add similar comment to WriteTable
```cpp
/// WARNING: If you are writing multiple files in parallel in the same
/// executor, deadlock may occur if ArrowWriterProperties::use_threads
/// is set to true to write columns in parallel. Please disable use_threads
/// option in this case.
```
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5030,6 +5064,93 @@ TYPED_TEST(TestBufferedParquetIO, SingleColumnOptionalBufferedWriteLarge) {
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
}
+TYPED_TEST(TestBufferedParquetIO, WriteTableBase) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLarge) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(LARGE_SIZE, 100, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batch.
+ int64_t write_table_batch_size = LARGE_SIZE;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnTable(values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableBatches) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with four batches.
+ int64_t write_table_batch_size = SMALL_SIZE / 4;
+ int64_t write_table_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size, write_table_max_row_group_size,
+ write_max_row_group_size, &num_row_groups);
+ EXPECT_EQ(1, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NullableArray<TypeParam>(SMALL_SIZE, 10, kDefaultSeed, &values));
+ int num_row_groups = 0;
+ // Write all table with one batches, but set parquet max-row-group size smaller
+ {
+ int64_t write_table_batch_size = SMALL_SIZE;
+ int64_t parquet_writer_max_row_group_size = SMALL_SIZE / 4;
+ int64_t write_max_row_group_size = DEFAULT_MAX_ROW_GROUP_LENGTH;
+ this->WriteBufferedTable(values, write_table_batch_size,
+ parquet_writer_max_row_group_size, write_max_row_group_size,
+ &num_row_groups);
+ EXPECT_EQ(4, num_row_groups);
+ ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleColumnFile(*values, num_row_groups));
+ }
+}
+
+TYPED_TEST(TestBufferedParquetIO, WriteTableLimit2) {
Review Comment:
```suggestion
TYPED_TEST(TestBufferedParquetIO, WriteTableWithRowGroupSizeLimit2) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1257299928
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -469,6 +415,30 @@ class FileWriterImpl : public FileWriter {
return writer_->metadata();
}
+ Status WriteTableUnbuffered(const Table& table, int64_t chunk_size) {
Review Comment:
Also, this more write more than one rowgroup(at least a row-group is written), so I guess `WriteTable` is ok?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #36377:
URL: https://github.com/apache/arrow/pull/36377#issuecomment-1631114769
I guess this would also closes: https://github.com/apache/arrow/issues/31405
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] `parquet::arrow::FileWriter` support table buffered write
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1251861862
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -406,57 +402,7 @@ class FileWriterImpl : public FileWriter {
}
// Max number of rows allowed in a row group.
- const int64_t max_row_group_length = this->properties().max_row_group_length();
-
- if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
- row_group_writer_->num_rows() >= max_row_group_length) {
- RETURN_NOT_OK(NewBufferedRowGroup());
- }
-
- auto WriteBatch = [&](int64_t offset, int64_t size) {
- std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
- int column_index_start = 0;
-
- for (int i = 0; i < batch.num_columns(); i++) {
- ChunkedArray chunked_array{batch.column(i)};
- ARROW_ASSIGN_OR_RAISE(
- std::unique_ptr<ArrowColumnWriterV2> writer,
- ArrowColumnWriterV2::Make(chunked_array, offset, size, schema_manifest_,
- row_group_writer_, column_index_start));
- column_index_start += writer->leaf_count();
- if (arrow_properties_->use_threads()) {
- writers.emplace_back(std::move(writer));
- } else {
- RETURN_NOT_OK(writer->Write(&column_write_context_));
- }
- }
-
- if (arrow_properties_->use_threads()) {
Review Comment:
oops... It's really amazing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268238707
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -488,6 +458,59 @@ class FileWriterImpl : public FileWriter {
std::vector<ArrowWriteContext> parallel_column_write_contexts_;
};
+template <typename T>
+Status FileWriterImpl::WriteBuffered(const T& batch, int64_t max_row_group_length) {
+ if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
+ row_group_writer_->num_rows() >= max_row_group_length) {
+ RETURN_NOT_OK(NewBufferedRowGroup());
+ }
+
+ auto WriteBatch = [&](int64_t offset, int64_t size) {
+ std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
+ int column_index_start = 0;
+
+ for (int i = 0; i < batch.num_columns(); i++) {
+ std::shared_ptr<ChunkedArray> chunked_array = GetColumnChunkedArray(batch, i);
Review Comment:
Ok, then you can simply call `GetColumnChunkedArray(batch, i)` outside of `WriteBatch`. It does not depend on offset/size.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268110361
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -469,6 +415,30 @@ class FileWriterImpl : public FileWriter {
return writer_->metadata();
}
+ Status WriteTableUnbuffered(const Table& table, int64_t chunk_size) {
+ auto WriteRowGroup = [&](int64_t offset, int64_t size) {
+ RETURN_NOT_OK(NewRowGroup(size));
+ for (int i = 0; i < table.num_columns(); i++) {
+ RETURN_NOT_OK(WriteColumnChunk(table.column(i), offset, size));
+ }
+ return Status::OK();
+ };
+
+ if (table.num_rows() == 0) {
+ // Append a row group with 0 rows
+ RETURN_NOT_OK_ELSE(WriteRowGroup(0, 0), PARQUET_IGNORE_NOT_OK(Close()));
+ return Status::OK();
+ }
+
+ for (int chunk = 0; chunk * chunk_size < table.num_rows(); chunk++) {
+ int64_t offset = chunk * chunk_size;
+ RETURN_NOT_OK_ELSE(
+ WriteRowGroup(offset, std::min(chunk_size, table.num_rows() - offset)),
+ PARQUET_IGNORE_NOT_OK(Close()));
Review Comment:
I know you're just moving code around, but do you know why `Close()` is being called here? We shouldn't close the file even though we have not finished writing all chunks.
Also, I don't understand why errors are silenced using `PARQUET_IGNORE_NOT_OK`. I don't think this is a good idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic closed pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
URL: https://github.com/apache/arrow/pull/36377
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a diff in pull request #36377: GH-36280: [Parquet][C++] FileWriter supports WriteTable in the buffered mode
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1268134956
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -469,6 +415,30 @@ class FileWriterImpl : public FileWriter {
return writer_->metadata();
}
+ Status WriteTableUnbuffered(const Table& table, int64_t chunk_size) {
+ auto WriteRowGroup = [&](int64_t offset, int64_t size) {
+ RETURN_NOT_OK(NewRowGroup(size));
+ for (int i = 0; i < table.num_columns(); i++) {
+ RETURN_NOT_OK(WriteColumnChunk(table.column(i), offset, size));
+ }
+ return Status::OK();
+ };
+
+ if (table.num_rows() == 0) {
+ // Append a row group with 0 rows
+ RETURN_NOT_OK_ELSE(WriteRowGroup(0, 0), PARQUET_IGNORE_NOT_OK(Close()));
+ return Status::OK();
+ }
+
+ for (int chunk = 0; chunk * chunk_size < table.num_rows(); chunk++) {
+ int64_t offset = chunk * chunk_size;
+ RETURN_NOT_OK_ELSE(
+ WriteRowGroup(offset, std::min(chunk_size, table.num_rows() - offset)),
+ PARQUET_IGNORE_NOT_OK(Close()));
Review Comment:
I see, thank you for the explanation. This macro is a bit confusing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1257298908
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -406,57 +402,7 @@ class FileWriterImpl : public FileWriter {
}
// Max number of rows allowed in a row group.
- const int64_t max_row_group_length = this->properties().max_row_group_length();
-
- if (row_group_writer_ == nullptr || !row_group_writer_->buffered() ||
- row_group_writer_->num_rows() >= max_row_group_length) {
- RETURN_NOT_OK(NewBufferedRowGroup());
- }
-
- auto WriteBatch = [&](int64_t offset, int64_t size) {
- std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
- int column_index_start = 0;
-
- for (int i = 0; i < batch.num_columns(); i++) {
- ChunkedArray chunked_array{batch.column(i)};
- ARROW_ASSIGN_OR_RAISE(
- std::unique_ptr<ArrowColumnWriterV2> writer,
- ArrowColumnWriterV2::Make(chunked_array, offset, size, schema_manifest_,
- row_group_writer_, column_index_start));
- column_index_start += writer->leaf_count();
- if (arrow_properties_->use_threads()) {
- writers.emplace_back(std::move(writer));
- } else {
- RETURN_NOT_OK(writer->Write(&column_write_context_));
- }
- }
-
- if (arrow_properties_->use_threads()) {
Review Comment:
This is added in declaration
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] mapleFU commented on a diff in pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1257298854
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -356,7 +366,10 @@ class FileWriterImpl : public FileWriter {
std::shared_ptr<::arrow::Schema> schema() const override { return schema_; }
- Status WriteTable(const Table& table, int64_t chunk_size) override {
+ template <typename T>
+ Status WriteBuffered(const T& batch, int64_t max_row_group_length);
Review Comment:
I guess `WriteBuffered` is better than `WriteBufferedRowGroup`, because it might write more than 1 row-groups, or not write a rowgroup?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wgtmac commented on a diff in pull request #36377: GH-36280: [Parquet][C++] parquet::arrow::FileWriter supports WriteTable in buffered mode
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #36377:
URL: https://github.com/apache/arrow/pull/36377#discussion_r1257299123
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -356,7 +366,10 @@ class FileWriterImpl : public FileWriter {
std::shared_ptr<::arrow::Schema> schema() const override { return schema_; }
- Status WriteTable(const Table& table, int64_t chunk_size) override {
+ template <typename T>
+ Status WriteBuffered(const T& batch, int64_t max_row_group_length);
Review Comment:
Make sense
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org