Skip to content

Commit

Permalink
simplify approach (just copy full array instead of slice+concat)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Jun 20, 2024
1 parent 85fb619 commit 595ad89
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions cpp/src/arrow/pretty_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <vector>

#include "arrow/array.h"
#include "arrow/array/concatenate.h"
#include "arrow/chunked_array.h"
#include "arrow/record_batch.h"
#include "arrow/status.h"
Expand Down Expand Up @@ -414,21 +413,6 @@ Status ArrayPrinter::WriteValidityBitmap(const Array& array) {
}
}

Result<std::shared_ptr<Array>> CopyStartEndToCPU(const Array& arr, int window) {
std::shared_ptr<Array> arr_sliced;
if (arr.length() > (2 * window + 1)) {
ARROW_ASSIGN_OR_RAISE(auto arr_start,
arr.Slice(0, window + 1)->CopyTo(default_cpu_memory_manager()));
ARROW_ASSIGN_OR_RAISE(
auto arr_end,
arr.Slice(arr.length() - window - 1)->CopyTo(default_cpu_memory_manager()));
ARROW_ASSIGN_OR_RAISE(arr_sliced, Concatenate({arr_start, arr_end}));
} else {
ARROW_ASSIGN_OR_RAISE(arr_sliced, arr.CopyTo(default_cpu_memory_manager()));
}
return arr_sliced;
}

} // namespace

Status PrettyPrint(const Array& arr, int indent, std::ostream* sink) {
Expand All @@ -441,8 +425,8 @@ Status PrettyPrint(const Array& arr, const PrettyPrintOptions& options,
std::ostream* sink) {
ArrayPrinter printer(options, sink);
if (arr.device_type() != DeviceAllocationType::kCPU) {
ARROW_ASSIGN_OR_RAISE(auto arr_sliced, CopyStartEndToCPU(arr, options.window));
return printer.Print(*arr_sliced);
ARROW_ASSIGN_OR_RAISE(auto arr_copied, arr.CopyTo(default_cpu_memory_manager()));
return printer.Print(*arr_copied);
}
return printer.Print(arr);
}
Expand Down

0 comments on commit 595ad89

Please sign in to comment.