Skip to content

Commit

Permalink
Rename R cross_join to join, add documentation (#4548)
Browse files Browse the repository at this point in the history
* Refactor cross-join to join and add doc

* Correct test

* Generate docs
  • Loading branch information
alexpeters1208 authored Sep 27, 2023
1 parent 442966a commit 9e1e93a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
16 changes: 13 additions & 3 deletions R/rdeephaven/R/table_handle_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,19 @@ TableHandle <- R6Class("TableHandle",
return(TableHandle$new(self$.internal_rcpp_object$count_by(col, by)))
},

#' @export
cross_join = function(table, on = character(), joins = character()) {
#' @description
#' Creates a new table containing rows that have matching values in both tables. Rows that do not have matching
#' criteria will not be included in the result. If there are multiple matches between a row from the left table
#' and rows from the right table, all matching combinations will be included. If no columns to match (on) are
#' specified, every combination of left and right table rows is included.
#' @param table TableHandle referencing the table to join with.
#' @param on String or list of strings denoting the names of the columns to join on.
#' @param joins String or list of strings denoting the names of the columns to add from `table`.
#' @return A TableHandle referencing the new table.
join = function(table, on = character(), joins = character()) {
verify_string("on", on, FALSE)
verify_string("joins", joins, FALSE)
return(TableHandle$new(self$.internal_rcpp_object$cross_join(
return(TableHandle$new(self$.internal_rcpp_object$join(
table$.internal_rcpp_object,
on, joins
)))
Expand All @@ -406,6 +414,7 @@ TableHandle <- R6Class("TableHandle",
#' @param table TableHandle referencing the table to join with.
#' @param on String or list of strings denoting the names of the columns to join on.
#' @param joins String or list of strings denoting the names of the columns to add from `table`.
#' @return A TableHandle referencing the new table.
natural_join = function(table, on = character(), joins = character()) {
verify_string("on", on, FALSE)
verify_string("joins", joins, FALSE)
Expand All @@ -422,6 +431,7 @@ TableHandle <- R6Class("TableHandle",
#' @param table TableHandle referencing the table to join with.
#' @param on String or list of strings denoting the names of the columns to join on.
#' @param joins String or list of strings denoting the names of the columns to add from `table`.
#' @return A TableHandle referencing the new table.
exact_join = function(table, on = character(), joins = character()) {
verify_string("on", on, FALSE)
verify_string("joins", joins, FALSE)
Expand Down
4 changes: 2 additions & 2 deletions R/rdeephaven/inst/tests/testthat/test_table_ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,11 @@ test_that("sort behaves as expected", {
data$client$close()
})

test_that("cross_join behaves as expected", {
test_that("join behaves as expected", {
data <- setup()

new_th1 <- data$th5$
cross_join(data$th6,
join(data$th6,
on = character(),
joins = c("X_y = X", "Y_y = Y", "Number1_y = Number1", "Number2_y = Number2")
)
Expand Down
7 changes: 3 additions & 4 deletions R/rdeephaven/man/Client.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 30 additions & 6 deletions R/rdeephaven/man/TableHandle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion R/rdeephaven/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ RCPP_MODULE(DeephavenInternalModule) {
.method("percentile_by", &TableHandleWrapper::PercentileBy)
.method("count_by", &TableHandleWrapper::CountBy)

.method("cross_join", &TableHandleWrapper::CrossJoin)
.method("join", &TableHandleWrapper::CrossJoin)
.method("natural_join", &TableHandleWrapper::NaturalJoin)
.method("exact_join", &TableHandleWrapper::ExactJoin)

Expand Down

0 comments on commit 9e1e93a

Please sign in to comment.