[ 
https://issues.apache.org/jira/browse/ARROW-1929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16386588#comment-16386588
 ] 

ASF GitHub Bot commented on ARROW-1929:
---------------------------------------

wesm closed pull request #1697: ARROW-1929: [C++] Copy over testing utility 
code from PARQUET-1092
URL: https://github.com/apache/arrow/pull/1697
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/cpp/src/arrow/array-test.cc b/cpp/src/arrow/array-test.cc
index c3ac08286..bda1946c6 100644
--- a/cpp/src/arrow/array-test.cc
+++ b/cpp/src/arrow/array-test.cc
@@ -2480,19 +2480,19 @@ TEST_F(TestListArray, TestFromArrays) {
 
   ListArray expected1(list_type, length, offsets1->data()->buffers[1], values,
                       offsets1->data()->buffers[0], 0);
-  AssertArraysEqual(expected1, *list1);
+  test::AssertArraysEqual(expected1, *list1);
 
   // Use null bitmap from offsets3, but clean offsets from non-null version
   ListArray expected3(list_type, length, offsets1->data()->buffers[1], values,
                       offsets3->data()->buffers[0], 1);
-  AssertArraysEqual(expected3, *list3);
+  test::AssertArraysEqual(expected3, *list3);
 
   // Check that the last offset bit is zero
   ASSERT_TRUE(BitUtil::BitNotSet(list3->null_bitmap()->data(), length + 1));
 
   ListArray expected4(list_type, length, offsets2->data()->buffers[1], values,
                       offsets4->data()->buffers[0], 1);
-  AssertArraysEqual(expected4, *list4);
+  test::AssertArraysEqual(expected4, *list4);
 
   // Test failure modes
 
diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index af7441682..24c8d5e15 100644
--- a/cpp/src/arrow/table-test.cc
+++ b/cpp/src/arrow/table-test.cc
@@ -116,11 +116,11 @@ TEST_F(TestChunkedArray, SliceEquals) {
 
   std::shared_ptr<ChunkedArray> slice = one_->Slice(125, 50);
   ASSERT_EQ(slice->length(), 50);
-  ASSERT_TRUE(slice->Equals(one_->Slice(125, 50)));
+  test::AssertChunkedEqual(*one_->Slice(125, 50), *slice);
 
   std::shared_ptr<ChunkedArray> slice2 = one_->Slice(75)->Slice(25)->Slice(25, 
50);
   ASSERT_EQ(slice2->length(), 50);
-  ASSERT_TRUE(slice2->Equals(slice));
+  test::AssertChunkedEqual(*slice, *slice2);
 }
 
 class TestColumn : public TestChunkedArray {
@@ -390,7 +390,7 @@ TEST_F(TestTable, ConcatenateTables) {
 
   ASSERT_OK(ConcatenateTables({t1, t2}, &result));
   ASSERT_OK(Table::FromRecordBatches({batch1, batch2}, &expected));
-  ASSERT_TRUE(result->Equals(*expected));
+  test::AssertTablesEqual(*expected, *result);
 
   // Error states
   std::vector<std::shared_ptr<Table>> empty_tables;
diff --git a/cpp/src/arrow/test-util.h b/cpp/src/arrow/test-util.h
index 1a3480848..ab68fd442 100644
--- a/cpp/src/arrow/test-util.h
+++ b/cpp/src/arrow/test-util.h
@@ -35,6 +35,7 @@
 #include "arrow/memory_pool.h"
 #include "arrow/pretty_print.h"
 #include "arrow/status.h"
+#include "arrow/table.h"
 #include "arrow/type.h"
 #include "arrow/type_traits.h"
 #include "arrow/util/bit-util.h"
@@ -77,6 +78,18 @@ namespace arrow {
 
 using ArrayVector = std::vector<std::shared_ptr<Array>>;
 
+#define ASSERT_ARRAYS_EQUAL(LEFT, RIGHT)                                       
        \
+  do {                                                                         
        \
+    if (!(LEFT).Equals((RIGHT))) {                                             
        \
+      std::stringstream pp_result;                                             
        \
+      std::stringstream pp_expected;                                           
        \
+                                                                               
        \
+      EXPECT_OK(PrettyPrint(RIGHT, 0, &pp_result));                            
        \
+      EXPECT_OK(PrettyPrint(LEFT, 0, &pp_expected));                           
        \
+      FAIL() << "Got: \n" << pp_result.str() << "\nExpected: \n" << 
pp_expected.str(); \
+    }                                                                          
        \
+  } while (false)
+
 namespace test {
 
 template <typename T, typename U>
@@ -288,6 +301,62 @@ Status MakeRandomBytePoolBuffer(int64_t length, 
MemoryPool* pool,
   return Status::OK();
 }
 
+void AssertArraysEqual(const Array& expected, const Array& actual) {
+  ASSERT_ARRAYS_EQUAL(expected, actual);
+}
+
+void AssertChunkedEqual(const ChunkedArray& expected, const ChunkedArray& 
actual) {
+  ASSERT_EQ(expected.num_chunks(), actual.num_chunks()) << "# chunks unequal";
+  if (!actual.Equals(expected)) {
+    std::stringstream pp_result;
+    std::stringstream pp_expected;
+
+    for (int i = 0; i < actual.num_chunks(); ++i) {
+      auto c1 = actual.chunk(i);
+      auto c2 = expected.chunk(i);
+      if (!c1->Equals(*c2)) {
+        EXPECT_OK(::arrow::PrettyPrint(*c1, 0, &pp_result));
+        EXPECT_OK(::arrow::PrettyPrint(*c2, 0, &pp_expected));
+        FAIL() << "Chunk " << i << " Got: " << pp_result.str()
+               << "\nExpected: " << pp_expected.str();
+      }
+    }
+  }
+}
+
+void PrintColumn(const Column& col, std::stringstream* ss) {
+  const ChunkedArray& carr = *col.data();
+  for (int i = 0; i < carr.num_chunks(); ++i) {
+    auto c1 = carr.chunk(i);
+    *ss << "Chunk " << i << std::endl;
+    EXPECT_OK(::arrow::PrettyPrint(*c1, 0, ss));
+    *ss << std::endl;
+  }
+}
+
+void AssertTablesEqual(const Table& expected, const Table& actual,
+                       bool same_chunk_layout = true) {
+  ASSERT_EQ(expected.num_columns(), actual.num_columns());
+
+  if (same_chunk_layout) {
+    for (int i = 0; i < actual.num_columns(); ++i) {
+      AssertChunkedEqual(*expected.column(i)->data(), 
*actual.column(i)->data());
+    }
+  } else {
+    std::stringstream ss;
+    if (!actual.Equals(expected)) {
+      for (int i = 0; i < expected.num_columns(); ++i) {
+        ss << "Actual column " << i << std::endl;
+        PrintColumn(*actual.column(i), &ss);
+
+        ss << "Expected column " << i << std::endl;
+        PrintColumn(*expected.column(i), &ss);
+      }
+      FAIL() << ss.str();
+    }
+  }
+}
+
 }  // namespace test
 
 template <typename TYPE, typename C_TYPE>
@@ -352,26 +421,10 @@ Status MakeArray(const std::vector<uint8_t>& valid_bytes, 
const std::vector<T>&
   return builder->Finish(out);
 }
 
-#define ASSERT_ARRAYS_EQUAL(LEFT, RIGHT)                                       
        \
-  do {                                                                         
        \
-    if (!(LEFT).Equals((RIGHT))) {                                             
        \
-      std::stringstream pp_result;                                             
        \
-      std::stringstream pp_expected;                                           
        \
-                                                                               
        \
-      EXPECT_OK(PrettyPrint(RIGHT, 0, &pp_result));                            
        \
-      EXPECT_OK(PrettyPrint(LEFT, 0, &pp_expected));                           
        \
-      FAIL() << "Got: \n" << pp_result.str() << "\nExpected: \n" << 
pp_expected.str(); \
-    }                                                                          
        \
-  } while (false)
-
 #define DECL_T() typedef typename TestFixture::T T;
 
 #define DECL_TYPE() typedef typename TestFixture::Type Type;
 
-void AssertArraysEqual(const Array& expected, const Array& actual) {
-  ASSERT_ARRAYS_EQUAL(expected, actual);
-}
-
 #define ASSERT_BATCHES_EQUAL(LEFT, RIGHT)    \
   do {                                       \
     if (!(LEFT).ApproxEquals(RIGHT)) {       \


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [C++] Move various Arrow testing utility code from Parquet to Arrow codebase
> ----------------------------------------------------------------------------
>
>                 Key: ARROW-1929
>                 URL: https://issues.apache.org/jira/browse/ARROW-1929
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Wes McKinney
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> see https://github.com/apache/parquet-cpp/pull/426 and comments within



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to