【Hive十三】Hive读写Avro格式的数据

 1. 原始数据

hive> select * from word; 
OK
1	MSN  
10	QQ  
100	Gtalk  
1000	Skype 

 

 

 2. 创建avro格式的数据表

 

hive> CREATE TABLE avro_table(age INT, name STRING)STORED AS AVRO;

 

 

3. 数据表的描述

 

hive> describe avro_table; 
OK
age                 	int                 	from deserializer   
name                	string              	from deserializer   
Time taken: 0.154 seconds, Fetched: 2 row(s)

 

 

 

4. 插入数据

 

hive> INSERT OVERWRITE TABLE avro_table SELECT * FROM word;

 

 

5. 查询

hive> select * from avro_table;
OK
1	MSN  
10	QQ  
100	Gtalk  
1000	Skype 

 

6. HDFS上文件的内容(avro二进制格式)

Objavro.schema?{"type":"record","name":"avro_table","namespace":"default","fields":[{"name":"age","type":["null","int"],"doc":"\u0000","default":null},{"name":"name","type":["null","string"],"default":null}]} 9?$-侭蹈艉{3!
T
MSN  QQ  ?Gtalk  ?Skype   9?$-侭蹈艉{3!

 

 

7.参考

https://cwiki.apache.org/confluence/display/Hive/AvroSerDe

 

 

你可能感兴趣的:(hive)