Hive数据提取

Hive是基于Hadoop的ETL工具和数据仓库。

结构化数据

结构化数据就像RDBMS

hive> create table structured_table(id int, name string)
    > row format delimited
    > fields terminated by ','
    > location '/yandufeng/structured_table';
OK
Time taken: 0.209 seconds
hive> load data local inpath '/home/hive/test2.txt' into table structured_table;
Loading data to table default.structured_table
Table default.structured_table stats: [numFiles=1, totalSize=23]
OK
Time taken: 0.831 seconds
hive> select * from structured_table;
OK
1    hello
2    name
3    world
Time taken: 0.106 seconds, Fetched: 3 row(s)

半结构化的数据,例如:json,xml

hive> 
    > create table json_table(str string);
OK
Time taken: 0.229 seconds
hive> load data local inpath '/home/hive/json_table.json' into table json_table;
Loading data to table default.json_table
Table default.json_table stats: [numFiles=1, totalSize=26]
OK
Time taken: 1.523 seconds
hive> select get_json_object(str, '$.a') from json_table;
OK
2
Time taken: 0.168 seconds, Fetched: 1 row(s)
hive> select get_json_object(str, '$.a'), get_json_object(str, '$.b') from json_table;
OK
2    blah
Time taken: 0.084 seconds, Fetched: 1 row(s)

 什么时候使用Hive

  • 当需要强大的统计方法的时候
  • 当要处理结构化或者半结构化数据
  • 当需要基于Hadoop的数据仓库
  • 可以于Hbase结合

Hive用在什么地方

  • 作为ETL工具和数据仓库
  • 提供HQL进行数据查询
  • 为特定的需求,用自定义的map和reduce脚本
原文地址:https://www.cnblogs.com/yandufeng/p/6433622.html