Repository: spark Updated Branches: refs/heads/master 76399d75e -> 95b177c8f
[SPARK-23648][R][SQL] Adds more types for hint in SparkR ## What changes were proposed in this pull request? Addition of numeric and list hints for SparkR. ## How was this patch tested? Add test in test_sparkSQL.R Author: Huaxin Gao <huax...@us.ibm.com> Closes #21649 from huaxingao/spark-23648. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/95b177c8 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/95b177c8 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/95b177c8 Branch: refs/heads/master Commit: 95b177c8f0862c6965a7c3cd76b3935c975adee9 Parents: 76399d7 Author: Huaxin Gao <huax...@us.ibm.com> Authored: Wed Sep 19 21:27:30 2018 -0700 Committer: Felix Cheung <felixche...@apache.org> Committed: Wed Sep 19 21:27:30 2018 -0700 ---------------------------------------------------------------------- R/pkg/R/DataFrame.R | 12 +++++++++++- R/pkg/tests/fulltests/test_sparkSQL.R | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/95b177c8/R/pkg/R/DataFrame.R ---------------------------------------------------------------------- diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index 458deca..a1cb478 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -3985,7 +3985,17 @@ setMethod("hint", signature(x = "SparkDataFrame", name = "character"), function(x, name, ...) { parameters <- list(...) - stopifnot(all(sapply(parameters, is.character))) + if (!all(sapply(parameters, function(y) { + if (is.character(y) || is.numeric(y)) { + TRUE + } else if (is.list(y)) { + all(sapply(y, function(z) { is.character(z) || is.numeric(z) })) + } else { + FALSE + } + }))) { + stop("sql hint should be character, numeric, or list with character or numeric.") + } jdf <- callJMethod(x@sdf, "hint", name, parameters) dataFrame(jdf) }) http://git-wip-us.apache.org/repos/asf/spark/blob/95b177c8/R/pkg/tests/fulltests/test_sparkSQL.R ---------------------------------------------------------------------- diff --git a/R/pkg/tests/fulltests/test_sparkSQL.R b/R/pkg/tests/fulltests/test_sparkSQL.R index 0c4bdb3..40d8f80 100644 --- a/R/pkg/tests/fulltests/test_sparkSQL.R +++ b/R/pkg/tests/fulltests/test_sparkSQL.R @@ -2419,6 +2419,15 @@ test_that("join(), crossJoin() and merge() on a DataFrame", { expect_true(any(grepl("BroadcastHashJoin", execution_plan_broadcast))) }) +test_that("test hint", { + df <- sql("SELECT * FROM range(10e10)") + hintList <- list("hint2", "hint3", "hint4") + execution_plan_hint <- capture.output( + explain(hint(df, "hint1", 1.23456, "aaaaaaaaaa", hintList), TRUE) + ) + expect_true(any(grepl("1.23456, aaaaaaaaaa", execution_plan_hint))) +}) + test_that("toJSON() on DataFrame", { df <- as.DataFrame(cars) df_json <- toJSON(df) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org