sql-server - pyspark : spark-submit is not able to perform the desired job

标签 sql-server apache-spark hive pyspark

我是 PySpark 新手。我正在使用以下 spark-submit 进程在集群中的 Hive 中加载表。

/usr/hdp/2.5.0.0-1245/spark2/bin/spark-submit --driver-class-path /path/to/driver/sqljdbc4-3.0.jar --jars /path/to/driver/sqljdbc4-3.0.jar --deploy-mode cluster --master yarn /home/meter/myfile.py

每当我运行这个时,我都会遇到无数的错误。喜欢

1. pyspark.sql.utils.analysisexception u'path file:/root/spark-warehouse/table_name already exist
2. Couldn't find driver for com.microsoft.sqljdbc # something like this
3. Some other staging related errors

底线:我无法使用上述 spark-submit 代码创建 Hive 表。我的Python脚本如下

from pyspark import SparkConf,SparkContext
from pyspark.sql import HiveContext,SQLContext
conf = SparkConf().setAppName("myapp")
sc = SparkContext(conf=conf)
sql_cntx = SQLContext(sc)
df_curr_volt = sql_cntx.read.format("jdbc").options(url="url",dbtable="table").load()
hc = HiveContext(sc)
df_cv_filt.write.format("orc").saveAsTable("df_cv_raw")

根据stackoverflow搜索,看来我需要修改上面的conf定义。或者我必须在 spark-submit 中添加 Hive 元存储 hive-site.xml

或者可能我错过了一些我不知道的东西。

我的问题是:我应该使用的正确 spark-submit 代码是什么?或者我需要在上面的 python 代码中修改什么,然后运行 ​​spark-submit 吗?或者我应该使用spark2-submit? P.S:我使用的是 PySpark 2.0。

更新

我现在终于把错误归零了。这是在阅读了其他一些 stackoverflow 帖子后进行的一些尝试。 事实上,我已将 spark-submit 更改为以下内容。

/usr/hdp...bin/spark-submit --driver-class /path/to/sqljdbc4-3.0.jar --jars /path /to/ sqljdbc4-3.0.jar --master yarn /path/to/.py 

发布此内容后,我收到如下错误。

staging error.could not find registered driver com.microsoft.sqlserver.jdbc.SQLServerDriver #similar to this line.

有趣的是,当使用 scala 时,相同的方法可以正常工作。 请让我知道现在如何解决这个问题。

最佳答案

df_cv_filt.write.format("orc").saveAsTable("df_cv_raw").

saveAsTable:这将创建一个表,并且由于该表已经存在,因此除非您使用覆盖,否则它不会允许

df_cv_filt.write.mode('overwrite').format("orc").saveAsTable("df_cv_raw")

或者您已对数据使用 insertInto

data.write.mode("append").insertInto("my_table").

此外,请确保您具有对 jar 文件及其与 sql-server 对应的正确版本的读取权限。

关于sql-server - pyspark : spark-submit is not able to perform the desired job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55409624/

相关文章:

c# - 在 C# 中调用标量函数

sql-server - 为什么 varchar 比 nvarchar 慢

scala - 按列 "grp"分组并压缩 DataFrame -(按列 "ord"对每列排序取最后一个非空值)

scala - Greenplum Spark 连接器 org.postgresql.util.PSQLException : ERROR: error when writing data to gpfdist

python - 创建按日期范围分区的暂存表

hadoop - 使用 Hadoop 将数据加载到 Hive 表中

sql - 按先前组减去先前值 - SQL Server

sql-server - Oracle 的 SQLServer 发布

apache-spark - Spark命令中的--driver-class-path有什么用?

sql - 如何避免Hive中的交叉连接?