Spark 1.6:java.lang.IllegalArgumentException:spark.sql.execution.id已设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spark 1.6:java.lang.IllegalArgumentException:spark.sql.execution.id已设置相关的知识,希望对你有一定的参考价值。
当我运行以下代码时,我正在使用spark 1.6并遇到上述问题:
// Imports
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SaveMode
import scala.concurrent.ExecutionContext.Implicits.global
import java.util.Properties
import scala.concurrent.Future
// Set up spark on local with 2 threads
val conf = new SparkConf().setMaster("local[2]").setAppName("app")
val sc = new SparkContext(conf)
val sqlCtx = new HiveContext(sc)
// Create fake dataframe
import sqlCtx.implicits._
var df = sc.parallelize(1 to 50000).map { i => (i, i, i, i, i, i, i) }.toDF("a", "b", "c", "d", "e", "f", "g").repartition(2)
// Write it as a parquet file
df.write.parquet("/tmp/parquet1")
df = sqlCtx.read.parquet("/tmp/parquet1")
// JDBC connection
val url = s"jdbc:postgresql://localhost:5432/tempdb"
val prop = new Properties()
prop.setProperty("user", "admin")
prop.setProperty("password", "")
// 4 futures - at least one of them has been consistently failing for
val x1 = Future { df.write.jdbc(url, "temp1", prop) }
val x2 = Future { df.write.jdbc(url, "temp2", prop) }
val x3 = Future { df.write.jdbc(url, "temp3", prop) }
val x4 = Future { df.write.jdbc(url, "temp4", prop) }
这是github要点:https://gist.github.com/karanveerm/27d852bf311e39f05491
我得到的错误是:at
org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:87) ~[org.apache.spark.spark-sql_2.11-1.6.0.jar:1.6.0]
at org.apache.spark.sql.DataFrame.withNewExecutionId(DataFrame.scala:2125) ~[org.apache.spark.spark-sql_2.11-1.6.0.jar:1.6.0]
at org.apache.spark.sql.DataFrame.foreachPartition(DataFrame.scala:1482) ~[org.apache.spark.spark-sql_2.11-1.6.0.jar:1.6.0]
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.saveTable(JdbcUtils.scala:247) ~[org.apache.spark.spark-sql_2.11-1.6.0.jar:1.6.0]
at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:306) ~[org.apache.spark.spark-sql_2.11-1.6.0.jar:1.6.0]
at writer.SQLWriter$.writeDf(Writer.scala:75) ~[temple.temple-1.0-sans-externalized.jar:na]
at writer.Writer$.writeDf(Writer.scala:33) ~[temple.temple-1.0-sans-externalized.jar:na]
at controllers.Api$$anonfun$downloadTable$1$$anonfun$apply$25.apply(Api.scala:460) ~[temple.temple-1.0-sans-externalized.jar:2.4.6]
at controllers.Api$$anonfun$downloadTable$1$$anonfun$apply$25.apply(Api.scala:452) ~[temple.temple-1.0-sans-externalized.jar:2.4.6]
at scala.util.Success$$anonfun$map$1.apply(Try.scala:237) ~[org.scala-lang.scala-library-2.11.7.jar:na]
这是一个火花虫还是我做错了什么/任何变通办法?
在尝试了几件事后,我发现全局ForkJoinPool
创建的一个线程将其spark.sql.execution.id
属性设置为随机值。我无法确定真正做到这一点的过程,但我可以通过使用我自己的ExecutionContext
来解决它。
import java.util.concurrent.Executors
import concurrent.ExecutionContext
val executorService = Executors.newFixedThreadPool(4)
implicit val ec = ExecutionContext.fromExecutorService(executorService)
我使用了http://danielwestheide.com/blog/2013/01/16/the-neophytes-guide-to-scala-part-9-promises-and-futures-in-practice.html的代码。也许ForkJoinPool
在创建新的线程时克隆线程属性,如果在SQL执行的上下文中发生这种情况,它将获得非null值,而FixedThreadPool
将在实例化时创建线程。
请检查SPARK-13747
如果适用于您的环境,请考虑使用Spark 2.2.0或更高版本。
测试1:如果以串行方式而不是并行方式运行每个df.write操作,它会有帮助吗?
测试2:如果你持久保存数据帧然后并行执行所有df.write操作并在完成所有操作后seralize to unpersist以查看是否有帮助,它会有帮助吗?
以上是关于Spark 1.6:java.lang.IllegalArgumentException:spark.sql.execution.id已设置的主要内容,如果未能解决你的问题,请参考以下文章
Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected imp(示例
Spark(1.6) Densevector.type 不带参数