| 1061 | Status PrintDiff(const Array& left, const Array& right, std::ostream* os); |
| 1062 | |
| 1063 | Status PrintDiff(const Array& left, const Array& right, int64_t left_offset, |
| 1064 | int64_t left_length, int64_t right_offset, int64_t right_length, |
| 1065 | std::ostream* os) { |
| 1066 | if (os == nullptr) { |
| 1067 | return Status::OK(); |
| 1068 | } |
| 1069 | |
| 1070 | if (!left.type()->Equals(right.type())) { |
| 1071 | *os << "# Array types differed: " << *left.type() << " vs " << *right.type() |
| 1072 | << std::endl; |
| 1073 | return Status::OK(); |
| 1074 | } |
| 1075 | |
| 1076 | if (left.type()->id() == Type::DICTIONARY) { |
| 1077 | *os << "# Dictionary arrays differed" << std::endl; |
| 1078 | |
| 1079 | const auto& left_dict = checked_cast<const DictionaryArray&>(left); |
| 1080 | const auto& right_dict = checked_cast<const DictionaryArray&>(right); |
| 1081 | |
| 1082 | *os << "## dictionary diff"; |
| 1083 | auto pos = os->tellp(); |
| 1084 | RETURN_NOT_OK(PrintDiff(*left_dict.dictionary(), *right_dict.dictionary(), os)); |
| 1085 | if (os->tellp() == pos) { |
| 1086 | *os << std::endl; |
| 1087 | } |
| 1088 | |
| 1089 | *os << "## indices diff"; |
| 1090 | pos = os->tellp(); |
| 1091 | RETURN_NOT_OK(PrintDiff(*left_dict.indices(), *right_dict.indices(), os)); |
| 1092 | if (os->tellp() == pos) { |
| 1093 | *os << std::endl; |
| 1094 | } |
| 1095 | return Status::OK(); |
| 1096 | } |
| 1097 | |
| 1098 | const auto left_slice = left.Slice(left_offset, left_length); |
| 1099 | const auto right_slice = right.Slice(right_offset, right_length); |
| 1100 | ARROW_ASSIGN_OR_RAISE(auto edits, |
| 1101 | Diff(*left_slice, *right_slice, default_memory_pool())); |
| 1102 | ARROW_ASSIGN_OR_RAISE(auto formatter, MakeUnifiedDiffFormatter(*left.type(), os)); |
| 1103 | return formatter(*edits, *left_slice, *right_slice); |
| 1104 | } |
| 1105 | |
| 1106 | Status PrintDiff(const Array& left, const Array& right, std::ostream* os) { |
| 1107 | return PrintDiff(left, right, 0, left.length(), 0, right.length(), os); |