1. 程式人生 > 其它 >HIVE:

HIVE:

my_cluster.sh start
(1-標準輸出,2-錯誤輸出,2>&1 : 表示將錯誤重定向到標準輸出上,&: 放在命令結尾,表示後臺執行)
nohup hive --service metastore 1>/opt/module/hive-3.1.2/logs/metastore.log 2>&1 &
nohup hive --service hiveserver2 1>/opt/module/hive-3.1.2/logs/hiveSercer2.log 2>&1 &
beeline -u jdbc:hive2://hadoop102:10000 -n atguigu ---退出命令 ----> !quit

停止所有的RunJar程序
jps | grep RunJar | awk '{print $1}' | xargs -n1 kill -9

hive啟停指令碼
-- hiveService.sh start
-- 等一會,再啟動
-- beeline -u jdbc:hive2://hadoop102:10000 -n atguigu
-- hiveService.sh stop

將JSON格式轉為以下形式,存在coll.txt檔案中;
songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing

create table collection(
name string ,
friends array<string>,
childrens map<string,int>,
address struct<street:string,city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

資料存在coll.txt檔案中
load data local inpath '/opt/module/hive-3.1.2/datas/coll.txt' into table collection;
載入資料 本地路徑(存放的資料) 目標表

查詢另一種方式:
struct-->address struct<street:string,city:string> ---> 查詢時可以將strut的集合屬性類比於java的物件
select name,friends[0],childrens['xiao song'],address.street from collection;