This is an automated email from the ASF dual-hosted git repository. sbinet 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 40632c8 ARROW-5582: [Go] implement RecordEqual 40632c8 is described below commit 40632c847c93291ed025b8e539677882e0a69d35 Author: Sebastien Binet <bi...@cern.ch> AuthorDate: Fri Jun 14 15:53:42 2019 +0200 ARROW-5582: [Go] implement RecordEqual Author: Sebastien Binet <bi...@cern.ch> Closes #4561 from sbinet/issue-5582 and squashes the following commits: 751ba393c <Sebastien Binet> go/arrow/array: add RecordApproxEqual a67379b60 <Sebastien Binet> ARROW-5582: implement RecordEqual --- go/arrow/array/compare.go | 41 ++++++++++++++++++++++++++++++++++ go/arrow/array/compare_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/go/arrow/array/compare.go b/go/arrow/array/compare.go index 9fa13a1..da8f5ab 100644 --- a/go/arrow/array/compare.go +++ b/go/arrow/array/compare.go @@ -24,6 +24,47 @@ import ( "github.com/pkg/errors" ) +// RecordEqual reports whether the two provided records are equal. +func RecordEqual(left, right Record) bool { + switch { + case left.NumCols() != right.NumCols(): + return false + case left.NumRows() != right.NumRows(): + return false + } + + for i := range left.Columns() { + lc := left.Column(i) + rc := right.Column(i) + if !ArrayEqual(lc, rc) { + return false + } + } + return true +} + +// RecordApproxEqual reports whether the two provided records are approximately equal. +// For non-floating point columns, it is equivalent to RecordEqual. +func RecordApproxEqual(left, right Record, opts ...EqualOption) bool { + switch { + case left.NumCols() != right.NumCols(): + return false + case left.NumRows() != right.NumRows(): + return false + } + + opt := newEqualOption(opts...) + + for i := range left.Columns() { + lc := left.Column(i) + rc := right.Column(i) + if !arrayApproxEqual(lc, rc, opt) { + return false + } + } + return true +} + // ArrayEqual reports whether the two provided arrays are equal. func ArrayEqual(left, right Interface) bool { switch { diff --git a/go/arrow/array/compare_test.go b/go/arrow/array/compare_test.go index 9985f51..e9927f0 100644 --- a/go/arrow/array/compare_test.go +++ b/go/arrow/array/compare_test.go @@ -479,3 +479,53 @@ func TestArrayEqualDifferentMaskedValues(t *testing.T) { t.Errorf("%v must be equal to %v", a1, a2) } } + +func TestRecordEqual(t *testing.T) { + for name, recs := range arrdata.Records { + t.Run(name, func(t *testing.T) { + rec0 := recs[0] + rec1 := recs[1] + if !array.RecordEqual(rec0, rec0) { + t.Fatalf("identical records should compare equal:\nrecord:\n%v", rec0) + } + + if array.RecordEqual(rec0, rec1) { + t.Fatalf("non-identical records should not compare equal:\nrec0:\n%v\nrec1:\n%v", rec0, rec1) + } + + sub00 := rec0.NewSlice(0, recs[0].NumRows()-1) + defer sub00.Release() + sub01 := rec0.NewSlice(1, recs[0].NumRows()) + defer sub01.Release() + + if array.RecordEqual(sub00, sub01) { + t.Fatalf("non-identical records should not compare equal:\nsub0:\n%v\nsub1:\n%v", sub00, sub01) + } + }) + } +} + +func TestRecordApproxEqual(t *testing.T) { + for name, recs := range arrdata.Records { + t.Run(name, func(t *testing.T) { + rec0 := recs[0] + rec1 := recs[1] + if !array.RecordApproxEqual(rec0, rec0) { + t.Fatalf("identical records should compare equal:\nrecord:\n%v", rec0) + } + + if array.RecordApproxEqual(rec0, rec1) { + t.Fatalf("non-identical records should not compare equal:\nrec0:\n%v\nrec1:\n%v", rec0, rec1) + } + + sub00 := rec0.NewSlice(0, recs[0].NumRows()-1) + defer sub00.Release() + sub01 := rec0.NewSlice(1, recs[0].NumRows()) + defer sub01.Release() + + if array.RecordApproxEqual(sub00, sub01) { + t.Fatalf("non-identical records should not compare equal:\nsub0:\n%v\nsub1:\n%v", sub00, sub01) + } + }) + } +}