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

Method make

matlab/src/cpp/arrow/matlab/array/proxy/string_array.cc:35–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35libmexclass::proxy::MakeResult StringArray::make(
36 const libmexclass::proxy::FunctionArguments& constructor_arguments) {
37 namespace mda = ::matlab::data;
38
39 mda::StructArray opts = constructor_arguments[0];
40 const mda::StringArray array_mda = opts[0]["MatlabArray"];
41 const mda::TypedArray<bool> unpacked_validity_bitmap_mda = opts[0]["Valid"];
42
43 // Convert UTF-16 encoded MATLAB string values to UTF-8 encoded Arrow string values.
44 const auto array_length = array_mda.getNumberOfElements();
45 std::vector<std::string> strings;
46 strings.reserve(array_length);
47 for (const auto& str : array_mda) {
48 if (!str) {
49 // Substitute MATLAB string(missing) values with the empty string value ("")
50 strings.emplace_back("");
51 } else {
52 MATLAB_ASSIGN_OR_ERROR(auto str_utf8, arrow::util::UTF16StringToUTF8(*str),
53 error::UNICODE_CONVERSION_ERROR_ID);
54 strings.push_back(std::move(str_utf8));
55 }
56 }
57
58 auto unpacked_validity_bitmap_ptr = bit::extract_ptr(unpacked_validity_bitmap_mda);
59
60 // Build up an Arrow StringArray from a vector of UTF-8 encoded strings.
61 arrow::StringBuilder builder;
62 MATLAB_ERROR_IF_NOT_OK(builder.AppendValues(strings, unpacked_validity_bitmap_ptr),
63 error::STRING_BUILDER_APPEND_FAILED);
64 MATLAB_ASSIGN_OR_ERROR(auto array, builder.Finish(),
65 error::STRING_BUILDER_FINISH_FAILED);
66 auto typed_array = std::static_pointer_cast<arrow::StringArray>(array);
67 return std::make_shared<arrow::matlab::array::proxy::StringArray>(
68 std::move(typed_array));
69}
70
71void StringArray::toMATLAB(libmexclass::proxy::method::Context& context) {
72 namespace mda = ::matlab::data;

Callers

nothing calls this directly

Calls 5

extract_ptrFunction · 0.85
emplace_backMethod · 0.80
push_backMethod · 0.80
reserveMethod · 0.45
AppendValuesMethod · 0.45

Tested by

no test coverage detected