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


##########
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:
   `outerRead` in `unencryptedChunkReader` only wraps `Outer()`, which `Next()` 
and data page reads never touch. Only `GetDictionaryPage()` reads from 
`Outer()` when falling back to the chunk stream, so asserting `*outerRead == 0` 
isolates dictionary fallback reads directly.



##########
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:
   Callers release the returned `*DictionaryPage` via 
`DictionaryPage.Release()`, which calls `d.buf.Release()`. Returning a fresh 
`DictionaryPage` and `memory.NewBufferBytes` wrapper keeps each caller's 
`Release()` safe, and `GetDictionaryPage()` runs per seek rather than per row.



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