【发布时间】:2019-07-17 07:02:12
【问题描述】:
我正在尝试在使用spark-scala 生成的一些avro 文件之上创建一个Hive external table。我正在使用CDH 5.16,它有hive 1.1、spark 1.6。
我创建了hive external table,它运行成功。但是当我查询数据时,我得到了所有列的NULL。
My problem is similar to this
经过一些研究,我发现这可能是架构的问题。但我在该位置找不到这些 avro 文件的架构文件。
我对@987654334@ 文件类型很陌生。有人能帮帮我吗?
下面是我的spark代码sn-p,我将文件保存为avro:
df.write.mode(SaveMode.Overwrite).format("com.databricks.spark.avro").save("hdfs:path/user/hive/warehouse/transform.db/prod_order_avro")
下面是我的hive外部表创建语句:
create external table prod_order_avro
(ProductID string,
ProductName string,
categoryname string,
OrderDate string,
Freight string,
OrderID string,
ShipperID string,
Quantity string,
Sales string,
Discount string,
COS string,
GP string,
CategoryID string,
oh_Updated_time string,
od_Updated_time string
)
STORED AS AVRO
LOCATION '/user/hive/warehouse/transform.db/prod_order_avro';
以下是我查询数据时得到的结果:
select * from prod_order_avro
同时,当我使用spark-scala 作为dataframe 读取这些avro 文件并打印它们时,我得到了正确的结果。
下面是我用来读取这些数据的spark 代码:
val df=hiveContext.read.format("com.databricks.spark.avro").option("header","true").load("hdfs:path/user/hive/warehouse/transform.db/prod_order_avro")
我的问题是,
- 在创建这些
avro文件时,我是否需要更改我的spark
单独创建架构文件的代码或将其嵌入
文件。如果需要分开,那如何实现呢? - 如果不是如何创建
hive表,以便从 自动存档。我读到在最新版本中,蜂巢负责 如果文件中存在架构,则此问题本身。
请帮帮我
【问题讨论】:
标签: hadoop hive avro spark-avro hive-table