[ 
https://issues.apache.org/jira/browse/SPARK-19925?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15906469#comment-15906469
 ] 

Yanbo Liang edited comment on SPARK-19925 at 3/12/17 9:32 AM:
--------------------------------------------------------------

The error was caused by {{spark.getSparkFiles}} calling backend Java code, 
however, it can not connect to backend when it's on executors.
{code}
spark.getSparkFiles <- function(fileName) {
  callJStatic("org.apache.spark.SparkFiles", "get", as.character(fileName))
}
{code}
I think we should have special handling when it was called on executors, 
following the PySpark implementation:
{code}
    def getRootDirectory(cls):
        """
        Get the root directory that contains files added through
        C{SparkContext.addFile()}.
        """
        if cls._is_running_on_worker:
            return cls._root_directory
        else:
            # This will have to change if we support multiple SparkContexts:
            return cls._sc._jvm.org.apache.spark.SparkFiles.getRootDirectory()
{code}


was (Author: yanboliang):
The error was caused by {{spark.getSparkFiles}} calling backend Java code, 
however, it can not connect to backend when it's on executors.
{code}
spark.getSparkFiles <- function(fileName) {
  callJStatic("org.apache.spark.SparkFiles", "get", as.character(fileName))
}
{code}
I think we should have special handling when it was called on executors, 
following the PySpark implementation:
{code}
@classmethod
    def getRootDirectory(cls):
        """
        Get the root directory that contains files added through
        C{SparkContext.addFile()}.
        """
        if cls._is_running_on_worker:
            return cls._root_directory
        else:
            # This will have to change if we support multiple SparkContexts:
            return cls._sc._jvm.org.apache.spark.SparkFiles.getRootDirectory()
{code}

> SparkR spark.getSparkFiles fails on executor
> --------------------------------------------
>
>                 Key: SPARK-19925
>                 URL: https://issues.apache.org/jira/browse/SPARK-19925
>             Project: Spark
>          Issue Type: Bug
>          Components: SparkR
>    Affects Versions: 2.1.0
>            Reporter: Yanbo Liang
>            Priority: Critical
>         Attachments: error-log
>
>
> SparkR function {{spark.getSparkFiles}} fails when it was called on 
> executors. For examples, the following R code will fail. (See error logs in 
> attachment.) 
> {code}
> spark.addFile("./README.md")
> seq <- seq(from = 1, to = 10, length.out = 5)
> train <- function(seq) {
> path <- spark.getSparkFiles("README.md")
> print(path)
> }
> spark.lapply(seq, train)
> {code}
> However, we can run successfully with Scala API:
> {code}
> import org.apache.spark.SparkFiles
> sc.addFile("./README.md”)
> sc.parallelize(Seq(0)).map{ _ => SparkFiles.get("README.md")}.first()
> {code}
> and also successfully with Python API:
> {code}
> from pyspark import SparkFiles
> sc.addFile("./README.md")
> sc.parallelize(range(1)).map(lambda x: SparkFiles.get("README.md")).first()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to