array+map+struct.hql

weixin_43192671發表於2019-03-22

– /* 不支援多行註釋
– 資料準備 vi /home/cat/data/ams.txt
– shiny 23 beijing,tianjin,qingdao chinese:90,math:100,english:99 1 chinese,100
– jack 34 shanghai,guangzhou chinese:89,math:56,english:87 2 math,98
– mark 26 beijing,xian chinese:94,math:78,english:81 3 english,99
– ella 21 beijing chinese:54,math:23,english:48 4 computer,78
– judy 30 shanghai,hangzhou,chongqing chinese:100,math:95,english:69 1 chinese,100
– cendy 28 beijing,shanghai,dalian,chengdu chinese:67,math:83,english:45 1 chinese,100
– */

– 建立資料庫如果沒有
create database if not exists ams;

– 使用ams資料庫
use ams;

– 建立綜合表class 其實可以用join連表插入 只是資料結構優麻煩
create table if not exists class(
name string,
age int,
worklocations array,
score MAP<string,int>,
id int,
course STRUCTname:string,score:int)
row format delimited fields terminated by ‘\t’
collection items terminated by ‘,’
map keys terminated by ‘:’
STORED as TEXTFILE;

– 載入資料
load data local inpath ‘/home/cat/data/ams.txt’ overwrite into table class;

– 將新建的class表放到HDFS上 覆蓋
insert overwrite directory ‘/data/class’ row format delimited fields terminated by ‘\t’ select * from class;

– 去Linux終端執行 havi -f ams.hql