You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/06/21 17:44:41 UTC

[arrow] branch master updated: ARROW-5668 [C++/Python] Include 'not null' in schema fields pretty print

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

wesm 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 a6d1b9c  ARROW-5668 [C++/Python] Include 'not null' in schema fields pretty print
a6d1b9c is described below

commit a6d1b9c789af3108c95263c97cea5d9fd3cde760
Author: Joris Van den Bossche <jo...@gmail.com>
AuthorDate: Fri Jun 21 12:09:07 2019 -0500

    ARROW-5668 [C++/Python] Include 'not null' in schema fields pretty print
    
    https://issues.apache.org/jira/browse/ARROW-5668
    
    Author: Joris Van den Bossche <jo...@gmail.com>
    
    Closes #4645 from jorisvandenbossche/ARROW-5668-schema-repr-nonnull and squashes the following commits:
    
    055917f98 <Joris Van den Bossche> lint
    bfc6c6842 <Joris Van den Bossche> ARROW-5668  include 'not null' in schema fields repr
---
 cpp/src/arrow/pretty_print-test.cc | 23 +++++++++++++++++++++++
 cpp/src/arrow/pretty_print.cc      |  9 ++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/cpp/src/arrow/pretty_print-test.cc b/cpp/src/arrow/pretty_print-test.cc
index 1aed4d7..7600ab4 100644
--- a/cpp/src/arrow/pretty_print-test.cc
+++ b/cpp/src/arrow/pretty_print-test.cc
@@ -658,4 +658,27 @@ four: struct<one: int32, two: dictionary<values=string, indices=int16, ordered=0
   Check(*sch, options, expected);
 }
 
+TEST_F(TestPrettyPrint, SchemaWithNotNull) {
+  auto simple = field("one", int32());
+  auto non_null = field("two", int32(), false);
+  auto list_simple = field("three", list(int32()));
+  auto list_non_null = field("four", list(int32()), false);
+  auto list_non_null2 = field("five", list(field("item", int32(), false)));
+
+  auto sch = schema({simple, non_null, list_simple, list_non_null, list_non_null2});
+
+  static const char* expected = R"expected(one: int32
+two: int32 not null
+three: list<item: int32>
+  child 0, item: int32
+four: list<item: int32> not null
+  child 0, item: int32
+five: list<item: int32 not null>
+  child 0, item: int32 not null)expected";
+
+  PrettyPrintOptions options{0};
+
+  Check(*sch, options, expected);
+}
+
 }  // namespace arrow
diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc
index 175514b..cb67b0d 100644
--- a/cpp/src/arrow/pretty_print.cc
+++ b/cpp/src/arrow/pretty_print.cc
@@ -570,7 +570,7 @@ class SchemaPrinter : public PrettyPrinter {
       : PrettyPrinter(indent, indent_size, window, skip_new_lines, sink),
         schema_(schema) {}
 
-  Status PrintType(const DataType& type);
+  Status PrintType(const DataType& type, bool nullable);
   Status PrintField(const Field& field);
 
   Status Print() {
@@ -588,8 +588,11 @@ class SchemaPrinter : public PrettyPrinter {
   const Schema& schema_;
 };
 
-Status SchemaPrinter::PrintType(const DataType& type) {
+Status SchemaPrinter::PrintType(const DataType& type, bool nullable) {
   Write(type.ToString());
+  if (!nullable) {
+    Write(" not null");
+  }
   for (int i = 0; i < type.num_children(); ++i) {
     Newline();
 
@@ -607,7 +610,7 @@ Status SchemaPrinter::PrintType(const DataType& type) {
 Status SchemaPrinter::PrintField(const Field& field) {
   Write(field.name());
   Write(": ");
-  return PrintType(*field.type());
+  return PrintType(*field.type(), field.nullable());
 }
 
 Status PrettyPrint(const Schema& schema, const PrettyPrintOptions& options,