hdp沙盒ioexception调用dataframe上的saveastable

eagi6jfj  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(268)

我尝试运行下面的示例,该示例尝试从sparkDataframe创建一个配置单元表。当我用master=local调用spark submit时,代码可以工作,但当我用master=yarn调用它时,它会抛出一个异常。下面是调用:spark submit--class test.sandbox.hdpriskfactor--master yarn--name“risk factor”。/hdprisk-0.0.1-snapshot.jar此外,我从配置单元控制台创建了一个名为“default.geolocation”的表,但在调用show()时,我无法从spark看到它。我试图将Yarn模式中的执行器计数设置为0,但这也不起作用。1) 为什么代码与master local一起工作,而与yarn一起工作2)为什么我看不到从spark代码在hive中创建的表。

def main(args: Array[String]): Unit = {

val spark = SparkSession.builder().getOrCreate()
//    val spark = SparkSession.builder().master("local[*]").getOrCreate()
val sc = spark.sparkContext
val hadoopconf = new Configuration()
val hdfs = FileSystem.get(hadoopconf)
val csvDataDir = "/tmp/data"
//import spark.implicits._
val dataList = List(("geolocation", "csv"), ("trucks", "csv"))
listFiles(this.getClass.getClassLoader.getResource(".").getFile)
dataList.map(path => {
  val localFile = path._1 + "." + path._2
  val hdfsFile = csvDataDir + "/" + path._1 + "." + path._2
  if (!testDirExist(hdfs, hdfsFile)) copyStreamToHdfs(hdfs, "/root/", csvDataDir, localFile)
})
val geoLocationDF = spark.read.format("csv").option("header", "true").load("hdfs:///tmp/data/geolocation.csv")

// Now that we have the data loaded into a DataFrame, we can register a temporary view.
spark.sql("SHOW TABLES").show()
geoLocationDF.write.format("orc").saveAsTable("default.geolocation")
//      geoLocationDF.createOrReplaceTempView("geolocation")

spark.sql("select * from default.geolocation").show()

}

oknwwptz

oknwwptz1#

我没有正确配置配置配置单元上下文。所以它正在将文件写入根目录。解决方案是传递正确的配置参数:

val spark = SparkSession.builder()
  .config("spark.sql.warehouse.dir", "/user/hive/warehouse")
  .config("spark.sql.sources.maxConcurrentWrites","1")
  .config("spark.sql.parquet.compression.codec", "snappy")
  .config("hive.exec.dynamic.partition", "true")
  .config("hive.exec.dynamic.partition.mode", "nonstrict")
  .config("parquet.compression", "SNAPPY")
  .config("hive.exec.max.dynamic.partitions", "3000")
  .config("parquet.enable.dictionary", "false")
  .config("hive.support.concurrency", "true")
  .enableHiveSupport()
  .getOrCreate()

相关问题