hcrosse commented on code in PR #1728:
URL: https://github.com/apache/arrow-go/pull/1728#discussion_r4805457081


##########
parquet/file/file_writer.go:
##########
@@ -163,6 +163,26 @@ func (fw *Writer) TotalCompressedBytes() int64 {
        return total
 }
 
+// RowGroupEstimatedBufferedStats returns the estimated byte breakdown of
+// unflushed encoder data currently buffered in memory for the open row group
+// (excluding buffered pages), or zero if no row group is open.
+func (fw *Writer) RowGroupEstimatedBufferedStats() BufferedStats {
+       if fw.rowGroupWriter != nil {
+               return fw.rowGroupWriter.EstimatedBufferedStats()
+       }
+       return BufferedStats{}
+}
+
+// RowGroupEstimatedBufferedBytes returns the estimated total in-memory 
buffered
+// bytes for the currently open row group, including buffered pages and
+// unflushed column encoder data, or 0 if no row group is open.
+func (fw *Writer) RowGroupEstimatedBufferedBytes() int64 {
+       if fw.rowGroupWriter != nil {
+               return fw.rowGroupWriter.EstimatedBufferedBytes()
+       }
+       return 0
+}

Review Comment:
   That field holds the concrete `*rowGroupWriter` pointer rather than the 
`RowGroupWriter` interface, so calling both methods directly compiles cleanly 
without a type assertion.



##########
parquet/internal/encoding/delta_bit_packing.go:
##########
@@ -528,13 +529,14 @@ func (enc *deltaBitPackEncoder[T]) Reset() {
        enc.deltas = enc.deltas[:0]
 }
 
-// EstimatedDataEncodedSize returns the current amount of data actually 
flushed out and written
+// EstimatedDataEncodedSize returns the estimated byte size of flushed blocks
+// plus unflushed values buffered in the current block.
 func (enc *deltaBitPackEncoder[T]) EstimatedDataEncodedSize() int64 {
-       if enc.bitWriter == nil {
+       if enc.bitWriter == nil || enc.totalVals == 0 {
                return 0
        }
 
-       return int64(enc.bitWriter.Written())
+       return int64(enc.bitWriter.Written()) + 
int64(unsafe.Sizeof(T(0)))*int64(1+len(enc.deltas))
 }

Review Comment:
   The pending buffer holds at most one 128-value block (at most 1 KiB for 
64-bit integers), so multiplying by the element width gives a constant-time 
upper bound without scanning pending deltas on every batch write.



##########
parquet/internal/encoding/delta_length_byte_array.go:
##########
@@ -100,6 +100,14 @@ func (enc *DeltaLengthByteArrayEncoder) FlushValues() 
(Buffer, error) {
        return poolBuffer{output}, nil
 }
 
+func (enc *DeltaLengthByteArrayEncoder) EstimatedDataEncodedSize() int64 {
+       lengthEstimatedSize := int64(0)
+       if enc.lengthEncoder != nil {
+               lengthEstimatedSize = 
enc.lengthEncoder.EstimatedDataEncodedSize()
+       }
+       return enc.encoder.EstimatedDataEncodedSize() + lengthEstimatedSize
+}
+
 func (enc *DeltaLengthByteArrayEncoder) Reset() {
        enc.encoder.Reset()
        enc.lengthEncoder.Reset()

Review Comment:
   I kept the nil guard to match 
`DeltaByteArrayEncoder.EstimatedDataEncodedSize` in the same package so the 
size query stays safe on a zero-value encoder without changing reset behavior.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to