Skip to content

[R] read_parquet(col_select =) silently returns the wrong columns when the file has nested (list) columns #55578

Open

Description

@stufield

read_parquet(col_select = ...) returns incorrect columns, with no error or warning, that
come after a nested column with more than one leaf (e.g. list<struct<...>>). Appears to be an
indexing error introduced by the nested list column.

reprex

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

Activity

  1. changed the title [-]`read_parquet(col_select =)` silently returns the wrong columns when the file has nested (list) columns[/-] [+][R] `read_parquet(col_select =)` silently returns the wrong columns when the file has nested (list) columns[/+] on Nov 12, 2026
  2. thisisnic commented on Nov 12, 2026

    @thisisnic
    Member

    Thanks for the clear reproducible example, can confirm this is an Arrow bug that we should fix.

  3. self-assigned this
    on Nov 12, 2026
  4. stufield commented on Nov 12, 2026

    @stufield
    Author

    FWIW, I've been using this workaround locally:

    cols <- c("a", "b", "c")
    read_parquet(...) |>
          dplyr::select(dplyr::all_of(cols)) |>
          dplyr::collect()

    Tho, admittedly this is just a workaround ... sorry it took me a while to post an issue about it 🙏🏽

  5. stufield commented on Nov 12, 2026

    @stufield
    Author

    Thanks for taking a look so quickly 👍🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions