mapleFU commented on code in PR #38367:
URL: https://github.com/apache/arrow/pull/38367#discussion_r1368694227


##########
go/parquet/internal/encoding/boolean_decoder.go:
##########
@@ -109,3 +114,76 @@ func (dec *PlainBooleanDecoder) DecodeSpaced(out []bool, 
nullCount int, validBit
        }
        return dec.Decode(out)
 }
+
+type RleBooleanDecoder struct {
+       decoder
+
+       rleDec *utils.RleDecoder
+}
+
+func (RleBooleanDecoder) Type() parquet.Type {
+       return parquet.Types.Boolean
+}
+
+func (dec *RleBooleanDecoder) SetData(nvals int, data []byte) error {
+       dec.nvals = nvals
+
+       if len(data) < 4 {
+               return fmt.Errorf("invalid length - %d (corrupt data page?)", 
len(data))
+       }
+
+       // load the first 4 bytes in little-endian which indicates the length
+       nbytes := binary.LittleEndian.Uint32(data[:4])
+       if nbytes > uint32(len(data)-4) {
+               return fmt.Errorf("received invalid number of bytes - %d 
(corrupt data page?)", nbytes)
+       }
+
+       dec.data = data[4:]

Review Comment:
   Seems C++ do the same here...Though we can check equality `nbytes == 
uint32(len(data)-4)`  here and use ` data[4:(4 + nbytes)]` here.



##########
go/parquet/internal/encoding/boolean_decoder.go:
##########
@@ -109,3 +114,76 @@ func (dec *PlainBooleanDecoder) DecodeSpaced(out []bool, 
nullCount int, validBit
        }
        return dec.Decode(out)
 }
+
+type RleBooleanDecoder struct {
+       decoder
+
+       rleDec *utils.RleDecoder
+}
+
+func (RleBooleanDecoder) Type() parquet.Type {
+       return parquet.Types.Boolean
+}
+
+func (dec *RleBooleanDecoder) SetData(nvals int, data []byte) error {
+       dec.nvals = nvals
+
+       if len(data) < 4 {
+               return fmt.Errorf("invalid length - %d (corrupt data page?)", 
len(data))
+       }
+
+       // load the first 4 bytes in little-endian which indicates the length
+       nbytes := binary.LittleEndian.Uint32(data[:4])
+       if nbytes > uint32(len(data)-4) {
+               return fmt.Errorf("received invalid number of bytes - %d 
(corrupt data page?)", nbytes)
+       }
+
+       dec.data = data[4:]
+       if dec.rleDec == nil {
+               dec.rleDec = utils.NewRleDecoder(bytes.NewReader(dec.data), 1)
+       } else {
+               dec.rleDec.Reset(bytes.NewReader(dec.data), 1)
+       }
+       return nil
+}
+
+func (dec *RleBooleanDecoder) Decode(out []bool) (int, error) {
+       max := shared_utils.MinInt(len(out), dec.nvals)
+
+       var (
+               buf [1024]uint64
+               n   = max
+       )
+
+       for n > 0 {
+               batch := shared_utils.MinInt(len(buf), n)
+               decoded := dec.rleDec.GetBatch(buf[:batch])
+               if decoded != batch {

Review Comment:
   Should `dec.nvals` dec in this branch?



##########
go/parquet/internal/encoding/boolean_decoder.go:
##########
@@ -109,3 +114,76 @@ func (dec *PlainBooleanDecoder) DecodeSpaced(out []bool, 
nullCount int, validBit
        }
        return dec.Decode(out)
 }
+
+type RleBooleanDecoder struct {
+       decoder
+
+       rleDec *utils.RleDecoder
+}
+
+func (RleBooleanDecoder) Type() parquet.Type {
+       return parquet.Types.Boolean
+}
+
+func (dec *RleBooleanDecoder) SetData(nvals int, data []byte) error {
+       dec.nvals = nvals
+
+       if len(data) < 4 {
+               return fmt.Errorf("invalid length - %d (corrupt data page?)", 
len(data))
+       }
+
+       // load the first 4 bytes in little-endian which indicates the length
+       nbytes := binary.LittleEndian.Uint32(data[:4])
+       if nbytes > uint32(len(data)-4) {
+               return fmt.Errorf("received invalid number of bytes - %d 
(corrupt data page?)", nbytes)
+       }
+
+       dec.data = data[4:]
+       if dec.rleDec == nil {
+               dec.rleDec = utils.NewRleDecoder(bytes.NewReader(dec.data), 1)
+       } else {
+               dec.rleDec.Reset(bytes.NewReader(dec.data), 1)
+       }
+       return nil
+}
+
+func (dec *RleBooleanDecoder) Decode(out []bool) (int, error) {
+       max := shared_utils.MinInt(len(out), dec.nvals)
+
+       var (
+               buf [1024]uint64
+               n   = max
+       )
+
+       for n > 0 {
+               batch := shared_utils.MinInt(len(buf), n)
+               decoded := dec.rleDec.GetBatch(buf[:batch])
+               if decoded != batch {
+                       return max - n, io.ErrUnexpectedEOF

Review Comment:
   I guess we may meet the case if user use `Decoder` directly.
   
   However, during arrow reading it, I guess the upper reader will keep 
non-null value count and didn't hit the branch here?



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to