Hive QL详解

<一>数据定义(DML)操作

1、创建普通表

create table page_view 
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table' ;

2、添加表分区

create table page_view 
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table' 
partitioned by (dt string , country string)
row format delimited    
fields terminated by '\001'
stored as sequencefile;

3、添加聚类存储

create table page_view 
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table' 
partitioned by (dt string , country string)
clustered by(userid) sorted by(viewTime) into 32 buckets
row format delimited    --delimite限制
fields terminated by '\001'
collection items terminated by '\002'
map keys terminated by '\003'
stored as sequencefile;

4、指定存储路径

create table page_view 
(viewtime int,
userid bigint,
page_url string,
referrer_url string,
ip STRING comment 'IP Address of the User')
comment 'This is the page view table' 
row format delimited 
fields terminated by '\054'
stored as textfile
location '<hdfs_location>';  

5、重命名表

alter table   tablename  rename to new_table_name ;

6、改变列名字/类型/位置/注释

create table test (a int , b int , c int);
alter table test change a a1 int ;
alter table test change a a1 string after b ;
alter table test change b b1 int first ;
注意:列的改变只会修改hive的元数据,不会修改实际数据。用户应该确保元数据定义和实际数据结构的一致性。

7、增加/更新列

alter table test  add|replace 
columns (d int comment 'new columns');

注:replace,删除当前的列,增加新的列。只有使用native的SerDE时才可以这么做。


8、增加表属性

alter table table_name set tblproperties table_properties
table_properties:
:(property_name = property_value , property_name = property_value)

9、增加SerDe属性

alter table table_name 
set serde serde_class_name
[with serdeproperties serde_properties]

alter table table_name
set serdeproperties serde_properties

ser_properties:
:(property_name =property_value , property_name = property_value)
注:Hive 为了序列化和反序列化,将会初始化SerDe属性。


10、改变文件格式和组织

alter table table_name set fileformat file_format ;
alter table table_name clustered by (col_name,col_name,...)
[sorted by (col_name,col_name,...)] into num_buckets buckets


11、增加分区

alter table page_view add 
partition (dt='2010-08-08',country='us')
location '/path/to/us/part080808'
partition (dt='2010-08-09',country='us')
location '/path/to/us/part080809';

12、删除分区
alter table page_view drop
partition (dt='2010-08-08',country='us');

13、创建视图

create view [if not exists] view 
[(column_name [comment column_comment],...)]
[comment view_coment]
as select ... ;


14、创建/删除函数

create temporary funcation funcation_name as class_name;
drop  temporary funcation_name ;


<二>数据操作(DML)

插入数据:load data local inpath '/iflytek/data/test.txt' into table test ;

其他的可以参考:http://blog.csdn.net/lifuxiangcaohui/article/details/40588929


<三>数据查询(DCL)

与标准的SQL类似。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
窗口函数是一种在Hive中用于分析数据的函数。它指定了函数工作的数据窗口大小,也就是当前行的上下多少行。与聚合函数不同,窗口函数对于每个组返回多行,而聚合函数只返回一行。在日常的开发中,常用的窗口函数包括sum() over()、count() over()等。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [hive的窗口函数详解](https://blog.csdn.net/qianfeng_dashuju/article/details/107151220)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【大数据HiveHive 窗口函数使用详解](https://blog.csdn.net/congge_study/article/details/128996163)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Hive语法详解](https://download.csdn.net/download/thomson617/10952541)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值