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