Skip to content

Commit a4eb975

Browse files
committed
[R] Add test coverage for joins with duplicate columns and type casting
1 parent de6eb89 commit a4eb975

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

r/tests/testthat/test-dplyr-join.R

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,41 @@ test_that("Error handling for unsupported expressions in join_by", {
188188
)
189189
})
190190

191-
# TODO: test duplicate col names
192-
# TODO: casting: int and float columns?
191+
test_that("joins with duplicate column names", {
192+
# When column names are duplicated (not in by), suffixes are added
193+
left_dup <- tibble::tibble(
194+
x = 1:5,
195+
y = 1:5,
196+
z = letters[1:5]
197+
)
198+
right_dup <- tibble::tibble(
199+
x = 1:5,
200+
y = 6:10,
201+
z = LETTERS[1:5]
202+
)
203+
204+
compare_dplyr_binding(
205+
.input |>
206+
left_join(right_dup, by = "x") |>
207+
collect(),
208+
left_dup
209+
)
210+
211+
compare_dplyr_binding(
212+
.input |>
213+
inner_join(right_dup, by = "x") |>
214+
collect(),
215+
left_dup
216+
)
217+
218+
# Test with custom suffixes
219+
compare_dplyr_binding(
220+
.input |>
221+
left_join(right_dup, by = "x", suffix = c("_left", "_right")) |>
222+
collect(),
223+
left_dup
224+
)
225+
})
193226

194227
test_that("right_join", {
195228
compare_dplyr_binding(

0 commit comments

Comments
 (0)