You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[R] right_join() function does not produce the expected outcome #14907
Describe the bug, including details regarding any error messages, version, and platform.
Hi,
I noticed something strange today when I was using arrow datasets. I cannot give a reproducible example but you can get the idea from the code below. I have ccaei as an arrow dataset. When I try to use right_join() with an R tibble before using collect(), it gives me wrong numbers (the number of distinct ENROLID is less than that present in outpatients). I get the correct number when I use right_join() after using collect(), although this is computationally inefficient. Could you help me with this?
Thanks for responding. I am using the latest version of Arrow 10.0.1
In the example I posted, ccaei is a dataset I built using multiple parquet files. I will attach an example, but it does not show exactly the problem I faced.
library(tidyverse)
library(arrow)
#> #> Attaching package: 'arrow'#> The following object is masked from 'package:utils':#> #> timestamp
library(duckdb)
#> Loading required package: DBIdata1<- tibble(
id=1:100,
x= rnorm(100)
)
data2<- tibble(
id=52:69,
z= rbinom(18, size=18, prob=0.5)
)
data2_arrow<-data2|> as_arrow_table()
# The weired right_join outputdata2_arrow|>
right_join(data1) |> collect() |># The ids from data 1 are missing
tail(10)
#> # A tibble: 10 × 3#> id z x#> <int> <int> <dbl>#> 1 NA NA -0.369#> 2 NA NA 0.470#> 3 NA NA -0.372#> 4 NA NA 0.505#> 5 NA NA 1.47 #> 6 NA NA -0.858#> 7 NA NA -0.330#> 8 NA NA 2.02 #> 9 NA NA 1.53 #> 10 NA NA -0.399# The expected right_join output data2|>
right_join(data1) |>
tail(10)
#> Joining, by = "id"#> # A tibble: 10 × 3#> id z x#> <int> <int> <dbl>#> 1 91 NA -0.369#> 2 92 NA 0.470#> 3 93 NA -0.372#> 4 94 NA 0.505#> 5 95 NA 1.47 #> 6 96 NA -0.858#> 7 97 NA -0.330#> 8 98 NA 2.02 #> 9 99 NA 1.53 #> 10 100 NA -0.399
Thanks for the reprex there, this looks similar to an issue we had back in ARROW-15838 though there has been work done to fix it - I'm suspecting we might need to do something extra to make this work for right_join().
I'll take a look into what's going on in the example in the reprex, which hopefully should also fix the original problem you had, though it's not guaranteed - if you do find a reprex that captures that, feel free to add that here.
I can confirm that I can reproduce the error from the reprex in the latest dev version of Arrow.
I was wondering if this has been resolved as I'm still coming up against behaviour that differs from dplyr behaviour in both left_join() and right_join() (see reprex below) in arrow version 12.0.1.1.
What appears to me to be the difference is that while dplyr matches NA values by default, arrow does not seem to.
Am I missing sth?
library(dplyr)
#> #> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#> #> filter, lag#> The following objects are masked from 'package:base':#> #> intersect, setdiff, setequal, union
library(arrow)
#> #> Attaching package: 'arrow'#> The following object is masked from 'package:utils':#> #> timestamptbl1<-tibble::tibble(
a=1:3,
b= c("a", "b", NA),
d= c(letters[4:6])
)
tbl2<-tibble::tibble(
b= c("b", NA),
c= c("a should be 2", "a should be 3")
)
# Left join tibbles, NAs matched
left_join(tbl2, tbl1)
#> Joining with `by = join_by(b)`#> # A tibble: 2 × 4#> b c a d #> <chr> <chr> <int> <chr>#> 1 b a should be 2 2 e #> 2 <NA> a should be 3 3 f# Left join arrow table & tibble, NAs NOT matched
left_join(as_arrow_table(tbl2), tbl1) %>% collect()
#> # A tibble: 2 × 4#> b c a d #> <chr> <chr> <int> <chr>#> 1 b a should be 2 2 e #> 2 <NA> a should be 3 NA <NA># Left join arrow table & arrow table, NAs NOT matched
left_join(as_arrow_table(tbl2), as_arrow_table(tbl1)) %>% collect()
#> # A tibble: 2 × 4#> b c a d #> <chr> <chr> <int> <chr>#> 1 b a should be 2 2 e #> 2 <NA> a should be 3 NA <NA># Same with right_join. It appears that the NAs are the problem as arrow doesn't seem to count them as a match
right_join(tbl1, tbl2)
#> Joining with `by = join_by(b)`#> # A tibble: 2 × 4#> a b d c #> <int> <chr> <chr> <chr> #> 1 2 b e a should be 2#> 2 3 <NA> f a should be 3
right_join(as_arrow_table(tbl1), as_arrow_table(tbl2)) %>% collect()
#> # A tibble: 2 × 4#> a b d c #> <int> <chr> <chr> <chr> #> 1 2 b e a should be 2#> 2 NA <NA> <NA> a should be 3
right_join(as_arrow_table(tbl1), tbl2) %>% collect()
#> # A tibble: 2 × 4#> a b d c #> <int> <chr> <chr> <chr> #> 1 NA <NA> <NA> a should be 3#> 2 2 b e a should be 2
Hi @annakrystalli, the problem described in the original issue has been fixed, but the problem you are describing in your reprex there is something else. I've opened up #37902 as a feature request, and have added some more explanation there - happy to discuss further on that ticket
Activity
thisisnic commentedon Dec 11, 2022
Hi @abduazizR , thanks for reporting this! Just to check, which version of Arrow are you using?
I understand that your data may be confidential, but is it possible to create a reproducible example using in-built datasets instead?
abduazizR commentedon Dec 11, 2022
Hi Nic,
Thanks for responding. I am using the latest version of Arrow 10.0.1
In the example I posted,
ccaeiis a dataset I built using multiple parquet files. I will attach an example, but it does not show exactly the problem I faced.Created on 2022-12-11 with reprex v2.0.2
With my data,
right_joinis acting asinner_join. As a result, I don't even have rows withNAs in the ID column.Thank you.
thisisnic commentedon Dec 12, 2022
Thanks for the reprex there, this looks similar to an issue we had back in ARROW-15838 though there has been work done to fix it - I'm suspecting we might need to do something extra to make this work for
right_join().I'll take a look into what's going on in the example in the reprex, which hopefully should also fix the original problem you had, though it's not guaranteed - if you do find a reprex that captures that, feel free to add that here.
I can confirm that I can reproduce the error from the reprex in the latest dev version of Arrow.
abduazizR commentedon Dec 12, 2022
Thanks for the response. Can I rely on
left_join()for now until the issue withright_join()gets resolved?thisisnic commentedon Dec 13, 2022
@abduazizR It looks like that issue is restricted to
right_join()only - see the reprex below:GH-14907: [R] right_join() function does not produce the expected out…
apacheGH-14907: [R] right_join() function does not produce the expect…
annakrystalli commentedon Sep 26, 2023
Hello!
I was wondering if this has been resolved as I'm still coming up against behaviour that differs from
dplyrbehaviour in bothleft_join()andright_join()(see reprex below) inarrowversion 12.0.1.1.What appears to me to be the difference is that while
dplyrmatchesNAvalues by default,arrowdoes not seem to.Am I missing sth?
Created on 2023-09-26 with reprex v2.0.2
Session info
Temp remove use of arrow tables until NAs match (as they do in dplyr)…
thisisnic commentedon Sep 27, 2023
Hi @annakrystalli, the problem described in the original issue has been fixed, but the problem you are describing in your reprex there is something else. I've opened up #37902 as a feature request, and have added some more explanation there - happy to discuss further on that ticket
annakrystalli commentedon Sep 27, 2023
Great! Thank you.