Skip to content

Commit dfd872a

Browse files
committed
use BufferedStats for buffered data
1 parent b11fb06 commit dfd872a

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

cpp/src/parquet/column_writer.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,19 @@ class TypedColumnWriterImpl : public ColumnWriterImpl,
14801480
return current_encoder_->EstimatedDataEncodedSize();
14811481
}
14821482

1483-
int64_t EstimatedBufferedLevelsBytes() const override {
1484-
return definition_levels_sink_.length() + repetition_levels_sink_.length();
1483+
int64_t estimated_buffered_def_level_bytes() const override {
1484+
return definition_levels_sink_.length();
1485+
}
1486+
1487+
int64_t estimated_buffered_rep_level_bytes() const override {
1488+
return repetition_levels_sink_.length();
1489+
}
1490+
1491+
int64_t estimated_buffered_dict_bytes() const override {
1492+
if (current_dict_encoder_) {
1493+
return current_dict_encoder_->dict_encoded_size();
1494+
}
1495+
return 0;
14851496
}
14861497

14871498
protected:

cpp/src/parquet/column_writer.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ class PARQUET_EXPORT ColumnWriter {
164164
/// \brief Estimated size of the values that are not written to a page yet.
165165
virtual int64_t estimated_buffered_value_bytes() const = 0;
166166

167-
/// \brief Estimated size of the levels that are not written to a page yet.
168-
virtual int64_t EstimatedBufferedLevelsBytes() const = 0;
167+
/// \brief Estimated size of the definition levels that are not written to a page yet.
168+
virtual int64_t estimated_buffered_def_level_bytes() const = 0;
169+
170+
/// \brief Estimated size of the repetition levels that are not written to a page yet.
171+
virtual int64_t estimated_buffered_rep_level_bytes() const = 0;
172+
173+
/// \brief Estimated size of the dictionary that are not written to a page yet.
174+
virtual int64_t estimated_buffered_dict_bytes() const = 0;
169175

170176
/// \brief The file-level writer properties
171177
virtual const WriterProperties* properties() = 0;

cpp/src/parquet/file_writer.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ int64_t RowGroupWriter::total_compressed_bytes_written() const {
6868
return contents_->total_compressed_bytes_written();
6969
}
7070

71-
int64_t RowGroupWriter::total_buffered_bytes() const {
72-
return contents_->EstimatedBufferedBytes();
71+
BufferedStats RowGroupWriter::estimated_buffered_stats() const {
72+
return contents_->EstimatedBufferedStats();
7373
}
7474

7575
bool RowGroupWriter::buffered() const { return contents_->buffered(); }
@@ -199,19 +199,20 @@ class RowGroupSerializer : public RowGroupWriter::Contents {
199199
return total_compressed_bytes_written;
200200
}
201201

202-
int64_t EstimatedBufferedBytes() const override {
202+
BufferedStats EstimatedBufferedStats() const override {
203+
BufferedStats stats;
203204
if (closed_) {
204-
return 0;
205+
return stats;
205206
}
206-
int64_t estimated_buffered_value_bytes = 0;
207207
for (size_t i = 0; i < column_writers_.size(); i++) {
208208
if (column_writers_[i]) {
209-
estimated_buffered_value_bytes +=
210-
column_writers_[i]->estimated_buffered_value_bytes() +
211-
column_writers_[i]->EstimatedBufferedLevelsBytes();
209+
stats.def_level_bytes += column_writers_[i]->estimated_buffered_def_level_bytes();
210+
stats.rep_level_bytes += column_writers_[i]->estimated_buffered_rep_level_bytes();
211+
stats.value_bytes += column_writers_[i]->estimated_buffered_value_bytes();
212+
stats.dict_bytes += column_writers_[i]->estimated_buffered_dict_bytes();
212213
}
213214
}
214-
return estimated_buffered_value_bytes;
215+
return stats;
215216
}
216217

217218
bool buffered() const override { return buffered_row_group_; }

cpp/src/parquet/file_writer.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ class ColumnWriter;
3434
static constexpr uint8_t kParquetMagic[4] = {'P', 'A', 'R', '1'};
3535
static constexpr uint8_t kParquetEMagic[4] = {'P', 'A', 'R', 'E'};
3636

37+
struct PARQUET_EXPORT BufferedStats {
38+
int64_t def_level_bytes = 0;
39+
int64_t rep_level_bytes = 0;
40+
int64_t value_bytes = 0;
41+
int64_t dict_bytes = 0;
42+
};
43+
3744
class PARQUET_EXPORT RowGroupWriter {
3845
public:
3946
// Forward declare a virtual class 'Contents' to aid dependency injection and more
@@ -58,9 +65,9 @@ class PARQUET_EXPORT RowGroupWriter {
5865
virtual int64_t total_compressed_bytes() const = 0;
5966
/// \brief total compressed bytes written by the page writer
6067
virtual int64_t total_compressed_bytes_written() const = 0;
61-
/// \brief Estimated bytes of values and levels that are buffered by the page writer
62-
/// but not written to a page yet
63-
virtual int64_t EstimatedBufferedBytes() const = 0;
68+
/// \brief Estimated sizes of buffered data (levels, values, dict) not yet
69+
/// written to a page.
70+
virtual BufferedStats EstimatedBufferedStats() const = 0;
6471

6572
virtual bool buffered() const = 0;
6673
};
@@ -102,8 +109,9 @@ class PARQUET_EXPORT RowGroupWriter {
102109
int64_t total_compressed_bytes() const;
103110
/// \brief total compressed bytes written by the page writer
104111
int64_t total_compressed_bytes_written() const;
105-
/// \brief total bytes of values and levels that are buffered by the page writer
106-
int64_t total_buffered_bytes() const;
112+
/// \brief Estimated sizes of buffered data (levels, values, dict) not yet
113+
/// written to a page.
114+
BufferedStats estimated_buffered_stats() const;
107115

108116
/// Returns whether the current RowGroupWriter is in the buffered mode and is created
109117
/// by calling ParquetFileWriter::AppendBufferedRowGroup.

0 commit comments

Comments
 (0)