zeroshade commented on a change in pull request #10379: URL: https://github.com/apache/arrow/pull/10379#discussion_r645848592
########## File path: go/parquet/internal/encoding/byte_array_encoder.go ########## @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package encoding + +import ( + "encoding/binary" + "unsafe" + + "github.com/apache/arrow/go/arrow" + "github.com/apache/arrow/go/parquet" + "github.com/apache/arrow/go/parquet/internal/utils" +) + +// PlainByteArrayEncoder encodes byte arrays according to the spec for Plain encoding +// by encoding the length as a uint32 followed by the bytes of the value. +type PlainByteArrayEncoder struct { + encoder +} + +// PutByteArray writes out the 4 bytes for the length followed by the data +func (enc *PlainByteArrayEncoder) PutByteArray(val parquet.ByteArray) { + inc := val.Len() + arrow.Uint32SizeBytes + enc.sink.Reserve(inc) + vlen := uint32(val.Len()) + enc.sink.UnsafeWrite((*(*[4]byte)(unsafe.Pointer(&vlen)))[:]) + enc.sink.UnsafeWrite(val) +} + +// Put writes out all of the values in this slice to the buffer +func (enc *PlainByteArrayEncoder) Put(in []parquet.ByteArray) { + for _, val := range in { + enc.PutByteArray(val) + } +} + +// PutSpaced uses the bitmap of validBits to leave out anything that is null according +// to the bitmap. +// +// If validBits is nil, this is equivalent to calling Put +func (enc *PlainByteArrayEncoder) PutSpaced(in []parquet.ByteArray, validBits []byte, validBitsOffset int64) { Review comment: I'm not sure what you mean, are you saying that the PutSpaced/DecodeSpaced functions only really make sense in the context of being used with Arrow Arrays? and basically having a layer above the encoders that implements the *Spaced functions by performing the compress/expansion and then just calling `Put` without having a PutSpaced/DecodeSpaced on every encoder? -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org