Hive 使用積累

2021-10-04 09:33:05 字數 2244 閱讀 8773

批量處理 json

處理json 字串中的單個屬性

hive 處理 null 值

hive case when

hive if else

hive 擷取字串

hive 拼接字串

hive 模糊搜尋

型別轉化

數字和字串

cast(數字 as string)

時間相關

時間戳格式化 from_unixtime(message.create_time,『yyyy-mm-dd』)

字串轉時間戳 unix_timestamp(『20201021』,『yyyymmdd』) 【生成的為短時間戳 類似 1458382610】

from_unixtime(actiontime/1000,『yyyy-mm-dd hh:mm:ss』) 【如果時間戳是毫秒】

字串拼接

批量處理 json

json_tuple 函式

json 字段 必須是標準的

select log.欄位2, 新錶名.json內部欄位1,新錶名.json內部欄位2 as sendsum 

from log.表名 log

lateral view json_tuple(log.json欄位屬性,'json內部欄位1','json內部欄位2') 新錶名

as json內部欄位1,json內部欄位2

where dt='20200324' and ctime='2020032418'

處理json 字串中的單個屬性

比如 表為 demo_table,列名為 jsonstr, 內容為 ,要搜 name 屬性,重要的是 「$.」符號

select get_json_object(demo_table.jsonstr,'$.name') as name

from demo_table

hive 處理 null 值

null 值替換

當屬性不存在就取預設值

select nvl(欄位名,0)from 表
hive 中 null 值判斷

注意 null 不等同於 空字串,空字串用 =』』 或者 !=』』

null 有兩種方式

is not null

--或者

!='\\n'

hive case when
case 待判斷屬性 when 『a』 then 『成功』 when 『b』 then 『失敗』 else 『未知』 end as 『result』

select 

case 屬性值 when 'a' then 值 when 'b' then 值 else 預設值 end as thirdpartyids

from 表名

case when 結合複雜條件

*** 注意,條件判斷情況下,case 直接跟 when

case

when (condition1) then result1

when (condition2) then result2

when (condition3) then result3

when (condition4) then result4

else result_default

end as attribute_name

hive if else
if(條件,成立值,不成立值)

select if (條件,條件成立值,條件不成立值) as sendsum from 表明
hive 擷取字串
得到 k sql,第一位為1

select substr('spark sql', 5)
hive 拼接字串

如下,將 aaa 和 bbb 拼接到一起,得到 aaabbb

select concat('aaa','bbb');
hive 模糊搜尋

比如下面,模糊搜尋包含"你好"的字串

like "%你好%"

TestDisk使用積累

硬碟ext2 3檔案系統superblock損壞修復試驗 在修復此類故障的方法中,就一種方法是重新建立分割槽表,我們可以通過第三方軟體 例如diskgen partition table doctor diskman testdisk 易我分割槽表醫生等 來掃瞄硬碟的扇區,分析資料的儲存結構來重新建...

python OS使用積累

time.time 返回當前時間,這樣的獲得的是時間戳。精確到納秒 datetime.datetime.today datetime.datetime.now 獲取時間,但是格式和time不一樣。執行結果為 2019 01 23 13 15 50.919301 可以格式化時間。例如 datetime...

git使用積累

git fetch 拉取遠端所有分支的最新的提交 git pull 拉取當前分支 git pull 拉取當前分支後會自動merge 遠端與本地merge git fetch 不會自動merge,需要手動去merge 遠端與本地 在feature分支通過git rebase master,將maste...