emkornfield commented on a change in pull request #10379:
URL: https://github.com/apache/arrow/pull/10379#discussion_r644100191



##########
File path: go/parquet/internal/encoding/boolean_encoder.go
##########
@@ -0,0 +1,112 @@
+// 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 (
+       "github.com/apache/arrow/go/arrow/bitutil"
+       "github.com/apache/arrow/go/parquet"
+       "github.com/apache/arrow/go/parquet/internal/utils"
+)
+
+const boolBufSize = 1024
+
+// PlainBooleanEncoder encodes bools as a bitmap as per the Plain Encoding
+type PlainBooleanEncoder struct {
+       encoder
+       nbits      int
+       bitsBuffer []byte
+}
+
+// Type for the PlainBooleanEncoder is parquet.Types.Boolean
+func (PlainBooleanEncoder) Type() parquet.Type {
+       return parquet.Types.Boolean
+}
+
+// Put encodes the contents of in into the underlying data buffer.
+func (enc *PlainBooleanEncoder) Put(in []bool) {
+       if enc.bitsBuffer == nil {
+               enc.bitsBuffer = make([]byte, boolBufSize)
+       }
+
+       bitOffset := 0
+       // first check if we are in the middle of a byte due to previous
+       // encoding of data and finish out that byte's bits.
+       if enc.nbits > 0 {
+               bitsToWrite := utils.MinInt(enc.nbits, len(in))
+               beg := (boolBufSize * 8) - enc.nbits
+               for i, val := range in[:bitsToWrite] {
+                       bitmask := uint8(1 << uint((beg+i)%8))
+                       if val {
+                               enc.bitsBuffer[(beg+i)/8] |= bitmask

Review comment:
       general, comment, I'm not sure how good go is about optimizing away "/8" 
and "*8" operation into shifts for signed ints.  regardless it might pay to 
factor out some of these operations into ByteForBit.
   
   One other comment, did you port over the BitMapWriter (might be off on the 
name) from C++, this appears to be exactly what the class was meant for?




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


Reply via email to