sgilmore10 commented on a change in pull request #10305: URL: https://github.com/apache/arrow/pull/10305#discussion_r657193522
########## File path: matlab/src/feather_writer.cc ########## @@ -316,22 +331,46 @@ Status FeatherWriter::WriteVariables(const mxArray* variables) { std::string name_str = internal::MxArrayToString(name); std::string type_str = internal::MxArrayToString(type); + std::shared_ptr<arrow::DataType> datatype = + internal::ConvertMatlabTypeStringToArrowDataType(type_str); + std::shared_ptr<arrow::Field> field = + std::make_shared<arrow::Field>(name_str, datatype); + + arrow::Result<std::shared_ptr<ResizableBuffer>> maybe_buffer = + arrow::AllocateResizableBuffer(internal::BitPackedLength(num_rows_)); + RETURN_NOT_OK(maybe_buffer); + std::shared_ptr<ResizableBuffer> validity_bitmap = maybe_buffer.ValueOrDie(); + // Populate bit-packed arrow::Buffer using validity data in the mxArray*. internal::BitPackBuffer(valid, validity_bitmap); // Wrap mxArray data in an arrow::Array of the equivalent type. - std::unique_ptr<Array> array = + std::shared_ptr<Array> array = internal::WriteVariableData(data, type_str, validity_bitmap); // Verify that the arrow::Array has the right number of elements. - internal::ValidateNumRows(array->length(), this->num_rows_); + internal::ValidateNumRows(array->length(), num_rows_); + + // Append the field to the schema builder + RETURN_NOT_OK(schema_builder.AddField(field)); - // Write another column to the Feather file. - ARROW_RETURN_NOT_OK(this->table_writer_->Append(name_str, *array)); + // Store the table column + table_columns.push_back(array); } + // Create the table schema + arrow::Result<std::shared_ptr<arrow::Schema>> table_schema_result = + schema_builder.Finish(); + RETURN_NOT_OK(table_schema_result); + + std::shared_ptr<arrow::Schema> table_schema = table_schema_result.ValueOrDie(); Review comment: will do. ########## File path: matlab/src/feather_writer.cc ########## @@ -316,22 +331,46 @@ Status FeatherWriter::WriteVariables(const mxArray* variables) { std::string name_str = internal::MxArrayToString(name); std::string type_str = internal::MxArrayToString(type); + std::shared_ptr<arrow::DataType> datatype = + internal::ConvertMatlabTypeStringToArrowDataType(type_str); + std::shared_ptr<arrow::Field> field = + std::make_shared<arrow::Field>(name_str, datatype); + + arrow::Result<std::shared_ptr<ResizableBuffer>> maybe_buffer = + arrow::AllocateResizableBuffer(internal::BitPackedLength(num_rows_)); + RETURN_NOT_OK(maybe_buffer); + std::shared_ptr<ResizableBuffer> validity_bitmap = maybe_buffer.ValueOrDie(); Review comment: will do. ########## File path: matlab/src/feather_writer.cc ########## @@ -248,60 +279,44 @@ Status FeatherWriter::Open(const std::string& filename, *feather_writer = std::shared_ptr<FeatherWriter>(new FeatherWriter()); // Open a FileOutputStream corresponding to the provided filename. - std::shared_ptr<io::OutputStream> writable_file(nullptr); - ARROW_RETURN_NOT_OK(io::FileOutputStream::Open(filename, &writable_file)); - - // TableWriter::Open expects a shared_ptr to an OutputStream. - // Open the Feather file for writing with a TableWriter. - return ipc::feather::TableWriter::Open(writable_file, - &(*feather_writer)->table_writer_); -} - -// Write table metadata to the Feather file from a mxArray*. -void FeatherWriter::WriteMetadata(const mxArray* metadata) { - // Verify that all required fieldnames are provided. - internal::ValidateMxStructField(metadata, "Description", mxCHAR_CLASS, true); - internal::ValidateMxStructField(metadata, "NumRows", mxDOUBLE_CLASS, false); - internal::ValidateMxStructField(metadata, "NumVariables", mxDOUBLE_CLASS, false); - - // Convert Description to a std::string and set on FeatherWriter and TableWriter. - std::string description = - internal::MxArrayToString(mxGetField(metadata, 0, "Description")); - this->description_ = description; - this->table_writer_->SetDescription(description); - - // Get the NumRows field in the struct array and set on TableWriter. - this->num_rows_ = static_cast<int64_t>(mxGetScalar(mxGetField(metadata, 0, "NumRows"))); - this->table_writer_->SetNumRows(this->num_rows_); + arrow::Result<std::shared_ptr<arrow::io::OutputStream>> maybe_file_output_stream = + io::FileOutputStream::Open(filename, &((*feather_writer)->file_output_stream_)); + RETURN_NOT_OK(maybe_file_output_stream); + (*feather_writer)->file_output_stream_ = maybe_file_output_stream.ValueOrDie(); Review comment: will do. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org