Skip to content

Commit

Permalink
ARROW-5668 [C++/Python] Include 'not null' in schema fields pretty print
Browse files Browse the repository at this point in the history
https://issues.apache.org/jira/browse/ARROW-5668

Author: Joris Van den Bossche <[email protected]>

Closes apache#4645 from jorisvandenbossche/ARROW-5668-schema-repr-nonnull and squashes the following commits:

055917f <Joris Van den Bossche> lint
bfc6c68 <Joris Van den Bossche> ARROW-5668  include 'not null' in schema fields repr
  • Loading branch information
jorisvandenbossche authored and wesm committed Jun 21, 2019
1 parent be16de0 commit a6d1b9c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
23 changes: 23 additions & 0 deletions cpp/src/arrow/pretty_print-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions cpp/src/arrow/pretty_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();

Expand All @@ -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,
Expand Down

0 comments on commit a6d1b9c

Please sign in to comment.