
hive
天马行空KY
这个作者很懒,什么都没留下…
展开
-
Hive分桶创建及查询抽样(samping)数据
分桶表的作用: 做数据抽样及提升某些查询效率,例如mapside join1、生成辅助表create table bucket_num(num int);load data local inpath '/home/keyan/hive_test/digit.txt'into table bucket_num;ps:digit.txt使用shell脚本生成的,生成1到20,脚本如下:for i in {1..20} do ec...原创 2020-08-29 19:03:38 · 426 阅读 · 0 评论 -
Hive内部表和外部表区别
建立内部表:# 创建create table art_inn(sentence string)row format delimited fields terminated by '\n';# 导入load data local inpath '/home/root/mapreduce/The_Man_of_Property.txt'into table art_inn;建立外部表:注意:外部表是在创建的时候定义实体数据的位置的,而且位置必须为文件夹,不能为文件。create原创 2020-08-29 17:40:00 · 799 阅读 · 0 评论 -
Hive UDF字符串匹配函数
1、需求用逗号分隔的细粒度子串(match_str)与粗粒度字符串(source_str)匹配,如果粗粒度子串和细粒度子串的交集,交集按照中文排序,形成以逗号分隔的字符串返回2、UDF函数:MatchStringimport org.apache.hadoop.hive.ql.exec.UDF;import java.util.ArrayList;import java.util.Collections;public class StringMatch extends UDF {..原创 2020-08-28 22:25:42 · 755 阅读 · 0 评论 -
Hive、Spark、Python实现WordCount
Hive:select word, count(*)from (selectexplode(split(sentence, ' ')) as wordfrom article) tgroup by word原创 2020-08-27 12:42:47 · 186 阅读 · 0 评论 -
Hive创建分区及动态和静态分区实例
1、动态分区全量注意:动态分区字段必须在最后面及必须设置set hive.exec.dynamic.partition=true;不然报错set hive.exec.dynamic.partition=true;set hive.exec.dynamic.partition.mode=nonstrict;set hive.exec.max.dynamic.partitions=100000;set hive.exec.max.dynamic.partitions.pernode=100000;原创 2020-08-06 10:07:25 · 1193 阅读 · 0 评论 -
Hive字符串、条件、复杂类型函数
1、concat:多个子串连接concat('1', '2')2、regexp_replace(源字符串, 匹配的子串, 替换的子串)select regexp_replace('a,b,c', ',', '|')3、if(判断语句, 满足, 不满足)select if(2>1, 1, 0)3、collect_ws:按行将值连接起来变成一个数组4、concat_ws:按照分隔符将数组的值连起来变成一个以分隔符分隔的字符串5、str_to_map:将字符串变成原创 2020-08-06 09:58:11 · 478 阅读 · 0 评论 -
Hive开窗函数last_value、lead、lag、row_number、rank、dense等
一、开窗类1、求截止到当前行不为空最后一个值select calendar_day,if_trade_dt,mkt_code,last_value(tmp_trade_dt, true) over(partition by mkt_code order by calendar_day desc) as gt_trade_dt,last_value(tmp_trade_dt, true) over(partition by mkt_code order by calendar_day) as.原创 2020-08-04 17:54:01 · 1667 阅读 · 0 评论 -
Hive日期处理
1、求自然日、上一自然日、下一自然日、本周初/末、本月初/末、本季初/末、本年初/末、一月/三月/六月/一年前等selectcalendar_day AS CALENDAR_DAY, --'自然日(日期型)'regexp_replace(calendar_day,'-','') AS CALENDAR_DT, --'自然日(数值型)'date_add(calendar_day, -1) AS LAST_CALENDAR_DT,...原创 2020-07-31 10:42:47 · 3886 阅读 · 1 评论