From d08fe8be51206bf63fc926d0f3e7f0fd4f7db36e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 2 Oct 2023 13:54:07 -0400 Subject: [PATCH 01/12] Add `array_element_delimiter` option to `PrettyPrintOptions` class. --- cpp/src/arrow/pretty_print.cc | 6 +++--- cpp/src/arrow/pretty_print.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc index 03e2051c2fb88..5b99807e3858b 100644 --- a/cpp/src/arrow/pretty_print.cc +++ b/cpp/src/arrow/pretty_print.cc @@ -151,14 +151,14 @@ class ArrayPrinter : public PrettyPrinter { IndentAfterNewline(); (*sink_) << "..."; if (!is_last && options_.skip_new_lines) { - (*sink_) << ","; + (*sink_) << options_.array_element_delimiter; } i = array.length() - window - 1; } else if (array.IsNull(i)) { IndentAfterNewline(); (*sink_) << options_.null_rep; if (!is_last) { - (*sink_) << ","; + (*sink_) << options_.array_element_delimiter; } } else { if (indent_non_null_values) { @@ -166,7 +166,7 @@ class ArrayPrinter : public PrettyPrinter { } RETURN_NOT_OK(func(i)); if (!is_last) { - (*sink_) << ","; + (*sink_) << options_.array_element_delimiter; } } Newline(); diff --git a/cpp/src/arrow/pretty_print.h b/cpp/src/arrow/pretty_print.h index 5d22fd5c51ab8..b04bf5a88abfa 100644 --- a/cpp/src/arrow/pretty_print.h +++ b/cpp/src/arrow/pretty_print.h @@ -77,6 +77,9 @@ struct PrettyPrintOptions { /// If true, display schema metadata when pretty-printing a Schema bool show_schema_metadata = true; + + /// Delimiter for separating individual elements of an Array (e.g. ",") + std::string array_element_delimiter = ","; }; /// \brief Print human-readable representation of RecordBatch From 883a3460dd98af447bf4d998abe40901c7f41502 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 2 Oct 2023 15:46:27 -0400 Subject: [PATCH 02/12] Add `PrimitiveTypeCustomArrayElementDelimiter` test. --- cpp/src/arrow/pretty_print_test.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 9a6e347c0bdb2..c86775b4746ce 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -200,6 +200,33 @@ TEST_F(TestPrettyPrint, PrimitiveTypeNoNewlines) { CheckPrimitive(options, is_valid, values, expected, false); } +TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { + PrettyPrintOptions options{}; + // Display array contents on one line. + options.skip_new_lines = true; + // Display maximum of 3 elements at the beginning and at the end of the array + options.window = 3; + // Use a custom array element delimiter of " | ", + // rather than the default delimiter (i.e. ","). + options.array_element_delimiter = " | "; + + // Short array without ellipsis + { + std::vector is_valid = {true, true, false, true, false}; + std::vector values = {1, 2, 3, 4, 5}; + const char* expected = "[1 | 2 | null | 4 | null]"; + CheckPrimitive(options, is_valid, values, expected, false); + } + + // Longer array with ellipsis + { + std::vector is_valid = {true, false, true, true, false, true, false, true, true}; + std::vector values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + const char* expected = "[1 | null | 3 | ... | null | 8 | 9]"; + CheckPrimitive(options, is_valid, values, expected, false); + } +} + TEST_F(TestPrettyPrint, Int8) { static const char* expected = R"expected([ 0, From 5ed5b0fd280f9db8fc9414d326d684e747563134 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 2 Oct 2023 16:04:20 -0400 Subject: [PATCH 03/12] Add `ChunkedArrayPrimitiveTypeCustomArrayDelimiter` test. --- cpp/src/arrow/pretty_print_test.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index c86775b4746ce..6287958e4a8aa 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -1047,6 +1047,36 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveType) { CheckStream(chunked_array_2, {0}, expected_2); } +TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayDelimiter) { + PrettyPrintOptions options{}; + // Display array contents on one line. + options.skip_new_lines = true; + // Display maximum of 3 elements at the beginning and at the end of the array + options.window = 3; + // Use a custom array element delimiter of " | ", + // rather than the default delimiter (i.e. ","). + options.array_element_delimiter = " | "; + + const auto chunk = ArrayFromJSON(int32(), "[1, 2, null, 4, null]"); + + // ChunkedArray with 1 chunk + { + const ChunkedArray chunked_array(chunk); + + static const char* expected = R"expected([[1 | 2 | null | 4 | null]])expected"; + CheckStream(chunked_array, options, expected); + } + + // ChunkedArray with 2 chunks + { + const ChunkedArray chunked_array({chunk, chunk}); + + static const char* expected = R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; + + CheckStream(chunked_array, options, expected); + } +} + TEST_F(TestPrettyPrint, TablePrimitive) { std::shared_ptr int_field = field("column", int32()); auto array = ArrayFromJSON(int_field->type(), "[0, 1, null, 3, null]"); From 641cfb3bfdbb369c964572bd1cae90a27e4ba7a6 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Mon, 2 Oct 2023 17:42:29 -0400 Subject: [PATCH 04/12] 1. Fix linting errors. 2. Fix typo. ChunkedArrayPrimitiveTypeCustomArrayDelimiter -> ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter. --- cpp/src/arrow/pretty_print_test.cc | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 6287958e4a8aa..6c57505a3ac57 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -220,8 +220,28 @@ TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { // Longer array with ellipsis { - std::vector is_valid = {true, false, true, true, false, true, false, true, true}; - std::vector values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector is_valid = { + true, + false, + true, + true, + false, + true, + false, + true, + true + }; + std::vector values = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + }; const char* expected = "[1 | null | 3 | ... | null | 8 | 9]"; CheckPrimitive(options, is_valid, values, expected, false); } @@ -1047,7 +1067,7 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveType) { CheckStream(chunked_array_2, {0}, expected_2); } -TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayDelimiter) { +TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { PrettyPrintOptions options{}; // Display array contents on one line. options.skip_new_lines = true; @@ -1071,7 +1091,8 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayDelimiter) { { const ChunkedArray chunked_array({chunk, chunk}); - static const char* expected = R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; + static const char* expected = + R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; CheckStream(chunked_array, options, expected); } From fd5aaf2172e3511c6f0384364bba827105b7ad7b Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 3 Oct 2023 12:58:22 -0400 Subject: [PATCH 05/12] Fix C++ linting errors by applying @kou's patch. --- cpp/src/arrow/pretty_print_test.cc | 51 ++++++++++-------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 6c57505a3ac57..cdced96e7ce7c 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -212,38 +212,19 @@ TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { // Short array without ellipsis { - std::vector is_valid = {true, true, false, true, false}; - std::vector values = {1, 2, 3, 4, 5}; - const char* expected = "[1 | 2 | null | 4 | null]"; - CheckPrimitive(options, is_valid, values, expected, false); + std::vector is_valid = {true, true, false, true, false}; + std::vector values = {1, 2, 3, 4, 5}; + const char* expected = "[1 | 2 | null | 4 | null]"; + CheckPrimitive(options, is_valid, values, expected, false); } // Longer array with ellipsis { - std::vector is_valid = { - true, - false, - true, - true, - false, - true, - false, - true, - true - }; - std::vector values = { - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9 - }; - const char* expected = "[1 | null | 3 | ... | null | 8 | 9]"; - CheckPrimitive(options, is_valid, values, expected, false); + std::vector is_valid = {true, false, true, true, false, + true, false, true, true}; + std::vector values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + const char* expected = "[1 | null | 3 | ... | null | 8 | 9]"; + CheckPrimitive(options, is_valid, values, expected, false); } } @@ -1081,20 +1062,20 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { // ChunkedArray with 1 chunk { - const ChunkedArray chunked_array(chunk); + const ChunkedArray chunked_array(chunk); - static const char* expected = R"expected([[1 | 2 | null | 4 | null]])expected"; - CheckStream(chunked_array, options, expected); + static const char* expected = R"expected([[1 | 2 | null | 4 | null]])expected"; + CheckStream(chunked_array, options, expected); } // ChunkedArray with 2 chunks { - const ChunkedArray chunked_array({chunk, chunk}); + const ChunkedArray chunked_array({chunk, chunk}); - static const char* expected = - R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; + static const char* expected = + R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; - CheckStream(chunked_array, options, expected); + CheckStream(chunked_array, options, expected); } } From 6fe19f3ad73882858139bcbcb7bba98ad228a74e Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Tue, 3 Oct 2023 13:40:37 -0400 Subject: [PATCH 06/12] Update delimiter tests to use default values for `window` and `skip_new_lines` properties. --- cpp/src/arrow/pretty_print_test.cc | 34 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index cdced96e7ce7c..b2f70e9b341c4 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -1050,11 +1050,7 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveType) { TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { PrettyPrintOptions options{}; - // Display array contents on one line. - options.skip_new_lines = true; - // Display maximum of 3 elements at the beginning and at the end of the array - options.window = 3; - // Use a custom array element delimiter of " | ", + // Use a custom array element delimiter of " |", // rather than the default delimiter (i.e. ","). options.array_element_delimiter = " | "; @@ -1064,7 +1060,15 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { { const ChunkedArray chunked_array(chunk); - static const char* expected = R"expected([[1 | 2 | null | 4 | null]])expected"; + static const char* expected = R"expected([ + [ + 1 | + 2 | + null | + 4 | + null + ] +])expected"; CheckStream(chunked_array, options, expected); } @@ -1072,8 +1076,22 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { { const ChunkedArray chunked_array({chunk, chunk}); - static const char* expected = - R"expected([[1 | 2 | null | 4 | null],[1 | 2 | null | 4 | null]])expected"; + static const char* expected = R"expected([ + [ + 1 | + 2 | + null | + 4 | + null + ], + [ + 1 | + 2 | + null | + 4 | + null + ] +])expected"; CheckStream(chunked_array, options, expected); } From da353b98d21a4b4f93ca2a286fb9921523616774 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 11:10:11 -0400 Subject: [PATCH 07/12] Add `PrettyPrintDelimiters` struct and add `array_delimiters` and `chunked_array_delimiters` properties to `PrettyPrintOptions` struct based on @kou's suggestion. --- cpp/src/arrow/pretty_print.cc | 19 ++++++++++--------- cpp/src/arrow/pretty_print.h | 24 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc index 5b99807e3858b..a4a1fa90c2878 100644 --- a/cpp/src/arrow/pretty_print.cc +++ b/cpp/src/arrow/pretty_print.cc @@ -151,14 +151,14 @@ class ArrayPrinter : public PrettyPrinter { IndentAfterNewline(); (*sink_) << "..."; if (!is_last && options_.skip_new_lines) { - (*sink_) << options_.array_element_delimiter; + (*sink_) << options_.array_delimiters.element; } i = array.length() - window - 1; } else if (array.IsNull(i)) { IndentAfterNewline(); (*sink_) << options_.null_rep; if (!is_last) { - (*sink_) << options_.array_element_delimiter; + (*sink_) << options_.array_delimiters.element; } } else { if (indent_non_null_values) { @@ -166,7 +166,7 @@ class ArrayPrinter : public PrettyPrinter { } RETURN_NOT_OK(func(i)); if (!is_last) { - (*sink_) << options_.array_element_delimiter; + (*sink_) << options_.array_delimiters.element; } } Newline(); @@ -453,12 +453,12 @@ Status PrettyPrint(const ChunkedArray& chunked_arr, const PrettyPrintOptions& op if (!skip_new_lines) { *sink << "\n"; } - bool skip_comma = true; + bool skip_element_delimiter = true; for (int i = 0; i < num_chunks; ++i) { - if (skip_comma) { - skip_comma = false; + if (skip_element_delimiter) { + skip_element_delimiter = false; } else { - (*sink) << ","; + (*sink) << options.chunked_array_delimiters.element; if (!skip_new_lines) { *sink << "\n"; } @@ -467,12 +467,13 @@ Status PrettyPrint(const ChunkedArray& chunked_arr, const PrettyPrintOptions& op for (int i = 0; i < indent; ++i) { (*sink) << " "; } - (*sink) << "...,"; + (*sink) << "..."; + (*sink) << options.chunked_array_delimiters.element; if (!skip_new_lines) { *sink << "\n"; } i = num_chunks - window - 1; - skip_comma = true; + skip_element_delimiter = true; } else { PrettyPrintOptions chunk_options = options; chunk_options.indent += options.indent_size; diff --git a/cpp/src/arrow/pretty_print.h b/cpp/src/arrow/pretty_print.h index b04bf5a88abfa..edce6f9e1a953 100644 --- a/cpp/src/arrow/pretty_print.h +++ b/cpp/src/arrow/pretty_print.h @@ -32,7 +32,21 @@ class Schema; class Status; class Table; -struct PrettyPrintOptions { +/// \class PrettyPrintDelimiters +/// \brief Options for controlling which delimiters to use when printing +/// an Array or ChunkedArray. +struct ARROW_EXPORT PrettyPrintDelimiters { + /// Delimiter for separating individual elements of an Array (e.g. ","), + /// or individual chunks of a ChunkedArray + std::string element ","; + + /// Create a PrettyPrintDelimiters instance with default values + static PrettyPrintOptions Defaults() { return PrettyPrintDelimiters(); } +} + +/// \class PrettyPrintOptions +/// \brief Options for controlling how various Arrow types should be printed. +struct ARROW_EXPORT PrettyPrintOptions { PrettyPrintOptions() = default; PrettyPrintOptions(int indent, // NOLINT runtime/explicit @@ -47,6 +61,7 @@ struct PrettyPrintOptions { skip_new_lines(skip_new_lines), truncate_metadata(truncate_metadata) {} + /// Create a PrettyPrintOptions instance with default values static PrettyPrintOptions Defaults() { return PrettyPrintOptions(); } /// Number of spaces to shift entire formatted object to the right @@ -78,8 +93,11 @@ struct PrettyPrintOptions { /// If true, display schema metadata when pretty-printing a Schema bool show_schema_metadata = true; - /// Delimiter for separating individual elements of an Array (e.g. ",") - std::string array_element_delimiter = ","; + /// Delimiters to use when printing an Array + PrettyPrintDelimiters array_delimiters = PrettyPrintDelimiters::Default(); + + /// Delimiters to use when printing a ChunkedArray + PrettyPrintDelimiters chunked_array_delimiters = PrettyPrintDelimiters::Default(); }; /// \brief Print human-readable representation of RecordBatch From 72f64472b1364b7cd9ad341c488569e9dafa0562 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 11:22:53 -0400 Subject: [PATCH 08/12] 1. Fix syntax errors. 2. Update tests. --- cpp/src/arrow/pretty_print.h | 10 ++++----- cpp/src/arrow/pretty_print_test.cc | 34 ++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/cpp/src/arrow/pretty_print.h b/cpp/src/arrow/pretty_print.h index edce6f9e1a953..019c4724257a7 100644 --- a/cpp/src/arrow/pretty_print.h +++ b/cpp/src/arrow/pretty_print.h @@ -38,11 +38,11 @@ class Table; struct ARROW_EXPORT PrettyPrintDelimiters { /// Delimiter for separating individual elements of an Array (e.g. ","), /// or individual chunks of a ChunkedArray - std::string element ","; + std::string element = ","; /// Create a PrettyPrintDelimiters instance with default values - static PrettyPrintOptions Defaults() { return PrettyPrintDelimiters(); } -} + static PrettyPrintDelimiters Defaults() { return PrettyPrintDelimiters(); } +}; /// \class PrettyPrintOptions /// \brief Options for controlling how various Arrow types should be printed. @@ -94,10 +94,10 @@ struct ARROW_EXPORT PrettyPrintOptions { bool show_schema_metadata = true; /// Delimiters to use when printing an Array - PrettyPrintDelimiters array_delimiters = PrettyPrintDelimiters::Default(); + PrettyPrintDelimiters array_delimiters = PrettyPrintDelimiters::Defaults(); /// Delimiters to use when printing a ChunkedArray - PrettyPrintDelimiters chunked_array_delimiters = PrettyPrintDelimiters::Default(); + PrettyPrintDelimiters chunked_array_delimiters = PrettyPrintDelimiters::Defaults(); }; /// \brief Print human-readable representation of RecordBatch diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index b2f70e9b341c4..83f117cbb0a28 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -200,12 +200,8 @@ TEST_F(TestPrettyPrint, PrimitiveTypeNoNewlines) { CheckPrimitive(options, is_valid, values, expected, false); } -TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { +TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) { PrettyPrintOptions options{}; - // Display array contents on one line. - options.skip_new_lines = true; - // Display maximum of 3 elements at the beginning and at the end of the array - options.window = 3; // Use a custom array element delimiter of " | ", // rather than the default delimiter (i.e. ","). options.array_element_delimiter = " | "; @@ -214,7 +210,13 @@ TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { { std::vector is_valid = {true, true, false, true, false}; std::vector values = {1, 2, 3, 4, 5}; - const char* expected = "[1 | 2 | null | 4 | null]"; + static const char* expected = R"expected([ + 1 | + 2 | + null | + 4 | + null +])expected"; CheckPrimitive(options, is_valid, values, expected, false); } @@ -223,7 +225,14 @@ TEST_F(TestPrettyPrint, PrimitiveTypeCustomArrayElementDelimiter) { std::vector is_valid = {true, false, true, true, false, true, false, true, true}; std::vector values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - const char* expected = "[1 | null | 3 | ... | null | 8 | 9]"; + static const char* expected = R"expected([ + 1 | + null | + 3 | + ... | + 8 | + 9 | +])expected"; CheckPrimitive(options, is_valid, values, expected, false); } } @@ -1048,11 +1057,14 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveType) { CheckStream(chunked_array_2, {0}, expected_2); } -TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { +TEST_F(TestPrettyPrint, ChunkedArrayCustomElementDelimiter) { PrettyPrintOptions options{}; - // Use a custom array element delimiter of " |", + // Use a custom ChunkedArray element delimiter of ";", // rather than the default delimiter (i.e. ","). - options.array_element_delimiter = " | "; + options.array_delimiters.element = ";"; + // Use a custom Array element delimiter of " | ", + // rather than the default delimiter (i.e. ","). + options.array_delimiters.element = " | "; const auto chunk = ArrayFromJSON(int32(), "[1, 2, null, 4, null]"); @@ -1083,7 +1095,7 @@ TEST_F(TestPrettyPrint, ChunkedArrayPrimitiveTypeCustomArrayElementDelimiter) { null | 4 | null - ], + ]; [ 1 | 2 | From 573872be00e78338519286c3533f2262c9e694ea Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 11:24:00 -0400 Subject: [PATCH 09/12] Use `options.array_delimiters.element` instead of `array_element_delimiter`. --- cpp/src/arrow/pretty_print_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 83f117cbb0a28..76218e7ee778b 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -204,7 +204,7 @@ TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) { PrettyPrintOptions options{}; // Use a custom array element delimiter of " | ", // rather than the default delimiter (i.e. ","). - options.array_element_delimiter = " | "; + options.array_delimiters.element = " | "; // Short array without ellipsis { From fc24e0343d20b31c73e7167192b204bee75e7e97 Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 11:55:56 -0400 Subject: [PATCH 10/12] Update tests. --- cpp/src/arrow/pretty_print_test.cc | 40 +++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 76218e7ee778b..93989ab65cbe4 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -212,7 +212,7 @@ TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) { std::vector values = {1, 2, 3, 4, 5}; static const char* expected = R"expected([ 1 | - 2 | + 2 | null | 4 | null @@ -222,16 +222,38 @@ TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) { // Longer array with ellipsis { - std::vector is_valid = {true, false, true, true, false, - true, false, true, true}; - std::vector values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector is_valid = {true, false, true}; + std::vector values = {1, 2, 3}; + // Append 20 copies of the value "10" to the end of the values vector. + values.insert(values.end(), 20, 10); + // Append 20 copies of the value "true" to the end of the validity bitmap vector. + is_valid.insert(is_valid.end(), 20, 10); + // Append the values 4, 5, and 6 to the end of the values vector. + values.insert(values.end(), {4, 5, 6}); + // Append the values true, false, and true to the end of the validity bitmap vector. + is_valid.insert(is_valid.end(), {true, false, true}); static const char* expected = R"expected([ 1 | - null | + null | 3 | - ... | - 8 | - 9 | + 10 | + 10 | + 10 | + 10 | + 10 | + 10 | + 10 | + ... + 10 | + 10 | + 10 | + 10 | + 10 | + 10 | + 10 | + 4 | + null | + 6 ])expected"; CheckPrimitive(options, is_valid, values, expected, false); } @@ -1061,7 +1083,7 @@ TEST_F(TestPrettyPrint, ChunkedArrayCustomElementDelimiter) { PrettyPrintOptions options{}; // Use a custom ChunkedArray element delimiter of ";", // rather than the default delimiter (i.e. ","). - options.array_delimiters.element = ";"; + options.chunked_array_delimiters.element = ";"; // Use a custom Array element delimiter of " | ", // rather than the default delimiter (i.e. ","). options.array_delimiters.element = " | "; From f30e433f14d2295c4bf868404ee67a090c50de6c Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 12:22:58 -0400 Subject: [PATCH 11/12] Fix clang-format linting errors. --- cpp/src/arrow/pretty_print.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/pretty_print.h b/cpp/src/arrow/pretty_print.h index 019c4724257a7..96a214c68b8a6 100644 --- a/cpp/src/arrow/pretty_print.h +++ b/cpp/src/arrow/pretty_print.h @@ -36,12 +36,12 @@ class Table; /// \brief Options for controlling which delimiters to use when printing /// an Array or ChunkedArray. struct ARROW_EXPORT PrettyPrintDelimiters { - /// Delimiter for separating individual elements of an Array (e.g. ","), - /// or individual chunks of a ChunkedArray - std::string element = ","; + /// Delimiter for separating individual elements of an Array (e.g. ","), + /// or individual chunks of a ChunkedArray + std::string element = ","; - /// Create a PrettyPrintDelimiters instance with default values - static PrettyPrintDelimiters Defaults() { return PrettyPrintDelimiters(); } + /// Create a PrettyPrintDelimiters instance with default values + static PrettyPrintDelimiters Defaults() { return PrettyPrintDelimiters(); } }; /// \class PrettyPrintOptions From eedee47754e66f6f39520496848f45d90b5a02bf Mon Sep 17 00:00:00 2001 From: Kevin Gurney Date: Wed, 4 Oct 2023 13:08:19 -0400 Subject: [PATCH 12/12] Fix typo. --- cpp/src/arrow/pretty_print_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 93989ab65cbe4..45bb4ecffe054 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -227,7 +227,7 @@ TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) { // Append 20 copies of the value "10" to the end of the values vector. values.insert(values.end(), 20, 10); // Append 20 copies of the value "true" to the end of the validity bitmap vector. - is_valid.insert(is_valid.end(), 20, 10); + is_valid.insert(is_valid.end(), 20, true); // Append the values 4, 5, and 6 to the end of the values vector. values.insert(values.end(), {4, 5, 6}); // Append the values true, false, and true to the end of the validity bitmap vector.