-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-8354: [R] Fix segfault in Table to Array conversion #6871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -656,8 +656,15 @@ class Converter_Null : public Converter { | |
| return Status::OK(); | ||
| } | ||
| }; | ||
|
|
||
| std::shared_ptr<Converter> Converter::Make(const ArrayVector& arrays) { | ||
| switch (arrays[0]->type_id()) { | ||
| if (arrays.empty()) { | ||
|
||
| Rcpp::stop(tfm::format("Must have at least one array to create a converter")); | ||
| } | ||
|
|
||
| auto type = arrays[0]->type(); | ||
|
|
||
| switch (type->id()) { | ||
| // direct support | ||
| case Type::INT32: | ||
| return std::make_shared<arrow::r::Converter_SimpleArray<INTSXP>>(arrays); | ||
|
|
@@ -742,7 +749,7 @@ std::shared_ptr<Converter> Converter::Make(const ArrayVector& arrays) { | |
| break; | ||
| } | ||
|
|
||
| Rcpp::stop(tfm::format("cannot handle Array of type %s", arrays[0]->type()->name())); | ||
| Rcpp::stop(tfm::format("cannot handle Array of type %s", type->name())); | ||
| return nullptr; | ||
| } | ||
|
|
||
|
|
@@ -813,7 +820,6 @@ SEXP Array__as_vector(const std::shared_ptr<arrow::Array>& array) { | |
|
|
||
| // [[arrow::export]] | ||
| SEXP ChunkedArray__as_vector(const std::shared_ptr<arrow::ChunkedArray>& chunked_array) { | ||
| // NB: this segfaults if there are 0 chunks (presumably something tries chunks[0]) | ||
| return arrow::r::ArrayVector__as_vector(chunked_array->length(), | ||
| chunked_array->chunks()); | ||
| } | ||
|
|
@@ -849,7 +855,6 @@ Rcpp::List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table, | |
| std::vector<std::shared_ptr<arrow::r::Converter>> converters(nc); | ||
|
|
||
| for (int64_t i = 0; i < nc; i++) { | ||
| // This crashes if num_chunks == 0 | ||
| converters[i] = arrow::r::Converter::Make(table->column(i)->chunks()); | ||
| names[i] = table->field(i)->name(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should accept the type of
arraysexplicitly; a Converter should not fail when arrays is empty. Instead the result of conversion should also be empty.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated https://issues.apache.org/jira/browse/ARROW-7798 to include this. I tried to quickly refactor what you suggest but it bubbles to rewriting almost all methods/functions of the file.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also lead me to find a bug with handling Dictionary ChunkedArray, https://issues.apache.org/jira/browse/ARROW-8374