– /* 不支持多行注释
– 数据准备 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