| 62 | } |
| 63 | |
| 64 | void TableWriter::write(libmexclass::proxy::method::Context& context) { |
| 65 | namespace csv = ::arrow::csv; |
| 66 | namespace mda = ::matlab::data; |
| 67 | using TableProxy = ::arrow::matlab::tabular::proxy::Table; |
| 68 | |
| 69 | mda::StructArray opts = context.inputs[0]; |
| 70 | const mda::TypedArray<uint64_t> table_proxy_id_mda = opts[0]["TableProxyID"]; |
| 71 | const uint64_t table_proxy_id = table_proxy_id_mda[0]; |
| 72 | |
| 73 | auto proxy = libmexclass::proxy::ProxyManager::getProxy(table_proxy_id); |
| 74 | auto table_proxy = std::static_pointer_cast<TableProxy>(proxy); |
| 75 | auto table = table_proxy->unwrap(); |
| 76 | |
| 77 | MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(const auto output_stream, |
| 78 | arrow::io::FileOutputStream::Open(filename), |
| 79 | context, error::FAILED_TO_OPEN_FILE_FOR_WRITE); |
| 80 | const auto options = csv::WriteOptions::Defaults(); |
| 81 | MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(csv::WriteCSV(*table, options, output_stream.get()), |
| 82 | context, error::CSV_FAILED_TO_WRITE_TABLE); |
| 83 | } |
| 84 | } // namespace arrow::matlab::io::csv::proxy |