Copilot commented on code in PR #1728:
URL: https://github.com/apache/arrow-go/pull/1728#discussion_r4805229837
##########
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:
`EstimatedDataEncodedSize()` treats `enc.lengthEncoder` as possibly nil, but
`Reset()` unconditionally dereferences it. This inconsistency makes it unclear
whether `lengthEncoder` is an invariant (always non-nil) or optional. Suggested
fix (choose one): (1) if it’s always non-nil, remove the nil check in
`EstimatedDataEncodedSize()` to reflect the invariant; or (2) if it can be nil,
guard `Reset()` (and any other dereferences) to avoid a nil panic.
##########
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:
`fw.rowGroupWriter` is very likely typed as the existing `RowGroupWriter`
interface, which does not include
`EstimatedBufferedStats/EstimatedBufferedBytes`. Calling these methods through
the interface will not compile. Suggested fix: mirror the `pqarrow` approach by
type-asserting `fw.rowGroupWriter` to `BufferedStatsProvider` and returning
zero values when not supported (keeping the feature additive without changing
writer interfaces).
##########
parquet/internal/encoding/types.go:
##########
@@ -315,10 +315,11 @@ func (b *PooledBufferWriter) Bytes() []byte {
// Len provides the current Length of the byte slice
func (b *PooledBufferWriter) Len() int {
- if b.buf.Len() < b.pos {
- b.buf.ResizeNoShrink(b.pos)
+ bufLen := 0
+ if b.buf != nil {
+ bufLen = b.buf.Len()
}
- return b.buf.Len() - b.offset
+ return max(bufLen, b.pos) - b.offset
}
Review Comment:
This can return a negative value if `b.offset > max(bufLen, b.pos)`, which
would violate typical `Len()` expectations and can propagate incorrect
sizing/estimation elsewhere. Suggested fix: clamp the computed length to `>= 0`
(e.g., return 0 when `b.offset` exceeds the logical length). Also, the comment
“current Length of the byte slice” is no longer accurate if `b.pos` can exceed
`b.buf.Len()` without resizing; consider updating the doc to clarify it returns
a “logical” length used for estimation.
##########
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 added term uses `unsafe.Sizeof(T)` over the in-memory delta buffer,
which is not an encoded-size estimate and may substantially overestimate (or at
least conflate) “encoded bytes” vs “heap used by encoder state.” This can skew
page sizing / memory-budget decisions depending on how
`EstimatedDataEncodedSize()` is used elsewhere. Suggested fix: avoid `unsafe`
here and instead estimate pending *encoded* bytes (e.g., track the size
contribution of buffered deltas in bits/bytes based on current block
parameters), or split responsibilities by keeping `EstimatedDataEncodedSize()`
purely encoded-size and adding a separate explicit
“BufferedMemoryBytes()`/similar for memory accounting.
--
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]