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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值