hive学习心得二

4.HiveQl数据操作
a)像管理表中装载数据
insert overwrite table table_name partition(column_name='值1',column_name2='值2')
select column_name from table_name;
b)导出数据
1)hadoop fs -get /user/dim/dim_w3_gprs_product_type.txt /bonc/bonc/shell/zb_test/database
2)insert overwrite local directory '/bonc/hadoop/shell/default'
 row format delimited
 fields terminated by '\t'
 select * from dim_w3_gprs_product_type;
3)hive -e "select * from zb_dim.dim_w3_gprs_product;">/bonc/hadoop/shell/default/dim_w3_gprs_product.txt
需要注意的是这种方式数据之间的分隔符为默认的TAB键,其执行过程也是通过Mapreduce完成,但个数只有一个。”>”代表重写,”>>”代表追加。

5.Hive查询
a)避免mapruduce查询
select * from table_name limit 1;
6.HiveQL视图
a)创建视图
create view [if not exists] view_name [(column_name [comment column_comment],...)]
[comment view_commnet]
[tblproperties (property_name=property_value,...)]
as select....
b)删除view
drop view [if exists] view_name
c)修改view
alter view view_name set tblproperties table_properties
table_properties:
:(property_name = property_value,properyp_name = property_value,...)
7.HiveQL索引
创建索引
create index index_name
on table base_table_name (column_name,...)
as 'index.handler.class.name'
[with deferred rebuild]
[idxproperties (property_name=property_value,...)]
[in table index_table_name]
[partitioned by (column_name,...)]
[
[row format ...] stored as ...
| stored by
]
[location hdfs_path]
[tblproperties (...)]
[comment "index_comment"]
注意:
1.index的partition默认和数据表一致
2.视图上不能创建index
3. index可以通过stored as配置存储格式
重建索引
alter index index_name on table_name [partition (...)] rebuild
注意:
1.当hive数据更新时,必须调用该语句更新索引。
2. index rebuild操作时一个原子操作,因此,当rebuild失败时,先前构建的索引也无法使用
删除索引
drop index index_name on table_name;

你可能感兴趣的:(hive,Hadoop)