快捷搜索:  汽车  科技

大数据hive入门冷知识(大数据进击之路)

大数据hive入门冷知识(大数据进击之路)其他一些:设置变量:array:map:struct:

大数据hive入门冷知识(大数据进击之路)(1)

基础命令:

大数据hive入门冷知识(大数据进击之路)(2)

建表语句:

大数据hive入门冷知识(大数据进击之路)(3)

表结构修改:

大数据hive入门冷知识(大数据进击之路)(4)

字段类型:

  • tinyint smallint int bigint float decimal boolean string

复合数据类型

  • struct array map
复合数据类型:

array:

大数据hive入门冷知识(大数据进击之路)(5)

map:

大数据hive入门冷知识(大数据进击之路)(6)

struct:

大数据hive入门冷知识(大数据进击之路)(7)

优化配置:

大数据hive入门冷知识(大数据进击之路)(8)

设置变量:

大数据hive入门冷知识(大数据进击之路)(9)

其他一些:

大数据hive入门冷知识(大数据进击之路)(10)

常用函数:

if函数,如果满足条件,则返回A,否则返回B:

  • if(boolean condition TA TB)

case 条件判断函数当a为b时则返回c;当a为d时,返回e;否则返回f

  • case a when b then c when d then e else f end

将字符串类型的数据读取为json类型,并得到其中的元素key的值,第一个参数填写json对象变量,第二个参数使用表示json变量标识,然后用.读取对象或数组;

  • get_json_object(string s ‘$.key)

url解析(parse url())

  • parse url(http://weibo.com/path/p1.php?query=1 "HOST)返回'weibo.com'
  • parse url("http://weibo.com/path/p1.php?query=1 "PATH")返回/path/p1.php'
  • parse url"http://weibo.com/path/p1.php?query=1 'QUERY)返回'query=1'

其他一些常用函数:

explode就是将hive一行中复杂的aray或者map结构拆分成多行

  • explode(colname)

lateral view 将一行数据adid list拆分为多行adid后,使用lateral view使之成为一个虚表adTable,使得每行的数据adid与之前的pageid一一对应

  • select pageid adid from pageAds
  • lateral view explode(adid_list)adTable as adid

去除两边空格

  • trim()

大小写转换

  • lower(),upper()

返回列表中第一个非空元素如果所有值都为空,则返回null

  • coalesce(v1 v2 v3,.…)

返回当前时间

  • from_unixtime(unix_timestamp() yyyy-MM-dd HH:mm:ss')

返回第二个参数在待查找字符串中的位置(找不到返回0)

  • instr(string str string search_str)

字符串连接

  • concat(string A string B string C,...)

自定义分隔符sep的字符串连接

  • concat_ws(string sep string A string B string C ...)

返回字符串长度

  • length()

反转字符串

  • reverse()

字符串截取

  • substring(string A int start int len)

将字符串A中的符合java正则表达式pat的部分替换为C;

  • regexp_replace(string A string pat string C)

将字符串subject按照pattern正则表达式的规则进行拆分,返回index制定的字符0:显示与之匹配的整个字符串,1:显示第一个括号里的,2:显示第二个括号里的

  • regexp_extract(string subject string pattern int index)

按照pat字符串分割str,返回分割后的字符串数组

  • split(string str string pat)

类型转换

  • cast(expr as type)

将字符串转为map,item pat指定item之间的间隔符号,dict pat指定键与值之间的间隔

  • str_to_map(string A string item_pat string dict_pat)#提取出map的key,返回key的arraymap_keys(map m)

日期函数#日期比较函数,返回相差天数,datediff($(cur datel d)

  • datediff(datel.date2)
实际使用:

增加分区:

  • inster overwrite table table_name partition(d = ${pre_date})

建表语句:

大数据hive入门冷知识(大数据进击之路)(11)

Hive桶:

大数据hive入门冷知识(大数据进击之路)(12)

注意:

  • 如果字段类型是string,则通过get json_object提取数据;
  • 如果字段类型是struct或map 则通过col[xx]方式提取数据;
shell命令:

大数据hive入门冷知识(大数据进击之路)(13)

如果觉得对你有所帮助。记得收藏和关注呦!(每日更新各种大数据框架)

如需转载请注明出处(创作不易请见谅)

和巨婴程序猿一起成长。让自己变得更优秀

大数据hive入门冷知识(大数据进击之路)(14)

想了解更多精彩内容,快来关注跟着巨婴去逆袭

我最近一直在思考(大数据通俗讲解)的问题,你的看法是什么呢?关注我快说出来一起交流一下吧~

猜您喜欢: