Copilot commented on code in PR #1647:
URL: https://github.com/apache/arrow-go/pull/1647#discussion_r4645832097


##########
parquet/file/page_reader_internal_test.go:
##########
@@ -395,3 +401,49 @@ func 
TestGetDictionaryPageWithoutRecordedOffsetReadsOnlyTheDictionary(t *testing
        require.EqualValues(t, dictValues, got.NumValues())
        require.Less(t, *read, 2*len(dict), "read %d of %d chunk bytes for a %d 
byte dictionary page", *read, len(chunk), len(dict))
 }
+
+func TestSeekToRowDictionaryAtDataPageOffsetReadsDictionaryOnce(t *testing.T) {
+       // RLE_DICTIONARY indices 0,1,1,0,0,0,1,0 at bit width 1
+       indices := []byte{1, 3, 0x46}
+       chunk := append(
+               serializePage(t, dictPageSpec(10, 20)),
+               serializePage(t, dataPageSpec(8, 
format.Encoding_RLE_DICTIONARY, indices))...,
+       )
+
+       p, outerRead := unencryptedChunkReader(t, 8, chunk)
+       cr := requiredInt32Column(t, p)
+       t.Cleanup(func() { require.NoError(t, cr.Close()) })
+
+       require.NoError(t, cr.SeekToRow(0))
+       vals := make([]int32, 8)
+       _, n, err := cr.ReadBatch(8, vals, nil, nil)
+       require.NoError(t, err)
+       require.Equal(t, []int32{10, 20, 20, 10, 10, 10, 20, 10}, vals[:n])
+       require.Zero(t, *outerRead, "dictionary page was re-read from the chunk 
stream after seek already decoded it")

Review Comment:
   The `require.Zero(t, *outerRead, ...)` assertion is brittle because 
`outerRead` can increase for reasons unrelated to re-reading the dictionary 
(e.g., buffered reader refill while reading data pages, different buffer 
sizing, or prefetch strategy changes). To make this test robust and 
specifically tied to the regression, consider asserting on an `outerRead` delta 
across just the operation that previously caused the second dictionary read 
(e.g., record `readsBefore := *outerRead` immediately after `SeekToRow(0)` and 
then assert that the subsequent step(s) that used to trigger 
`GetDictionaryPage` do not increase reads beyond what is necessary for the data 
page), or otherwise isolate dictionary re-reads from data page reads.



##########
parquet/file/page_reader.go:
##########
@@ -755,7 +764,23 @@ func (p *serializedPageReader) dictionaryAtDataOffset() 
bool {
        return p.dataOffset <= p.baseOffset && (p.chunkStartsWithDict || 
p.cryptoCtx.MetaDecryptor == nil)
 }
 
+func (p *serializedPageReader) dictionaryPage() *DictionaryPage {
+       return &DictionaryPage{
+               page: page{
+                       buf:      
memory.NewBufferBytes(p.dictPageBuffer.Bytes()),
+                       typ:      format.PageType_DICTIONARY_PAGE,
+                       nvals:    p.cachedDict.nvals,
+                       encoding: p.cachedDict.encoding,
+               },
+               sorted: p.cachedDict.sorted,
+       }

Review Comment:
   `GetDictionaryPage` can now return the cached dictionary frequently, but 
each return still allocates a new `memory.Buffer` wrapper (and 
`DictionaryPage`) via `memory.NewBufferBytes(...)`. If `GetDictionaryPage` is 
called repeatedly in hot paths, consider caching a prebuilt `*DictionaryPage` 
(or at least a `*memory.Buffer` wrapper) alongside the cached metadata, and 
rebuilding it only when the underlying `dictPageBuffer` is resized/invalidated. 
This keeps the current behavior while reducing per-call allocations.



-- 
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