HiveSQL学习
1、建表语句
createtablet_user(idbigint,name string)rowformat delimited fielsterminatedby','//字段列之间以逗号分隔linesterminatedby'\n'//行之间以换行符分隔storeastextfile;//存储形式带数组字段的建表
createtablet_user(idbigint,name string,scores array<int>)rowformat delimited fielsterminatedby','//字段列之间以逗号分隔linesterminatedby'\n'//行之间以换行符分隔collection itemsterminatedby','storeastextfile;//存储形式数据展示
查询每个学生的第一个成绩
selectscores[0]fromt_user;2、加载本地数据到表
load localdatainpath'本地路径'into table t_user;3、加载hdfs数据到表
1、先将本地数据上传到HDFS
hdfs dfs-put 本地路径 hdfs路径
本质是挪动数据
loaddatainpath'hdfs路径'into table t_user;执行完后可以发现,在/home目录下就没有user.txt了
其实文本数据是迁移到表t_user下了
4、从其他表复制数据
insertintot_user2select*fromt_user;5、克隆表
克隆的表从表结构到数据与源表一模一样
createtablet_user3asselect*fromt_user;