
Hive
leeshutao
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
sql之小数点转义
所以以下图中,中括号中的.,是被转义了,就表示.本身,中括号后面的.,表示任意单个字符。原创 2022-12-30 17:23:58 · 448 阅读 · 1 评论 -
【Hive】计算分位数
hive中有两个函数可以用来计算分位数:percentile和percentile_approx具体使用方如下:(1)percentile:percentile(col, p)col是要计算的列(值必须为int类型),p的取值为0-1,若为0.5,那么就是2分位数,即中位数。(2)percentile_approx:percentile_approx(col, p)。列为数值类型都可以。percentile_approx还有一种形式percentile_approx(col, p, .原创 2022-05-16 18:40:21 · 11077 阅读 · 0 评论 -
【Hive】like与rlike的区别
摘自Hive中rlike,like,not like,regexp区别与使用详解_涤生大数据的博客-优快云博客_rlike1.like的使用详解1.语法规则:格式是A like B,其中A是字符串,B是表达式,表示能否用B去完全匹配A的内容,换句话说能否用B这个表达式去表示A的全部内容,注意这个和rlike是有区别的。返回的结果是True/False.B只能使用简单匹配符号_和%,”_”表示任意单个字符,字符”%”表示任意数量的字符like的匹配是按字符逐一匹配的,使用B从A的第一个字符开始匹配,所.转载 2022-05-11 14:50:28 · 642 阅读 · 0 评论 -
【Hive】动态分区
1. 建表,包含2个分区CREATE TABLE temp_exp20211226_shutao_generalAndZs(src string,dst string) PARTITIONED BY (dt string,type string )row format delimited fields terminated by "\t"STORED AS orc;2. 设置参数--是否开启动态分区功能,默认false关闭。使用动态分区时候,该参数必须设置成true原创 2021-11-29 14:41:00 · 1213 阅读 · 0 评论 -
Hive中case-when的应用注意空行以及结合聚合函数
--(1)建表create table cf_tmp.lst_work_wifi_test(wifi_name string,last_date string,wifi_imei_cnt int);--(2)插入数据insert into cf_tmp.lst_work_wifi_test values('fintell1107','20190430',30),('finte...原创 2019-05-22 21:08:18 · 2093 阅读 · 1 评论 -
Hive之Select Transform语法()
参考文章:阿里云 Select Transform语法 hive transform python主要解释:Select Transform功能允许指定启动一个子进程,将输入数据按照一定的格式通过stdin输入子进程,并且通过parse子进程的stdout输出来获取输出数据。能在不编写UDF的前提下实现MaxCompute SQL不具备的功能。最近的脚本涉及到的用法:...原创 2019-06-14 14:18:42 · 3277 阅读 · 0 评论 -
看一个hive表各个分区的内存大小 & 看一个hive表的更新时间
1. 看一个hive表各个分区的内存大小#看表test.students的一级分区下的内存大小hadoop fs -du -h /user/hive/warehouse/test.db/students#看表test.students的二级分区下的内存大小(假设一级分区为data_date)hadoop fs -du -h /user/hive/warehouse/test.db/...原创 2019-07-26 16:48:20 · 3956 阅读 · 1 评论 -
replace columns报code 1 from org.apache.hadoop.hive.ql.exec.DDLTask错误
目前找到的解决办法是(这边感谢xiaoxiao~):--先改fileformat为textfilealter table table_name set fileformat textfile;--再repalcealter table table_name repalce columns(col1 string,col2 string);--最后再改回来alter tab...原创 2019-08-09 15:21:41 · 442 阅读 · 1 评论 -
hive中count distinct报code 2错误
阅读文章:Hive之COUNT DISTINCT优化转载 2019-08-09 17:59:43 · 1193 阅读 · 0 评论 -
保留由C升到B再升到A的过程,但是若是由A变到C或者B,只保留A
select userid,level, time, first_value(time) OVER(PARTITION BY userid,level ORDER BY time) as firstTime, last_value(time) OVER(PARTITION BY userid,level ORDER BY time) as lastTime ...原创 2019-08-21 22:39:24 · 154 阅读 · 2 评论 -
Hive优化
本文主要参考文献:《Hive编程指南》 数据分析利器之hive优化十大原则 优化一:hive.auto.convert.join 数据分析系列(3):数据倾斜1. limit 调整以语句快速出结果很多情况下,Limit语句还是需要执行整个查询语句,然后再返回部分结果。有一个配置属性可以开启,用于对数据源进行抽样,从而避免执行整个查询语句。set hive.limi...转载 2019-09-03 12:03:48 · 199 阅读 · 0 评论 -
Hive常用函数
Hive 常用函数datediff(string enddate, string startdate) 返回int 的两个日期差 date_add(string startdate, int days) 日期加减 current_timestamp 和current_date 返回当前时间戳,当前日期 date_format(date/timestamp/string ts, stri...转载 2019-09-25 15:33:26 · 176 阅读 · 0 评论 -
用beeline将数据导入表中
(这边感谢yunheng)用beeline将数据导入表中,需要先将文件上传到hadoop,比如上传到tmp下:hadoop fs -put 路径/data.txt /tmp/然后进到beeline里面执行:load data inpath '/tmp/data.txt' overwrite into table 表名...原创 2019-05-16 21:43:29 · 3003 阅读 · 0 评论 -
beeline跑出来的文件没有数据(这里的原因是跑出来的数据量比较大)
beeline --incremental=true -f test.sqlnohup beeline --incremental=true --showHeader=true -f bj_imei_grid_wifi.sql &(感谢xianling)原创 2019-05-14 20:36:48 · 770 阅读 · 0 评论 -
Hive中yyyymmdd和yyyy-mm-dd日期之间的切换(4种方法)
方法1: from_unixtime+ unix_timestamp--20171205转成2017-12-05 select from_unixtime(unix_timestamp('20171205','yyyyMMdd'),'yyyy-MM-dd') from dual;--2017-12-05转成20171205select from_unixtime(unix_times...原创 2019-01-08 14:11:51 · 12866 阅读 · 0 评论 -
Hive分析窗口函数(一) SUM,AVG,MIN,MAX
转载自http://lxw1234.com/archives/2015/04/176.htm ,为了方便学习,侵删。数据准备CREATE EXTERNAL TABLE lxw1234 (cookieid string,createtime string, --day pv INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ...转载 2019-01-14 17:08:53 · 286 阅读 · 0 评论 -
hive查出来的命令加上表头
set hive.cli.print.header=true;原创 2019-01-09 15:33:15 · 6549 阅读 · 0 评论 -
Hive分析窗口函数(二) NTILE,ROW_NUMBER,RANK,DENSE_RANK
转载自http://lxw1234.com/archives/2015/04/181.htm ,为了方便学习,侵删。数据准备cookie1,2015-04-10,1cookie1,2015-04-11,5cookie1,2015-04-12,7cookie1,2015-04-13,3cookie1,2015-04-14,2cookie1,2015-04-15,4cookie1...转载 2019-01-15 11:39:56 · 248 阅读 · 0 评论 -
Hive分析窗口函数(三) CUME_DIST,PERCENT_RANK
转载自http://lxw1234.com/archives/2015/04/185.htm ,为了方便学习,侵删。数据准备d1,user1,1000d1,user2,2000d1,user3,3000d2,user4,4000d2,user5,5000 CREATE EXTERNAL TABLE lxw1234 (dept STRING,userid string,s...转载 2019-01-15 13:42:20 · 192 阅读 · 0 评论 -
Hive SQL脚本debug
1. 不能两个"("或者")"连着用2.Line 347:1 出现 Invalid table alias or column reference 'z_phone' :(possible column names are:phone)除了找'z_phone' 还可以找后面possible column names这些列是在哪个表里,不要局限于前面的行数347附近3. 下次不知道...原创 2019-01-09 21:10:39 · 718 阅读 · 0 评论 -
看某个表的某个分区是不是有数据
hadoop fs -du -s -h /user/hive/warehouse/ronghui_mart.db/table_name/data_date=201811*原创 2019-03-04 22:35:05 · 575 阅读 · 0 评论 -
转:hive中regexp_extract的用法总结
hive中regexp_extract的用法总结如:1)select regexp_extract('hitdecisiondlist','(i)(.*?)(e)',0) ;得到的结果为:itde2)select regexp_extract('hitdecisiondlist','(i)(.*?)(e)',1) ;得到的结果为:i3)select ...转载 2019-04-28 17:36:20 · 3338 阅读 · 0 评论 -
hive之regexp_replace函数、split函数的正则
Hive中,regexp_replace函数的第2个参数是正则表达式,第3个参数是字符串select split(regexp_replace(data,'\\},\\{','}||{'),'\\|\\|')[0]as test from (select '[{"source":"7fresh","monthSales":4900,"userCount":1900,"score":"...原创 2019-04-28 21:00:41 · 8660 阅读 · 0 评论 -
hive之substr函数
select case when int(substr(time,1,2))<05 then 1when int(substr(time,1,2))>=05 and int(substr(time,1,2))<12 then 2when int(substr(time,1,2))>=12 and int(substr(time,1,2))<18 then 3...原创 2019-04-24 16:29:12 · 10144 阅读 · 0 评论 -
hive之正则表达式函数
以下摘自:regexp正则表达式:提取目标内容在hive环境中相关的函数有如下三个:regexp :主要用在where子句中,用来选择内容 regexp_extract :用在select 子句中,用来从目标内容中提取指定样式内容 regexp_replace :用在select 子句中,用来将目标内容的特定部分替换成指定的内容1. regexpselect case w...原创 2019-04-24 16:59:11 · 7174 阅读 · 0 评论 -
把数据灌到已有hive表里
0. 如果原来的表里有分区最好先把分区删掉。 例如如果原来的表里有一个叫‘date’的分区,新灌入的数据里如果也有叫‘date’的分区,新数据灌入以后可能读不出来。--在hive中操作alter table table10_jin drop partition(tablename='alp',data_date='alp',part1='alp',part2='alp');1...原创 2019-01-02 20:15:22 · 629 阅读 · 0 评论