遇到的一些hive字符串处理 汇总

持续更新。。。

--取第一个顿号前面的所有字符

 split(new_occupy,'、')[0] as new_occupy

 

--替换

regexp_replace(occupy,',','、')

 

--hive不识别英文分号,输入报错问题 用\073

select cons_name,split(cons_name,'\073')[0] from WLH_TABLE_M11 where cons_name limit 10;

 

--截取分号与逗号之间的字符串

select cons_name,substr(cons_name,length(split(cons_name,'\073')[0])+2,(length(split(cons_name,',')[0])-length(split(cons_name,'\073')[0]))-1) from WLH_TABLE_M11 limit 10;

 

--删除分区

ALTER TABLE table_name DROP IF EXISTS PARTITION (inc_day='20180822');

 

--取日期对应的星期,第一个日期要为周日的日期

select pmod(datediff( '2018-08-29','2018-08-26'), 7)  from dual

 

--日期格式转换,例子为yyymmmdd转为yyyy-mm-dd

from_unixtime(unix_timestamp('20171205','yyyymmdd'),'yyyy-mm-dd') 

 

--时间需要修改,因为现在系统的时间是秒

select from_unixtime(cast(time_col/1000 as bigint),'yyyy-MM-dd HH:mm:ss') from table_name limit 10

注:to_date只能用于string类型 from_unixtime用于bigint

 

 

--查询

grep -ir "table_name/任务名称" --color

 

--调度

crontab -e

 

--上传

a.load data inpath  路径/wlh1.txt overwrite into table table_name

b.hadoop fs -put  wlh.txt /wlh.txt

c.例:将110主机上的文件夹 table_t3 传到本机的/data/log_data/目录下

   hadoop fs -get hdfs://路径/table_t3

   scp -r [email protected]:/wdir/wlh/table_t3 /data/log_data/

 

 

 

 

 

你可能感兴趣的:(每天一点HIVE)