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



##########
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:
       I did port the bitmap writer, and originally i was doing that, i need to 
do some digging to confirm, but if i remember correctly, I ended up doing it 
this way instead of using the bitmapwriter for this because it ultimately ended 
up being faster since I had bools rather than appending words, and thus avoided 
significant function calls by calling `Next()`, `Set()` and `Clear()`. 
   
   I'll take another look at the benchmarks and maybe add a function into the 
bitmapwriter that takes a bunch of bools to optimize that workflow




-- 
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:
[email protected]


Reply via email to