Repository: arrow
Updated Branches:
  refs/heads/master d9f895ebd -> 3033eac10


ARROW-1466: [C++] Implement PrettyPrint for DecimalArray

Author: Wes McKinney <[email protected]>

Closes #1056 from wesm/ARROW-1466 and squashes the following commits:

1ec7f1cc [Wes McKinney] Implement PrettyPrint for DecimalArray


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/3033eac1
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/3033eac1
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/3033eac1

Branch: refs/heads/master
Commit: 3033eac1056315f22024c1a36f21484789dd8675
Parents: d9f895e
Author: Wes McKinney <[email protected]>
Authored: Wed Sep 6 19:38:56 2017 -0400
Committer: Wes McKinney <[email protected]>
Committed: Wed Sep 6 19:38:56 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/pretty_print-test.cc | 26 ++++++++++++++++++++++++++
 cpp/src/arrow/pretty_print.cc      | 17 +++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/3033eac1/cpp/src/arrow/pretty_print-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/pretty_print-test.cc 
b/cpp/src/arrow/pretty_print-test.cc
index d4c92ce..ab0bc16 100644
--- a/cpp/src/arrow/pretty_print-test.cc
+++ b/cpp/src/arrow/pretty_print-test.cc
@@ -31,6 +31,8 @@
 #include "arrow/test-util.h"
 #include "arrow/type.h"
 #include "arrow/type_traits.h"
+#include "arrow/util/decimal.h"
+#include "arrow/util/int128.h"
 
 namespace arrow {
 
@@ -106,6 +108,30 @@ TEST_F(TestPrettyPrint, FixedSizeBinaryType) {
   CheckArray(*array, 0, ex);
 }
 
+TEST_F(TestPrettyPrint, DecimalType) {
+  int32_t p = 19;
+  int32_t s = 4;
+
+  auto type = decimal(p, s);
+
+  DecimalBuilder builder(type);
+
+  Int128 val;
+
+  ASSERT_OK(DecimalUtil::FromString("123.4567", &val));
+  ASSERT_OK(builder.Append(val));
+
+  ASSERT_OK(DecimalUtil::FromString("456.7891", &val));
+  ASSERT_OK(builder.Append(val));
+  ASSERT_OK(builder.AppendNull());
+
+  std::shared_ptr<Array> array;
+  ASSERT_OK(builder.Finish(&array));
+
+  static const char* ex = R"expected([123.4567, 456.7891, null])expected";
+  CheckArray(*array, 0, ex);
+}
+
 TEST_F(TestPrettyPrint, DictionaryType) {
   std::vector<bool> is_valid = {true, true, false, true, true, true};
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/3033eac1/cpp/src/arrow/pretty_print.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc
index f759056..1202faa 100644
--- a/cpp/src/arrow/pretty_print.cc
+++ b/cpp/src/arrow/pretty_print.cc
@@ -168,6 +168,21 @@ class ArrayPrinter : public PrettyPrinter {
   }
 
   template <typename T>
+  inline typename std::enable_if<std::is_same<DecimalArray, T>::value, 
void>::type
+  WriteDataValues(const T& array) {
+    for (int i = 0; i < array.length(); ++i) {
+      if (i > 0) {
+        (*sink_) << ", ";
+      }
+      if (array.IsNull(i)) {
+        Write("null");
+      } else {
+        (*sink_) << array.FormatValue(i);
+      }
+    }
+  }
+
+  template <typename T>
   inline typename std::enable_if<std::is_base_of<BooleanArray, T>::value, 
void>::type
   WriteDataValues(const T& array) {
     for (int i = 0; i < array.length(); ++i) {
@@ -198,8 +213,6 @@ class ArrayPrinter : public PrettyPrinter {
 
   Status Visit(const IntervalArray& array) { return 
Status::NotImplemented("interval"); }
 
-  Status Visit(const DecimalArray& array) { return 
Status::NotImplemented("decimal"); }
-
   Status WriteValidityBitmap(const Array& array);
 
   Status Visit(const ListArray& array) {

Reply via email to