【问题标题】:Saving dataframe in scala intellij throws exception在 scala intellij 中保存数据框会引发异常
【发布时间】:2018-01-07 01:52:51
【问题描述】:

我正在尝试使用 Intellij Spark Scala 将 CSV 或 XML 文件加载到预先存在的配置单元表中,然后在保存数据帧的最后一步给出以下异常。

具有讽刺意味的是:下面的代码在 spark-shell 中运行良好,在所有四种情况下都没有任何问题。

1。当我使用 Hive Context 和 Insertinto() 时。

val sparkConf = new SparkConf().setAppName("TEST")
val sc = new SparkContext(sparkConf)
val hiveContext = new HiveContext(sc)
hiveContext.setConf("hive.exec.dynamic.partition", "true")
hiveContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
println("CONFIG DONE!!!!!")
val xml = hiveContext.read.format("com.databricks.spark.xml").option("rowTag","employee").load("/PUBLIC_TABLESPACE/updatedtest1.xml")
println("XML LOADED!!!!!!")
xml.write.format("parquet").mode("overwrite").partitionBy("designation").insertInto("test2")
println("TABLE SAVED!!!!!!!")

线程“主”java.lang.NoSuchMethodException 中的异常:org.apache.hadoop.hive.ql.metadata.Hive.loadDynamicPartitions(org.apache.hadoop.fs.Path, java.lang.String, java.util .Map, boolean, int, boolean, boolean, boolean)

2.当我使用 Hive Context 和 SaveAsTable() 时。

val sparkConf = new SparkConf().setAppName("TEST")
val sc = new SparkContext(sparkConf)
val hiveContext = new HiveContext(sc)
hiveContext.setConf("hive.exec.dynamic.partition", "true")
hiveContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
println("CONFIG DONE!!!!!")
val xml = hiveContext.read.format("com.databricks.spark.xml").option("rowTag","employee").load("/PUBLIC_TABLESPACE/updatedtest1.xml")
println("XML LOADED!!!!!!")

xml.write.format("parquet")
  .mode("overwrite")
  .partitionBy("designation")
  .saveAsTable("test2")

线程“主”java.lang.NoSuchMethodException 中的异常:org.apache.hadoop.hive.ql.metadata.Hive.loadDynamicPartitions(org.apache.hadoop.fs.Path, java.lang.String, java.util .Map, boolean, int, boolean, boolean, boolean)

3。当我使用 SQL Context 和 Insertinto() 时。

val sparkConf = new SparkConf().setAppName("TEST")
val sc = new SparkContext(sparkConf)
val hiveContext = new SQLContext(sc)
hiveContext.setConf("hive.exec.dynamic.partition", "true")
hiveContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
println("CONFIG DONE!!!!!")
val xml = hiveContext.read.format("com.databricks.spark.xml").option("rowTag","employee").load("/PUBLIC_TABLESPACE/updatedtest1.xml")
println("XML LOADED!!!!!!") xml.write.format("parquet").mode("overwrite").partitionBy("designation").insertInto("test2")
println("TABLE SAVED!!!!!!!")

线程“主”org.apache.spark.sql.AnalysisException 中的异常:找不到表:test2;

4。当我使用 SQL 上下文和 saveAsTable() 时。

val sparkConf = new SparkConf().setAppName("TEST")
val sc = new SparkContext(sparkConf)
val hiveContext = new SQLContext(sc)
hiveContext.setConf("hive.exec.dynamic.partition", "true")
hiveContext.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
println("CONFIG DONE!!!!!") 
val xml = hiveContext.read.format("com.databricks.spark.xml").option("rowTag","employee").load("/PUBLIC_TABLESPACE/updatedtest1.xml")
println("XML LOADED!!!!!!") xml.write.format("parquet").mode("overwrite").partitionBy("designation").saveAsTable("test2")
println("TABLE SAVED!!!!!!!")

线程“main”java.lang.RuntimeException 中的异常:使用 SQLContext 创建的表必须是 TEMPORARY。请改用 HiveContext。

使用 BUILD.SBT 文件编辑:

BUILD.SBT File: name := "testonSpark"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.6.0"
libraryDependencies += "com.databricks" % "spark-csv_2.10" % "1.5.0"
libraryDependencies += "org.apache.spark" % "spark-hive_2.10" % "1.6.0"

【问题讨论】:

  • 您能否在加载后立即检查是否能够打印 xml 的第一行或行数?
  • 员工:[技术主管,1,Satish Kumar] 员工:[测试,2,Ramya]
  • 这是我加载后打印数据时得到的输出。
  • 你是在向 spark-submit 提交 jar 文件吗?
  • 是的。这就是我在 Intellij 中编写代码的原因

标签: scala hadoop apache-spark intellij-idea


【解决方案1】:

尝试使用 sbt 文件作为

val sparkVersion = "1.6.0"
resolvers ++= Seq(
  "apache-snapshots" at "http://repository.apache.org/snapshots/"
)
libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % sparkVersion,
  "org.apache.spark" %% "spark-sql" % sparkVersion,
  "org.apache.spark" %% "spark-hive" % sparkVersion,
  "org.apache.spark" %% "spark-mllib" % sparkVersion
)
libraryDependencies += "com.databricks" % "spark-csv_2.10" % "1.5.0"

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多