stufield opened a new issue, #55578:
URL: https://github.com/apache/arrow/issues/55578

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   ## reprex
   
   ```r
   library(arrow)
   
   df <- data.frame(a = 1:2)
   df$nested <- list(data.frame(x = 1, y = "p"), data.frame(x = 2, y = "q"))
   df$b <- c("b1", "b2")
   df$c <- c(TRUE, FALSE)
   
   tf <- tempfile(fileext = ".parquet")
   write_parquet(df, tf)
   
   names(read_parquet(tf, col_select = "b"))
   #> [1] "nested"
   names(read_parquet(tf, col_select = "c"))
   #> [1] "b"
   names(read_parquet(tf, col_select = c("a", "c")))
   #> [1] "a" "b"
   
   # Expected: "b", "c", c("a", "c")
   
   # Selecting after reading as a Table gives the right column
   names(read_parquet(tf, as_data_frame = FALSE)[, "c"])
   #> [1] "c"
   
   # 4 top-level fields, 5 parquet leaf columns
   reader <- ParquetFileReader$create(tf)
   length(reader$GetSchema()$names)
   #> [1] 4
   reader$num_columns
   #> [1] 5
   ```
   
   ## Likely cause
   
   `read_parquet()` computes `indices` with `tidyselect::eval_select()` on
   `as.data.frame(reader$GetSchema())`, i.e. top-level field positions, and
   passes them to `reader$ReadTable(indices)`.
   `ReadTable()` appears to treat them as parquet leaf column indices. 
   Each nested column with more than one leaf shifts every later column, so 
   the result is off by one leaf per extra leaf. 
   
   In the `reprex`, field index 2 (`b`) maps to leaf 2 (`nested.y`), so 
`nested` is
   returned.
   
   ## Possible fix
   translate the selected field indices to leaf
   indices before calling `ReadTable()`, or read by field.
   
   ## Reproduced with
   
   - `arrow` 23.0.1.2 and 26.0.1 (CRAN binaries)
   - R 4.6.0, aarch64-apple-darwin23 (macOS)
   
   ### Component(s)
   
   R


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to