| 37 | |
| 38 | template <typename TabularType> |
| 39 | arrow::Result<std::string> get_row_as_string( |
| 40 | const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) { |
| 41 | std::stringstream ss; |
| 42 | const int64_t row_index = matlab_row_index - 1; |
| 43 | if (row_index >= tabular_object->num_rows() || row_index < 0) { |
| 44 | ss << "Invalid Row Index: " << matlab_row_index; |
| 45 | return arrow::Status::Invalid(ss.str()); |
| 46 | } |
| 47 | |
| 48 | const auto opts = make_pretty_print_options(); |
| 49 | const auto num_columns = tabular_object->num_columns(); |
| 50 | const auto& columns = tabular_object->columns(); |
| 51 | |
| 52 | for (int32_t i = 0; i < num_columns; ++i) { |
| 53 | const auto& column = columns[i]; |
| 54 | const auto type_id = column->type()->id(); |
| 55 | if (arrow::is_primitive(type_id) || arrow::is_string(type_id)) { |
| 56 | auto slice = column->Slice(row_index, 1); |
| 57 | ARROW_RETURN_NOT_OK(arrow::PrettyPrint(*slice, opts, &ss)); |
| 58 | } else if (type_id == arrow::Type::type::STRUCT) { |
| 59 | // Use <Struct> as a placeholder since we don't have a good |
| 60 | // way to display StructArray elements horizontally on screen. |
| 61 | ss << "<Struct>"; |
| 62 | } else if (type_id == arrow::Type::type::LIST) { |
| 63 | // Use <List> as a placeholder since we don't have a good |
| 64 | // way to display ListArray elements horizontally on screen. |
| 65 | ss << "<List>"; |
| 66 | } else { |
| 67 | return arrow::Status::NotImplemented("Datatype " + column->type()->ToString() + |
| 68 | "is not currently supported for display."); |
| 69 | } |
| 70 | |
| 71 | if (i + 1 < num_columns) { |
| 72 | // Only add the delimiter if there is at least |
| 73 | // one more element to print. |
| 74 | ss << " | "; |
| 75 | } |
| 76 | } |
| 77 | return ss.str(); |
| 78 | } |
| 79 | } // namespace arrow::matlab::tabular |
nothing calls this directly
no test coverage detected