@@ -5797,11 +5797,11 @@ TEST(TestArrowReadWrite, WriteRecordBatchNotProduceEmptyRowGroup) {
57975797TEST (TestArrowReadWrite, WriteRecordBatchFlushRowGroupByBufferedSize) {
57985798 auto pool = ::arrow::default_memory_pool ();
57995799 auto sink = CreateOutputStream ();
5800- // Limit the max bytes in a row group to 100 so that each batch produces a new group .
5800+ // Limit the max bytes in a row group to 100.
58015801 auto writer_properties = WriterProperties::Builder ().max_row_group_bytes (100 )->build ();
58025802 auto arrow_writer_properties = default_arrow_writer_properties ();
58035803
5804- // Prepare schema
5804+ // Prepare schema.
58055805 auto schema = ::arrow::schema ({::arrow::field (" a" , ::arrow::int64 ())});
58065806 std::shared_ptr<SchemaDescriptor> parquet_schema;
58075807 ASSERT_OK_NO_THROW (ToParquetSchema (schema.get (), *writer_properties,
@@ -5825,9 +5825,49 @@ TEST(TestArrowReadWrite, WriteRecordBatchFlushRowGroupByBufferedSize) {
58255825 ASSERT_OK_AND_ASSIGN (auto buffer, sink->Finish ());
58265826
58275827 auto file_metadata = arrow_writer->metadata ();
5828- EXPECT_EQ (2 , file_metadata->num_row_groups ());
5829- EXPECT_EQ (3 , file_metadata->RowGroup (0 )->num_rows ());
5828+ EXPECT_EQ (3 , file_metadata->num_row_groups ());
5829+ EXPECT_EQ (1 , file_metadata->RowGroup (0 )->num_rows ());
58305830 EXPECT_EQ (2 , file_metadata->RowGroup (1 )->num_rows ());
5831+ EXPECT_EQ (2 , file_metadata->RowGroup (2 )->num_rows ());
5832+ }
5833+
5834+ TEST (TestArrowReadWrite, WriteRecordBatchWithSmallMaxRowGroupBytes) {
5835+ auto pool = ::arrow::default_memory_pool ();
5836+ auto sink = CreateOutputStream ();
5837+ // Limit the max bytes in a row group to 1, then each row starts a new row group.
5838+ auto writer_properties = WriterProperties::Builder ().max_row_group_bytes (1 )->build ();
5839+ auto arrow_writer_properties = default_arrow_writer_properties ();
5840+
5841+ // Prepare schema.
5842+ auto schema = ::arrow::schema ({::arrow::field (" a" , ::arrow::int64 ())});
5843+ std::shared_ptr<SchemaDescriptor> parquet_schema;
5844+ ASSERT_OK_NO_THROW (ToParquetSchema (schema.get (), *writer_properties,
5845+ *arrow_writer_properties, &parquet_schema));
5846+ auto schema_node = std::static_pointer_cast<GroupNode>(parquet_schema->schema_root ());
5847+
5848+ auto gen = ::arrow::random::RandomArrayGenerator (/* seed=*/ 42 );
5849+
5850+ // Create writer to write data via RecordBatch.
5851+ ASSERT_OK_AND_ASSIGN (auto arrow_writer, parquet::arrow::FileWriter::Open (
5852+ *schema, pool, sink, writer_properties,
5853+ arrow_writer_properties));
5854+ // NewBufferedRowGroup() is not called explicitly and it will be called
5855+ // inside WriteRecordBatch().
5856+ for (int i = 0 ; i < 5 ; ++i) {
5857+ auto record_batch =
5858+ gen.BatchOf ({::arrow::field (" a" , ::arrow::int64 ())}, /* length=*/ 1 );
5859+ ASSERT_OK_NO_THROW (arrow_writer->WriteRecordBatch (*record_batch));
5860+ }
5861+ ASSERT_OK_NO_THROW (arrow_writer->Close ());
5862+ ASSERT_OK_AND_ASSIGN (auto buffer, sink->Finish ());
5863+
5864+ auto file_metadata = arrow_writer->metadata ();
5865+ EXPECT_EQ (5 , file_metadata->num_row_groups ());
5866+ EXPECT_EQ (1 , file_metadata->RowGroup (0 )->num_rows ());
5867+ EXPECT_EQ (1 , file_metadata->RowGroup (1 )->num_rows ());
5868+ EXPECT_EQ (1 , file_metadata->RowGroup (2 )->num_rows ());
5869+ EXPECT_EQ (1 , file_metadata->RowGroup (3 )->num_rows ());
5870+ EXPECT_EQ (1 , file_metadata->RowGroup (4 )->num_rows ());
58315871}
58325872
58335873TEST (TestArrowReadWrite, WriteTableFlushRowGroupByBufferedSize) {
0 commit comments