使用Spark连接到Greenplum读取数据时将使用的jar和驱动程序类是什么?

时间:2019-01-07 16:10:17

标签: apache-spark greenplum

我正在尝试使用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"
)

我正在通过spark-submit传递greenplum连接器,如下所示:

  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-submit命令:

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 是一个集合,其中包含以逗号分隔的列和数据类型的数据。

当我运行该作业时,它根本不会进行,而是以“无此类元素异常”结束。

我引用了link中的代码,官方的greenplum文档给出了here。 这是连接器(greenplum-spark_2.11-1.3.0.jar)问题还是驱动程序问题?谁能告诉我使用的罐子是正确的吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用最新的Spark连接器v.1.6.0?

第二,您可以尝试使用不带“ partitions”的代码,因为partitions参数是可选的吗?

此外,如果您可以提供完整的堆栈跟踪,则将更容易调试此问题。

链接:https://greenplum-spark.docs.pivotal.io/160/index.html