This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new d7b4d2d5f7 GH-37465: [Go] Add Value method to BooleanBuilder (#37459)
d7b4d2d5f7 is described below

commit d7b4d2d5f7491a788649ccc0a9f61d3212a6e438
Author: Matthias Loibl <[email protected]>
AuthorDate: Thu Aug 31 16:35:04 2023 +0100

    GH-37465: [Go] Add Value method to BooleanBuilder (#37459)
    
    
    
    ### Rationale for this change
    
    Similar to the changes we've made in #35744 we need this for the 
BooleanBuilder too.
    
    ### What changes are included in this PR?
    
    Adding the method itself and adjusting a test to test both the Value method 
on the builder and the final array.
    
    ### Are these changes tested?
    
    Yes
    
    ### Are there any user-facing changes?
    
    Just an enhancement to get on-par with other builders.
    
    * Closes: #37465
    
    Authored-by: Matthias Loibl <[email protected]>
    Signed-off-by: Matt Topol <[email protected]>
---
 go/arrow/array/booleanbuilder.go      |  4 ++++
 go/arrow/array/booleanbuilder_test.go | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/go/arrow/array/booleanbuilder.go b/go/arrow/array/booleanbuilder.go
index f4a5ba9816..10b7405aa5 100644
--- a/go/arrow/array/booleanbuilder.go
+++ b/go/arrow/array/booleanbuilder.go
@@ -254,6 +254,10 @@ func (b *BooleanBuilder) UnmarshalJSON(data []byte) error {
        return b.Unmarshal(dec)
 }
 
+func (b *BooleanBuilder) Value(i int) bool {
+       return bitutil.BitIsSet(b.rawData, i)
+}
+
 var (
        _ Builder = (*BooleanBuilder)(nil)
 )
diff --git a/go/arrow/array/booleanbuilder_test.go 
b/go/arrow/array/booleanbuilder_test.go
index 702b0ca554..e270636a87 100644
--- a/go/arrow/array/booleanbuilder_test.go
+++ b/go/arrow/array/booleanbuilder_test.go
@@ -32,12 +32,21 @@ func TestBooleanBuilder_AppendValues(t *testing.T) {
        b := array.NewBooleanBuilder(mem)
 
        exp := tools.Bools(1, 1, 0, 1, 1, 0)
-       got := make([]bool, len(exp)+2)
 
        b.AppendValues(exp, nil)
        assert.NoError(t, b.AppendValueFromString("true"))
        assert.NoError(t, b.AppendValueFromString("false"))
        exp = tools.Bools(1, 1, 0, 1, 1, 0, 1, 0)
+
+       got := make([]bool, len(exp))
+       // make sure we can read the values directly from the builder.
+       for i := 0; i < b.Len(); i++ {
+               got[i] = b.Value(i)
+       }
+       assert.Equal(t, exp, got)
+
+       got = make([]bool, len(exp)) // reset
+
        a := b.NewBooleanArray()
        b.Release()
        for i := 0; i < a.Len(); i++ {

Reply via email to