在 Parquet 数据上使用 Avro 架构动态创建 Hive 外部表 [英] Dynamically create Hive external table with Avro schema on Parquet Data

查看:29
本文介绍了在 Parquet 数据上使用 Avro 架构动态创建 Hive 外部表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态地(没有在 Hive DDL 中列出列名和类型)在镶木地板数据文件上创建一个 Hive 外部表.我有底层镶木地板文件的 Avro 架构.

I'm trying to dynamically (without listing column names and types in Hive DDL) create a Hive external table on parquet data files. I have the Avro schema of underlying parquet file.

我尝试使用以下 DDL:

My try is to use below DDL:

CREATE EXTERNAL TABLE parquet_test
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS PARQUET
LOCATION 'hdfs://myParquetFilesPath'
TBLPROPERTIES ('avro.schema.url'='http://myHost/myAvroSchema.avsc');

我的 Hive 表已使用正确的架构成功创建,但是当我尝试读取数据时:

My Hive table is successfully created with the right schema, but when I try to read the data :

SELECT * FROM parquet_test;

我收到以下错误:

java.io.IOException: org.apache.hadoop.hive.serde2.avro.AvroSerdeException: Expecting a AvroGenericRecordWritable

有没有一种方法可以成功创建和读取 Parquet 文件,而无需在 DDL 中提及列名和类型列表?

Is there a way to successfully create and read Parquet files, without mentioning columns name and types list in DDL?

推荐答案

以下查询有效:

CREATE TABLE avro_test ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe' STORED AS AVRO TBLPROPERTIES ('avro.schema.url'='myHost/myAvroSchema.avsc'); 

CREATE EXTERNAL TABLE parquet_test LIKE avro_test STORED AS PARQUET LOCATION 'hdfs://myParquetFilesPath';

这篇关于在 Parquet 数据上使用 Avro 架构动态创建 Hive 外部表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆