This is an automated email from the ASF dual-hosted git repository. zeroshade pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push: new 27cea4367e GH-20415: [Go] Kernel Input Type for RLE (#14146) 27cea4367e is described below commit 27cea4367e09b4fdd0df7de50fb82c43043cd2ea Author: Matt Topol <zotthewiz...@gmail.com> AuthorDate: Mon Jan 30 11:37:05 2023 -0500 GH-20415: [Go] Kernel Input Type for RLE (#14146) Authored-by: Matt Topol <zotthewiz...@gmail.com> Signed-off-by: Matt Topol <zotthewiz...@gmail.com> --- go/arrow/array/concat.go | 2 +- go/arrow/compute/internal/exec/kernel.go | 34 +++++++++++++++++++++++++++ go/arrow/compute/internal/exec/kernel_test.go | 34 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/go/arrow/array/concat.go b/go/arrow/array/concat.go index 2e60670d47..c8e12318fa 100644 --- a/go/arrow/array/concat.go +++ b/go/arrow/array/concat.go @@ -47,7 +47,7 @@ func Concatenate(arrs []arrow.Array, mem memory.Allocator) (result arrow.Array, case error: err = fmt.Errorf("arrow/concat: %w", e) default: - err = fmt.Errorf("arrow/concat: unknown error: %v", pErr) + err = fmt.Errorf("arrow/concat: %v", pErr) } } }() diff --git a/go/arrow/compute/internal/exec/kernel.go b/go/arrow/compute/internal/exec/kernel.go index 6a88188574..92d40910d6 100644 --- a/go/arrow/compute/internal/exec/kernel.go +++ b/go/arrow/compute/internal/exec/kernel.go @@ -242,6 +242,40 @@ func (primitiveMatcher) Equals(other TypeMatcher) bool { // returns true for. func Primitive() TypeMatcher { return primitiveMatcher{} } +type reeMatcher struct { + runEndsMatcher TypeMatcher + encodedMatcher TypeMatcher +} + +func (r reeMatcher) Matches(typ arrow.DataType) bool { + if typ.ID() != arrow.RUN_END_ENCODED { + return false + } + + dt := typ.(*arrow.RunEndEncodedType) + return r.runEndsMatcher.Matches(dt.RunEnds()) && r.encodedMatcher.Matches(dt.Encoded()) +} + +func (r reeMatcher) Equals(other TypeMatcher) bool { + o, ok := other.(reeMatcher) + if !ok { + return false + } + return r.runEndsMatcher.Equals(o.runEndsMatcher) && r.encodedMatcher.Equals(o.encodedMatcher) +} + +func (r reeMatcher) String() string { + return "run_end_encoded(run_ends=" + r.runEndsMatcher.String() + ", values=" + r.encodedMatcher.String() + ")" +} + +// RunEndEncoded returns a matcher which matches a RunEndEncoded +// type whose encoded type is matched by the passed in matcher. +func RunEndEncoded(runEndsMatcher, encodedMatcher TypeMatcher) TypeMatcher { + return reeMatcher{ + runEndsMatcher: runEndsMatcher, + encodedMatcher: encodedMatcher} +} + // InputKind is an enum representing the type of Input matching // that will be done. Either accepting any type, an exact specific type // or using a TypeMatcher. diff --git a/go/arrow/compute/internal/exec/kernel_test.go b/go/arrow/compute/internal/exec/kernel_test.go index d198f07828..efca125b78 100644 --- a/go/arrow/compute/internal/exec/kernel_test.go +++ b/go/arrow/compute/internal/exec/kernel_test.go @@ -161,6 +161,40 @@ func TestPrimitiveMatcher(t *testing.T) { assert.False(t, match.Matches(arrow.Null)) } +func TestREEMatcher(t *testing.T) { + tests := []struct { + runEnds exec.TypeMatcher + enc exec.TypeMatcher + matchRunEnds arrow.DataType + nomatchRunEnds arrow.DataType + matchEnc arrow.DataType + nomatchEnc arrow.DataType + }{ + {exec.Integer(), exec.Integer(), arrow.PrimitiveTypes.Int16, arrow.FixedWidthTypes.Float16, arrow.PrimitiveTypes.Int8, arrow.BinaryTypes.String}, + {exec.SameTypeID(arrow.INT32), exec.BinaryLike(), arrow.PrimitiveTypes.Int32, arrow.PrimitiveTypes.Int64, arrow.BinaryTypes.String, arrow.PrimitiveTypes.Int32}, + {exec.SameTypeID(arrow.INT64), exec.SameTypeID(arrow.STRUCT), arrow.PrimitiveTypes.Int64, arrow.PrimitiveTypes.Int32, arrow.StructOf(arrow.Field{Name: "a", Type: arrow.PrimitiveTypes.Int16}), arrow.PrimitiveTypes.Int8}, + } + + for _, tt := range tests { + t.Run(tt.enc.String(), func(t *testing.T) { + matcher := exec.RunEndEncoded(tt.runEnds, tt.enc) + assert.False(t, matcher.Matches(tt.matchEnc)) + assert.True(t, matcher.Matches(arrow.RunEndEncodedOf(tt.matchRunEnds, tt.matchEnc))) + assert.False(t, matcher.Matches(arrow.RunEndEncodedOf(tt.matchRunEnds, tt.nomatchEnc))) + assert.False(t, matcher.Matches(arrow.RunEndEncodedOf(tt.nomatchRunEnds, tt.matchEnc))) + assert.False(t, matcher.Matches(arrow.RunEndEncodedOf(tt.nomatchRunEnds, tt.nomatchEnc))) + + assert.Equal(t, "run_end_encoded(run_ends="+tt.runEnds.String()+", values="+tt.enc.String()+")", matcher.String()) + + assert.True(t, matcher.Equals(exec.RunEndEncoded(tt.runEnds, tt.enc))) + assert.False(t, matcher.Equals(exec.Primitive())) + assert.False(t, matcher.Equals(exec.RunEndEncoded(exec.SameTypeID(tt.nomatchRunEnds.ID()), exec.SameTypeID(tt.nomatchEnc.ID())))) + assert.False(t, matcher.Equals(exec.RunEndEncoded(exec.SameTypeID(tt.matchRunEnds.ID()), exec.SameTypeID(tt.nomatchEnc.ID())))) + assert.False(t, matcher.Equals(exec.RunEndEncoded(exec.SameTypeID(tt.nomatchRunEnds.ID()), exec.SameTypeID(tt.matchEnc.ID())))) + }) + } +} + func TestInputTypeAnyType(t *testing.T) { var ty exec.InputType assert.Equal(t, exec.InputAny, ty.Kind)