Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark spark提交管道模型_Apache Spark_Docker_Apache Spark Ml_Spark Submit - Fatal编程技术网

Apache spark spark提交管道模型

Apache spark spark提交管道模型,apache-spark,docker,apache-spark-ml,spark-submit,Apache Spark,Docker,Apache Spark Ml,Spark Submit,我在docker上运行了一个Apache Spark群集(1个master+1个worker),我可以使用符合管道的Spark submit提交作业,然后将其保存(PipelineModel.save(path))。文件就在我执行Spark submit命令的位置保存在我的本地机器上 当我想加载PipelineModel并将其用于预测时,当我尝试部署生产代码时,就会出现问题。我无法传递包含已保存文件的文件夹 这是我用来提交作业的代码: spark-submit --class ch.supsi.

我在docker上运行了一个Apache Spark群集(1个master+1个worker),我可以使用符合管道的
Spark submit
提交作业,然后将其保存
(PipelineModel.save(path))。
文件就在我执行
Spark submit
命令的位置保存在我的本地机器上

当我想加载
PipelineModel
并将其用于预测时,当我尝试部署生产代码时,就会出现问题。我无法传递包含已保存文件的文件夹

这是我用来提交作业的代码:

spark-submit --class ch.supsi.isteps.Main --master spark://172.17.0.1:7077 --packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.2.0 --files=test/aFolder ./STR-0.1-alpha.jar --mode=production --file=test/aFolder
其中--mode=production--file=test/aFolder
是我的程序的参数

我已经尝试使用
--文件
,但它不接受文件夹。我希望避免在所有工作节点中复制模型

编辑

这个问题与HDFS和Docker有关。作为备份解决方案,我们避免在Docker内部使用spark cluster,并在Docker内部切换到本地模式。这样可以毫无问题地保存和检索文件。如果映射文件夹(docker compose->volumes),您甚至不需要传递文件,因为它们已经映射到您的容器

我已经尝试使用--files,但它不接受文件夹

备选案文1:
SparkContext
有下面的方法来添加文件,您可以循环并列出文件夹中的文件并添加它们

/**
* Add a file to be downloaded with this Spark job on every node.
*
* If a file is added during execution, it will not be available until the next TaskSet starts.
*
* @param path can be either a local file, a file in HDFS (or other Hadoop-supported
* filesystems), or an HTTP, HTTPS or FTP URI. To access the file in Spark jobs,
* use `SparkFiles.get(fileName)` to find its download location.
*/
def addFile(path: String): Unit = {
addFile(path, false)
}
如上所述
SparkFiles.get(文件名)
您可以获取文件名

或者
SparkFiles
具有
getRootDirectory
以获取已添加文件的文件夹,您可以在其中访问这些文件

/** 
  * Get the root directory that contains files added through `SparkContext.addFile()`. 
 */ 
 def getRootDirectory(): String = 
 SparkEnv.get.driverTmpDir.getOrElse(".") 

 } 
否则

使用
sparkcontext.listFiles
可以按顺序获得文件列表

选项2:如果您想继续使用
--files
选项,那么您可以使用相同的方法按照我的答案进行操作,您也可以从用分隔符分隔的文件夹中添加多个文件。
希望这有帮助

@Marco Cinus:你试过这种方法吗?它有用吗?