2016-03-03 170 views
8

在我的应用程序中,我需要连接到数据库,因此我需要在提交应用程序时传递IP地址和数据库名称。如何通过Spark提交外部参数提交

我递交了申请,如下所示:

./spark-submit --class class name --master spark://localhost:7077 \ 
--deploy-mode client /home/hadoop/myjar.jar 

回答

11

如果检查the official documentation你会看到​​有以下语法:

./bin/spark-submit \ 
    --class <main-class> 
    --master <master-url> \ 
    --deploy-mode <deploy-mode> \ 
    --conf <key>=<value> \ 
    ... # other options 
    <application-jar> \ 
    [application-arguments] 

您可以使用application-argumentsconf传递所需配置主要方法和SparkConf分别。

1

如前所述通过zero323可以使用从the link

./bin/spark-submit \ 
    --class <main-class> 
    --master <master-url> \ 
    --deploy-mode <deploy-mode> \ 
    --conf <key>=<value> \ 
    ... # other options 
    <application-jar> \ 
    [application-arguments] 

这里火花提交命令,的conf用来传递其所需的像任何运行应用程序的星火相关CONFIGS (执行程序内存),或者如果您要覆盖在Spark-default.conf中设置的默认属性。

至于你的使用情况而言,你想通过IP的应用程序连接到数据库,然后你可以使用[应用参数]它们的JAR后通过。

当您设置主要为:

def main(args: Array[String]) 

然后你就可以接受任何作为的.jar行后给出的参数。

请参考for more details