亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Hive創建表及插入數據demo

發布時間:2020-06-12 21:54:49 來源:網絡 閱讀:4025 作者:zjy1002261870 欄目:大數據

create table student(id int comment "學生id",name string comment "學生姓名",age int comment "學生年齡")
comment "學生信息表"
row format delimited fields terminated by ",";

create external table student_ext(id int comment "學生id",name string comment "學生姓名",age int comment "學生年齡")
comment "學生信息表"
row format delimited fields terminated by ","
location "/user/hive/student_ext";

create external table student_ptn(id int comment "學生id",name string comment "學生姓名",age int comment "學生年齡")
comment "學生信息表"
partitioned by (city string)
row format delimited fields terminated by ","
location "/user/hive/student_ptn";

set hive.exec.dynamici.partition=true; #開啟動態分區,默認是false
set hive.exec.dynamic.partition.mode=nonstrict; #開啟允許所有分區都是動態的,否則必須要有靜態分區才能使用。

set hive.exec.dynamic.partition=true;(可通過這個語句查看:set hive.exec.dynamic.partition;)
set hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.max.dynamic.partitions=100000;(如果自動分區數大于這個參數,將會報錯)
SET hive.exec.max.dynamic.partitions.pernode=100000;

insert into table student_ptn partition(city) select 6,"yangdong",29,"beijing";
insert into table student_ptn partition(city) select 2,"limei",22,"chongqing";
insert into table student_ptn partition(city) select 3,"wangxing",25,"beijing";
insert into table student_ptn partition(city) select 4,"chenming",22,"beijing";
insert into table student_ptn partition(city) select 5,"xiali",26,"chongqing";

create external table student_bck(id int comment "學生id",name string comment "學生姓名",age int comment "學生年齡")
comment "學生信息表"
clustered by(id) sorted by(id asc) into 2 buckets
row format delimited fields terminated by ","
location "/user/hive/student_bck";

insert into table student_bck
select * from student;

create table cdt(
id int,
name string,
work_location array<string>,
piaofang map<string,bigint>,
address struct<location:string,zipcode:int,phone:string,value:int>)
row format delimited
fields terminated by "\t"
collection items terminated by ","
map keys terminated by ":"
lines terminated by "\n";

將json字符串加載到table json中
{"movie":"1193","rate":"5","timeStamp":"978300760","uid":"1"}
{"movie":"661","rate":"3","timeStamp":"978302109","uid":"1"}
{"movie":"914","rate":"3","timeStamp":"978301968","uid":"1"}
{"movie":"3408","rate":"4","timeStamp":"978300275","uid":"1"}
{"movie":"2355","rate":"5","timeStamp":"978824291","uid":"1"}
{"movie":"1197","rate":"3","timeStamp":"978302268","uid":"1"}
{"movie":"1287","rate":"5","timeStamp":"978302039","uid":"1"}
{"movie":"2804","rate":"5","timeStamp":"978300719","uid":"1"}
{"movie":"594","rate":"4","timeStamp":"978302268","uid":"1"}

CREATE TABLE json(
data string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://hmaster:9000/user/hive/warehouse/plusorg.db/json'
TBLPROPERTIES (
'transient_lastDdlTime'='1542008332')

load data local inpath "/root/json.txt" into table json;
get_json_object(data,'$.movie') 內置函數解析某列數據
select get_json_object(data,'$.movie') as movie from json;
json_tuple(jsonStr, k1, k2, ...) 內置函數解析json字符串類數據
參數為一組鍵k1,k2……和JSON字符串,返回值的元組。該方法比?get_json_object?高效,因為可以在一次調用中輸入多個鍵

select
b.b_movie,
b.b_rate,
b.b_timeStamp,
b.b_uid
from json a
lateral view json_tuple(a.data,'movie','rate','timeStamp','uid') b as b_movie,b_rate,b_timeStamp,b_uid;

create table rate(movie int, rate int, unixtime int, userid int) row format delimited fields
terminated by '\t';

insert into table rate select
get_json_object(data,'$.movie') as moive,
get_json_object(data,'$.rate') as rate,
get_json_object(data,'$.timeStamp') as unixtime,
get_json_object(data,'$.uid') as userid
from json;

select from_unixtime(unixtime,'yyyy/MM/dd HH:mm:ss') from rate;

create table lastjsontable(movie int, rate int, utime date, userid int) row format delimited
fields terminated by '\t';
添加Python腳本,hive即可訪問,路徑為在當前Unix服務器存儲絕對路徑
add file /home/pythoncode/WeekdayMapper.py;

insert into table lastjsontable
select
transform(movie,rate,unixtime,userid) #輸入值(基表)
using 'python WeekdayMapper.py' #使用腳本清洗
as(movie,rate,utime,userid) #輸出值(子表)
from rate; #基表

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

天水市| 高陵县| 洛浦县| 那曲县| 长阳| 彭山县| 马尔康县| 长岛县| 瑞丽市| 绥宁县| 高尔夫| 河南省| 义马市| 乐陵市| 浦县| 云南省| 丹凤县| 黄浦区| 宜阳县| 谷城县| 西峡县| 汶上县| 内黄县| 家居| 从江县| 神农架林区| 南部县| 改则县| 崇仁县| 桐庐县| 静海县| 石棉县| 金华市| 资讯| 隆回县| 吴堡县| 天门市| 彩票| 永州市| 大姚县| 若羌县|