gpt4 book ai didi

scala - 无法使用 spark-sftp api 将数据帧写入目标 sftp 服务器

转载 作者:行者123 更新时间:2023-12-05 07:19:27 25 4
gpt4 key购买 nike

我正在尝试执行 sftp 并将数据帧从 spark-cluster 写入目标 sftp 服务器。

该代码在 spark-shell 上运行良好,但是当我尝试使用 scala 代码部署我的 jar 时,它失败并出现以下错误:

*Caused by: org.apache.hadoop.security.AccessControlException: Permission denied: user=abcuser, access=WRITE, inode="/":hdfs:supergroup:drwxr-xr-x*

我尝试在 spark-shell 中使用以下内容及其工作:

    spark2-shell --queue xyz --packages com.springml:spark-sftp_2.11:1.1.3

val df = sparksession.sql(s"select * from db.table")

df.write.format("com.springml.spark.sftp").option("host", "hostname").option("username", "username").option("password", "abc").option("port","22").option("fileType", "csv").option("delimiter", "|").option("header","true").save("/Download/file.txt")

但在我的 scala 代码中失败了。下面是我的程序:

    import com.springml.spark.sftp._

val df = sparksession.sql(s"select * from db.table")

df.write.format("com.springml.spark.sftp")
.option("host", "hostname")
.option("username", "username")
.option("password", "abc")
.option("port","22")
.option("fileType", "csv")
.option("delimiter", "|")
.option("header","false")
.save("sftp_directory")

有人可以让我知道错误或我遗漏的东西吗。

下面是我的 spark-submit 命令,我在其中添加了所有必需的 jar。所有 3 个 jar 都是使用选项 --jar 添加的。

 kinit -kt abcuser.keytab -V abcuser
spark2-submit --class com.sample.Program1 \
--master yarn \
--deploy-mode cluster \
--queue queuename \
--files sample.conf \
--executor-memory 25G \
--driver-memory 20G \
--executor-cores 5 \
--conf spark.dynamicAllocation.enabled=true \
--conf spark.dynamicAllocation.minExecutors=100 \
--conf spark.yarn.executor.memoryOverhead=4096 \
--conf spark.yarn.maxAppAttempts=2 \
--conf spark.network.timeout=1500 \
--conf spark.sql.broadcastTimeout=1500 \
--conf spark.kryoserializer.buffer.max=2000 \
--conf spark.driver.maxResultSize=25G \
--conf spark.shuffle.blockTransferService=nio \
--conf spark.yarn.appMasterEnv.HADOOP_USER_NAME=hdfs \
--jars hdfs://devnameservice/user/abcuser/jsch-0.1.53.jar,
hdfs://devnameservice/user/abcuser/sftp.client1.0.3.jar,
hdfs://devnameservice/user/abcuser/spark-sftp_2.11-1.1.0.jar \
--packages com.springml:spark-sftp_2.11:1.1.3 \
project-core.jar sample.conf

最佳答案

以下 spark 文档:

https://spark.apache.org/docs/latest/configuration.html

Note: When running Spark on YARN in cluster mode, environment variables need to be set using the spark.yarn.appMasterEnv.[EnvironmentVariableName] property in your conf/spark-defaults.conf file. Environment variables that are set in spark-env.sh will not be reflected in the YARN Application Master process in cluster mode. See the YARN-related Spark Properties for more information.

因此,要么修改 spark-defaults.conf,要么将其作为 spark-submit 的配置传递。

由于这是一个权限错误,您可以将其添加到您的 spark-submit 配置中:

./bin/spark-submit
--name "我的应用程序"
--master local[4]

--conf spark.yarn.appMasterEnv.HADOOP_USER_NAME=hdfs

myApp.jar

关于scala - 无法使用 spark-sftp api 将数据帧写入目标 sftp 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com