You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/09/07 10:52:20 UTC
[GitHub] [arrow] romainfrancois opened a new pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
romainfrancois opened a new pull request #8122:
URL: https://github.com/apache/arrow/pull/8122
I don't think this is about `shared_ptr_is_null()` as indicated in the jira issue: https://issues.apache.org/jira/browse/ARROW-9557 I guess profvis (or probably the underlying profiler) struggles with that case.
What happens though is that `$ReadTable()` first calls `$GetSchema()`:
```r
ReadTable = function(col_select = NULL) {
col_select <- enquo(col_select)
if (quo_is_null(col_select)) {
shared_ptr(Table, parquet___arrow___FileReader__ReadTable1(self))
} else {
all_vars <- shared_ptr(Schema, parquet___arrow___FileReader__GetSchema(self))$names
indices <- match(vars_select(all_vars, !!col_select), all_vars) - 1L
shared_ptr(Table, parquet___arrow___FileReader__ReadTable2(self, indices))
}
}
```
and that's expensive for some reason:
``` r
library(arrow)
#>
#> Attaching package: 'arrow'
#> The following object is masked from 'package:utils':
#>
#> timestamp
library(vctrs)
#>
#> Attaching package: 'vctrs'
#> The following objects are masked from 'package:arrow':
#>
#> field, list_of
library(purrr)
df <- new_data_frame(
map(set_names(1:4000), ~rnorm(50000))
)
tf <- tempfile()
write_parquet(df, tf)
reader <- ParquetFileReader$create(tf)
parquet___arrow___FileReader__GetSchema <- arrow:::parquet___arrow___FileReader__GetSchema
parquet___arrow___FileReader__ReadColumn <- arrow:::parquet___arrow___FileReader__ReadColumn
system.time({
for (i in 1:4000) {
parquet___arrow___FileReader__GetSchema(reader)
}
})
#> user system elapsed
#> 43.809 1.744 47.962
system.time({
for (i in 1:4000) {
parquet___arrow___FileReader__ReadColumn(reader, i)
}
})
#> user system elapsed
#> 3.035 2.448 10.606
```
<sup>Created on 2020-09-07 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0.9001)</sup>
So we probably need a more complete R6 wrapper around `parquet::arrow::FileReader`. https://github.com/apache/arrow/blob/master/cpp/src/parquet/arrow/reader.h#L107
As a start, here is `$GetColumn()`
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] nealrichardson commented on a change in pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
nealrichardson commented on a change in pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#discussion_r492850251
##########
File path: r/R/parquet.R
##########
@@ -409,10 +420,20 @@ ParquetFileWriter$create <- function(schema,
#'
#' @section Methods:
#'
-#' - `$ReadTable(col_select)`: get an `arrow::Table` from the file, possibly
-#' with columns filtered by a character vector of column names or a
-#' `tidyselect` specification.
+#' - `$ReadTable(column_indices)`: get an `arrow::Table` from the file. The optional
+#' `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroup(i, column_indices)`: get an `arrow::Table` by reading the `i`th row group.
Review comment:
Is `i` also 0-based?
##########
File path: r/R/parquet.R
##########
@@ -409,10 +420,20 @@ ParquetFileWriter$create <- function(schema,
#'
#' @section Methods:
#'
-#' - `$ReadTable(col_select)`: get an `arrow::Table` from the file, possibly
-#' with columns filtered by a character vector of column names or a
-#' `tidyselect` specification.
+#' - `$ReadTable(column_indices)`: get an `arrow::Table` from the file. The optional
+#' `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroup(i, column_indices)`: get an `arrow::Table` by reading the `i`th row group.
+#' The optional `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroups(row_groups, column_indices)`: get an `arrow::Table` by reading several row groups.
Review comment:
are `row_groups` also integers? 0-based?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-697232130
This returns too early, I believe this needs to be `RETURN_NOT_OK` instead of `return`:
https://github.com/apache/arrow/blob/master/cpp/src/parquet/arrow/reader.cc#L185
```cpp
Status BoundsCheck(const std::vector<int>& row_groups,
const std::vector<int>& column_indices) {
for (int i : row_groups) {
return BoundsCheckRowGroup(i);
}
for (int i : column_indices) {
return BoundsCheckColumn(i);
}
return Status::OK();
}
```
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-696593899
The methods of `ParquetFileReader` no longer use tidyselect, i.e. you can use `$ReadTable()` or `$ReadTable(column_indices)` with an 0-based integer vector so this does not have to pay for retrieving the schema (which appears to be expensive) and invoke tidy selection.
`read_parquet(col_select=<tidy selection spec>)` is still supported though, and does call `$GetSchema()`.
In addition, methods `ReadRowGroup()` and `$ReadRowGroups()` have been added.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] nealrichardson closed pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
nealrichardson closed pull request #8122:
URL: https://github.com/apache/arrow/pull/8122
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-697227723
I added some tests for `ReadRowGroup(s)()` and clarified about 0-based.
I'm getting a weird error in some cases with `ReadRowGroups()`:
``` r
library(arrow, warn.conflicts = FALSE)
tab <- Table$create(x = 1:100)
tf <- tempfile()
write_parquet(tab, tf, chunk_size = 10)
reader <- ParquetFileReader$create(tf)
# sensible error
reader$ReadRowGroups(-2)
#> Error in parquet___arrow___FileReader__ReadRowGroups1(self, row_groups): Invalid: Some index in row_group_indices is -2, which is either < 0 or >= num_row_groups(10)
#> In /Users/romainfrancois/git/apache/arrow/cpp/src/parquet/arrow/reader.cc, line 842, code: BoundsCheck(row_groups, column_indices)
# weird error
reader$ReadRowGroups(c(0, -2))
#> Error in parquet___arrow___FileReader__ReadRowGroups1(self, row_groups): IOError: The file only has 0 columns, requested metadata for column: 0
#> In /Users/romainfrancois/git/apache/arrow/cpp/src/parquet/arrow/reader.cc, line 873, code: final_status
```
<sup>Created on 2020-09-23 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0.9001)</sup>
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] nealrichardson commented on a change in pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
nealrichardson commented on a change in pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#discussion_r493703796
##########
File path: r/R/parquet.R
##########
@@ -432,19 +453,45 @@ ParquetFileReader <- R6Class("ParquetFileReader",
active = list(
num_rows = function() {
as.integer(parquet___arrow___FileReader__num_rows(self))
+ },
+ num_columns = function() {
+ parquet___arrow___FileReader__num_columns(self)
+ },
+ num_row_groups = function() {
+ parquet___arrow___FileReader__num_row_groups(self)
}
),
public = list(
- ReadTable = function(col_select = NULL) {
- col_select <- enquo(col_select)
- if (quo_is_null(col_select)) {
+ ReadTable = function(column_indices = NULL) {
+ if (is.null(column_indices)) {
shared_ptr(Table, parquet___arrow___FileReader__ReadTable1(self))
+ } else if (is_integerish(column_indices)) {
Review comment:
Hmm, the others don't check is_integerish, and if you do check that here, you have a missing `else` case to add. Presumably `vec_cast` will error for you if you give it something that isn't reasonably an integer?
```suggestion
} else {
```
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] bkietz commented on a change in pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
bkietz commented on a change in pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#discussion_r493791622
##########
File path: cpp/src/parquet/arrow/reader.cc
##########
@@ -174,10 +174,10 @@ class FileReaderImpl : public FileReader {
Status BoundsCheck(const std::vector<int>& row_groups,
const std::vector<int>& column_indices) {
for (int i : row_groups) {
- return BoundsCheckRowGroup(i);
+ RETURN_NOT_OK(BoundsCheckRowGroup(i));
Review comment:
No need to wait. That's an embarrassing bug, thanks for catching it
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] nealrichardson commented on a change in pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
nealrichardson commented on a change in pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#discussion_r492850251
##########
File path: r/R/parquet.R
##########
@@ -409,10 +420,20 @@ ParquetFileWriter$create <- function(schema,
#'
#' @section Methods:
#'
-#' - `$ReadTable(col_select)`: get an `arrow::Table` from the file, possibly
-#' with columns filtered by a character vector of column names or a
-#' `tidyselect` specification.
+#' - `$ReadTable(column_indices)`: get an `arrow::Table` from the file. The optional
+#' `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroup(i, column_indices)`: get an `arrow::Table` by reading the `i`th row group.
Review comment:
Is `i` also 0-based?
##########
File path: r/R/parquet.R
##########
@@ -409,10 +420,20 @@ ParquetFileWriter$create <- function(schema,
#'
#' @section Methods:
#'
-#' - `$ReadTable(col_select)`: get an `arrow::Table` from the file, possibly
-#' with columns filtered by a character vector of column names or a
-#' `tidyselect` specification.
+#' - `$ReadTable(column_indices)`: get an `arrow::Table` from the file. The optional
+#' `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroup(i, column_indices)`: get an `arrow::Table` by reading the `i`th row group.
+#' The optional `column_indices=` argument is a 0-based integer vector indicating which columns to retain.
+#' - `$ReadRowGroups(row_groups, column_indices)`: get an `arrow::Table` by reading several row groups.
Review comment:
are `row_groups` also integers? 0-based?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-696593899
The methods of `ParquetFileReader` no longer use tidyselect, i.e. you can use `$ReadTable()` or `$ReadTable(column_indices)` with an 0-based integer vector so this does not have to pay for retrieving the schema (which appears to be expensive) and invoke tidy selection.
`read_parquet(col_select=<tidy selection spec>)` is still supported though, and does call `$GetSchema()`.
In addition, methods `ReadRowGroup()` and `$ReadRowGroups()` have been added.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] nealrichardson closed pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
nealrichardson closed pull request #8122:
URL: https://github.com/apache/arrow/pull/8122
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-688284689
also, I guess `$ReadTable()` could either be simplified to only use column indices (as in the C++ function)
```cpp
virtual ::arrow::Status ReadTable(const std::vector<int>& column_indices,
std::shared_ptr<::arrow::Table>* out) = 0;
```
or maybe have some arguments to turn off potentially expensive tidyselect logic, that has to retrieve the schema ...
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#issuecomment-688252332
https://issues.apache.org/jira/browse/ARROW-9557
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [arrow] romainfrancois commented on a change in pull request #8122: ARROW-9557: [R] Iterating over parquet columns is slow in R
Posted by GitBox <gi...@apache.org>.
romainfrancois commented on a change in pull request #8122:
URL: https://github.com/apache/arrow/pull/8122#discussion_r493346352
##########
File path: cpp/src/parquet/arrow/reader.cc
##########
@@ -174,10 +174,10 @@ class FileReaderImpl : public FileReader {
Status BoundsCheck(const std::vector<int>& row_groups,
const std::vector<int>& column_indices) {
for (int i : row_groups) {
- return BoundsCheckRowGroup(i);
+ RETURN_NOT_OK(BoundsCheckRowGroup(i));
Review comment:
ping @bkietz I'm happy to revert this commit and have another pr if preferred.
----------------------------------------------------------------
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:
users@infra.apache.org