1

我想将 ORC 数据从 Spark 数据帧写入外部 Hive 表。当我将数据框另存为表时,数据会发送到现有的外部表,但是,当我尝试将 ORC 格式的数据保存到目录中,然后从外部表中读取此数据时,它不会显示。

第二种情况下数据缺失的原因可能是什么?

这个怎么运作:

val dataDir = "/tmp/avro_data"
sql("CREATE EXTERNAL TABLE avro_random(name string, age int, phone string, city string, country string) STORED AS ORC LOCATION '$dataDir'")

dataframe
  .write
  .mode(SaveMode.Overwrite)
  .saveAsTable("avro_random")

sql("SELECT * FROM avro_random").show()

返回空外部表的代码:

val dataDir = "/tmp/avro_data"
sql("CREATE EXTERNAL TABLE avro_random(name string, age int, phone string, city string, country string) STORED AS ORC LOCATION '$dataDir'")

dataframe
  .write
  .mode(SaveMode.Overwrite)
  .orc(dataDir)

sql("SELECT * FROM avro_random").show()
4

1 回答 1

2

saveAsTable适用于 Hive。如果您使用spark 将在没有 Hive 支持的情况下.orc(dataDir)将 orc 写入。dataDir

对于第二种情况。如果您尝试dataDir通过火花加载兽人,它将起作用

dataframe
  .write
  .mode(SaveMode.Overwrite)
  .orc(dataDir)

// New code is below
val newDf = spark.read.orc(dataDir)
newDf.createOrReplaceTempView("avro_random_orc") // Register TMP table instead to support sql

sql("SELECT * FROM avro_random_orc").show()
于 2019-01-25T09:12:56.890 回答