我正在尝试使用Spark连接到Greenplum数据库,以从表中读取数据并将其另存为HDFS上的文件。但是我正在使用的驱动程序或连接器面临障碍。下面是我的build.sbt文件:
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "2.0.0" % "provided",
"org.apache.spark" %% "spark-sql" % "2.0.0" % "provided",
"org.json4s" %% "json4s-jackson" % "3.2.11" % "provided",
"org.apache.httpcomponents" % "httpclient" % "4.5.3"
)
我正在从火花提交传递绿梅连接器,如下所示:
try {
Class.forName("io.pivotal.greenplum.spark.GreenplumRelationProvider").newInstance()
}
catch {
case cnf: ClassNotFoundException =>
println("No class def found.")
System.exit(1)
case e: Exception =>
println("No class def found.")
System.exit(1)
}
val yearDF = spark.read.format("greenplum").option("url", connectionUrl)
.option("dbtable", "gptable")
.option("dbschema","gpschema")
.option("user", username)
.option("password", password)
.option("partitionColumn","id")
.option("partitions",450)
.load()
.where("period=2017 and month=12")
.select(colSeq map col:_*)
println(yearDF.count)
火花提交命令:
SPARK_MAJOR_VERSION=2 spark-submit --class com.partition.source.PartitionData --master=yarn --conf spark.ui.port=4090 --driver-class-path /home/etluser/jars/greenplum-spark_2.11-1.3.0.jar --conf spark.jars=/home/etluser/jars/greenplum-spark_2.11-1.3.0.jar --executor-cores 3 --executor-memory 13G --keytab /home/etluser/etluser.keytab --principal etluser@HDPDEV.COM --files /usr/hdp/current/spark2-client/conf/hive-site.xml,connection.properties --name TEST_YEAR --conf spark.executor.extraClassPath=/home/etluser/jars/greenplum-spark_2.11-1.3.0.jar testYear_2.11-0.1.jar
colSeq是一个集合,其中包含列和数据类型的数据,每个数据用逗号分隔。
当我运行作业时,它根本没有进展,而是以"没有这样的元素异常"结束。
我引用了链接中的代码和官方 greenplum 文档在这里给出。这是连接器(绿梅-spark_2.11-1.3.0.jar)问题还是驱动程序问题?谁能告诉我使用的罐子是否正确?
您是否尝试过使用最新的火花连接器 v.1.6.0?
其次,您可以尝试使用没有"分区"的代码,因为分区参数是可选的?
此外,如果可以提供完整的堆栈跟踪,则调试此问题会更容易。
链接: https://greenplum-spark.docs.pivotal.io/160/index.html
您可以通过以下链接:
https://medium.com/@priya.chauhangfi/connect-to-ibm-db2-data-base-with-pyspark-in-hdfs-shell-environment-c0109926fd
将 IBM 驱动程序替换为 greenplum 驱动程序