MCPcopy Create free account
hub / github.com/apache/arrow / get_row_as_string

Function get_row_as_string

matlab/src/cpp/arrow/matlab/tabular/get_row_as_string.h:39–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38template <typename TabularType>
39arrow::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

Callers

nothing calls this directly

Calls 14

strMethod · 0.80
columnsMethod · 0.80
InvalidFunction · 0.50
is_primitiveFunction · 0.50
is_stringFunction · 0.50
PrettyPrintFunction · 0.50
NotImplementedFunction · 0.50
num_rowsMethod · 0.45
num_columnsMethod · 0.45
idMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected