-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-16581][SPARKR] Make JVM backend calling functions public #14775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
472072a
First cut of making JVM functions public
shivaram d772285
Improve documentation for JVM methods
shivaram 5f4b53a
Merge branch 'master' of https://github.com/apache/spark into sparkr-…
shivaram 5f29361
Merge branch 'master' of https://github.com/apache/spark into sparkr-…
shivaram d267f2f
Add unit tests for JVM API
shivaram 0959208
Create wrappers for JVM calls.
shivaram 448de0c
Update bug report URL and date in DESCRIPTION
shivaram d1ec80b
Address code review comments
shivaram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ Package: SparkR | |
| Type: Package | ||
| Title: R Frontend for Apache Spark | ||
| Version: 2.0.0 | ||
| Date: 2016-07-07 | ||
| Date: 2016-08-27 | ||
| Authors@R: c(person("Shivaram", "Venkataraman", role = c("aut", "cre"), | ||
| email = "[email protected]"), | ||
| person("Xiangrui", "Meng", role = "aut", | ||
|
|
@@ -11,7 +11,7 @@ Authors@R: c(person("Shivaram", "Venkataraman", role = c("aut", "cre"), | |
| email = "[email protected]"), | ||
| person(family = "The Apache Software Foundation", role = c("aut", "cph"))) | ||
| URL: http://www.apache.org/ http://spark.apache.org/ | ||
| BugReports: https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12315420&components=12325400&issuetype=4 | ||
| BugReports: https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark#ContributingtoSpark-ContributingBugReports | ||
| Depends: | ||
| R (>= 3.0), | ||
| methods | ||
|
|
@@ -39,6 +39,7 @@ Collate: | |
| 'deserialize.R' | ||
| 'functions.R' | ||
| 'install.R' | ||
| 'jvm.R' | ||
| 'mllib.R' | ||
| 'serialize.R' | ||
| 'sparkR.R' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| # Methods to directly access the JVM running the SparkR backend. | ||
|
|
||
| #' Call Java Methods | ||
| #' | ||
| #' Call a Java method in the JVM running the Spark driver. The return | ||
| #' values are automatically converted to R objects for simple objects. Other | ||
| #' values are returned as "jobj" which are references to objects on JVM. | ||
| #' | ||
| #' @details | ||
| #' This is a low level function to access the JVM directly and should only be used | ||
| #' for advanced use cases. The arguments and return values that are primitive R | ||
| #' types (like integer, numeric, character, lists) are automatically translated to/from | ||
| #' Java types (like Integer, Double, String, Array). A full list can be found in | ||
| #' serialize.R and deserialize.R in the Apache Spark code base. | ||
| #' | ||
| #' @param x object to invoke the method on. Should be a "jobj" created by newJObject. | ||
| #' @param methodName method name to call. | ||
| #' @param ... parameters to pass to the Java method. | ||
| #' @return the return value of the Java method. Either returned as a R object | ||
| #' if it can be deserialized or returned as a "jobj". See details section for more. | ||
| #' @export | ||
| #' @seealso \link{sparkR.callJStatic}, \link{sparkR.newJObject} | ||
| #' @rdname sparkR.callJMethod | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' sparkR.session() # Need to have a Spark JVM running before calling newJObject | ||
| #' # Create a Java ArrayList and populate it | ||
| #' jarray <- sparkR.newJObject("java.util.ArrayList") | ||
| #' sparkR.callJMethod(jarray, "add", 42L) | ||
| #' sparkR.callJMethod(jarray, "get", 0L) # Will print 42 | ||
| #' } | ||
| #' @note sparkR.callJMethod since 2.0.1 | ||
| sparkR.callJMethod <- function(x, methodName, ...) { | ||
| callJMethod(x, methodName, ...) | ||
| } | ||
|
|
||
| #' Call Static Java Methods | ||
| #' | ||
| #' Call a static method in the JVM running the Spark driver. The return | ||
| #' value is automatically converted to R objects for simple objects. Other | ||
| #' values are returned as "jobj" which are references to objects on JVM. | ||
| #' | ||
| #' @details | ||
| #' This is a low level function to access the JVM directly and should only be used | ||
| #' for advanced use cases. The arguments and return values that are primitive R | ||
| #' types (like integer, numeric, character, lists) are automatically translated to/from | ||
| #' Java types (like Integer, Double, String, Array). A full list can be found in | ||
| #' serialize.R and deserialize.R in the Apache Spark code base. | ||
| #' | ||
| #' @param x fully qualified Java class name that contains the static method to invoke. | ||
| #' @param methodName name of static method to invoke. | ||
| #' @param ... parameters to pass to the Java method. | ||
| #' @return the return value of the Java method. Either returned as a R object | ||
| #' if it can be deserialized or returned as a "jobj". See details section for more. | ||
| #' @export | ||
| #' @seealso \link{sparkR.callJMethod}, \link{sparkR.newJObject} | ||
| #' @rdname sparkR.callJStatic | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' sparkR.session() # Need to have a Spark JVM running before calling callJStatic | ||
| #' sparkR.callJStatic("java.lang.System", "currentTimeMillis") | ||
| #' sparkR.callJStatic("java.lang.System", "getProperty", "java.home") | ||
| #' } | ||
| #' @note sparkR.callJStatic since 2.0.1 | ||
| sparkR.callJStatic <- function(x, methodName, ...) { | ||
| callJStatic(x, methodName, ...) | ||
| } | ||
|
|
||
| #' Create Java Objects | ||
| #' | ||
| #' Create a new Java object in the JVM running the Spark driver. The return | ||
| #' value is automatically converted to an R object for simple objects. Other | ||
| #' values are returned as a "jobj" which is a reference to an object on JVM. | ||
| #' | ||
| #' @details | ||
| #' This is a low level function to access the JVM directly and should only be used | ||
| #' for advanced use cases. The arguments and return values that are primitive R | ||
| #' types (like integer, numeric, character, lists) are automatically translated to/from | ||
| #' Java types (like Integer, Double, String, Array). A full list can be found in | ||
| #' serialize.R and deserialize.R in the Apache Spark code base. | ||
| #' | ||
| #' @param x fully qualified Java class name. | ||
| #' @param ... arguments to be passed to the constructor. | ||
| #' @return the object created. Either returned as a R object | ||
| #' if it can be deserialized or returned as a "jobj". See details section for more. | ||
| #' @export | ||
| #' @seealso \link{sparkR.callJMethod}, \link{sparkR.callJStatic} | ||
| #' @rdname sparkR.newJObject | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' sparkR.session() # Need to have a Spark JVM running before calling newJObject | ||
| #' # Create a Java ArrayList and populate it | ||
| #' jarray <- sparkR.newJObject("java.util.ArrayList") | ||
| #' sparkR.callJMethod(jarray, "add", 42L) | ||
| #' sparkR.callJMethod(jarray, "get", 0L) # Will print 42 | ||
| #' } | ||
| #' @note sparkR.newJObject since 2.0.1 | ||
| sparkR.newJObject <- function(x, ...) { | ||
| newJObject(x, ...) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| context("JVM API") | ||
|
|
||
| sparkSession <- sparkR.session(enableHiveSupport = FALSE) | ||
|
|
||
| test_that("Create and call methods on object", { | ||
| jarr <- newJObject("java.util.ArrayList") | ||
| # Add an element to the array | ||
| callJMethod(jarr, "add", 1L) | ||
| # Check if get returns the same element | ||
| expect_equal(callJMethod(jarr, "get", 0L), 1L) | ||
| }) | ||
|
|
||
| test_that("Call static methods", { | ||
| # Convert a boolean to a string | ||
| strTrue <- callJStatic("java.lang.String", "valueOf", TRUE) | ||
| expect_equal(strTrue, "true") | ||
| }) | ||
|
|
||
| test_that("Manually garbage collect objects", { | ||
| jarr <- newJObject("java.util.ArrayList") | ||
| cleanup.jobj(jarr) | ||
| # Using a jobj after GC should throw an error | ||
| expect_error(print(jarr), "Error in invokeJava.*") | ||
| }) | ||
|
|
||
| sparkR.session.stop() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
sparkR.session.stop()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done