apache / apache/arrow

[R] Problem using `month()` binding on augmented column

Open
#39,548 0 comments 0 reactions 0 assignees View on GitHub
Component: R Priority: Critical Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

### Describe the bug, including details regarding any error messages, version, and platform.

``` r
library(stringr)
library(arrow)
library(dplyr)

tf <- tempfile()
dir.create(tf)
data <- tibble::tibble(x = 1)

write_parquet(data, file.path(tf, "2023_01_01.parquet"))
write_parquet(data, file.path(tf, "2023_02_02.parquet"))
write_parquet(data, file.path(tf, "2023_03_03.parquet"))

# works
start_of_query <- open_dataset(tf) |>
mutate(file = add_filename()) |>
mutate(file_date = str_remove(file, ".*/")) |>
mutate(file_date = str_remove(file_date, ".parquet")) |>
mutate(file_date = ymd(file_date)) |>
mutate(year = year(file_date))

# works
start_of_query |>
collect()
#> # A tibble: 3 × 4
#> x file file_date year
#>
#> 1 1 /tmp/Rtmpsy0nYY/file2fa7d1c483f2a/2023_03_03.parquet 2023-03-03 2023
#> 2 1 /tmp/Rtmpsy0nYY/file2fa7d1c483f2a/2023_01_01.parquet 2023-01-01 2023
#> 3 1 /tmp/Rtmpsy0nYY/file2fa7d1c483f2a/2023_02_02.parquet 2023-02-02 2023

# doesn't work
start_of_query |>
mutate(month = month(file_date)) |>
collect()
#> Error: Expression month(file_date) not supported in Arrow
#> Call collect() first to pull data into R.
```

The error comes from this bit of code at the top of the binding for `month()`:

```
call_binding("is.integer", x)
```

which results in this error:

```
Error: Invalid: No match for FieldRef.Name(__filename) in x: double
```

This is most likely pretty much the same as #33464

### Component(s)

R

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.