Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix lambda variable name issues in nested DataFrame functions in R APIs
  • Loading branch information
HyukjinKwon committed May 12, 2021
commit 03274568eef0a42d2e70bcec895d9a01ed111ecf
7 changes: 6 additions & 1 deletion R/pkg/R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3670,7 +3670,12 @@ unresolved_named_lambda_var <- function(...) {
"org.apache.spark.sql.Column",
newJObject(
"org.apache.spark.sql.catalyst.expressions.UnresolvedNamedLambdaVariable",
list(...)
lapply(list(...), function(x) {
handledCallJStatic(
"org.apache.spark.sql.catalyst.expressions.UnresolvedNamedLambdaVariable",
"freshVarName",
x)
})
)
)
column(jc)
Expand Down
14 changes: 14 additions & 0 deletions R/pkg/tests/fulltests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,20 @@ test_that("higher order functions", {
expect_error(array_transform("xs", function(...) 42))
})

test("SPARK-34794: lambda variables must be resolved properly in nested higher order functions") {
df <- sql("SELECT array(1, 2, 3) as numbers, array('a', 'b', 'c') as letters")
ret <- first(select(
df,
array_transform("numbers", function(number) {
array_transform("letters", function(latter) {
struct(alias(number, "n"), alias(latter, "l"))
})
})
))

expect_equal(1, ret[[1]][[1]][[1]][[1]]$n)
}

test_that("group by, agg functions", {
df <- read.json(jsonPath)
df1 <- agg(df, name = "max", age = "sum")
Expand Down