hive 中复杂类型的使用
2015-11-11 12:08
393 查看
hive 中的复杂类型包括 array(数组)、map(字典)、struct(结构体)等,下面分别介绍。
array
struct
map
array
1. 创建临时表 hive -e "use dataalgo; create table cb_array_test(citeid int, order_id_list array<int>) row format delimited fields terminated by '\t' collection items terminated by ','"; 2. 写入数据 cat cb_array_test.txt 1 1,2,3 2 4,5,6 3 7,8,9 hive -e "use dataalgo; load data inpath '/tmp/cb_array_test.txt' overwrite into table cb_array_test" 3. 测试结果 hive -e "use dataalgo; select * from dataalgo.cb_array_test" 1 [1,2,3] 2 [4,5,6] 3 [7,8,9]
struct
1. 创建临时表 hive -e "use dataalgo; drop table if exists cb_test; create table cb_test(id int, name struct<first:string, last:string>) row format delimited fields terminated by '\t' collection items terminated by ':' " 2. 写入数据 cat struct.txt 1 'a':'a' 1 'b':'b' 1 'c':'c' 1 'd':'d' hive -e "use dataalgo; load data inpath '/tmp/struct.txt' overwrite into table cb_test" 3. 测试结果 hive -e "use dataalgo; select * from cb_test" 1 {"first":"'a'","last":"'a'"} 1 {"first":"'b'","last":"'b'"} 1 {"first":"'c'","last":"'c'"} 1 {"first":"'d'","last":"'d'"}
map
1. 创建临时表 hive -e "use dataalgo; drop table if exists cb_test_map; create table cb_test_map(id int, name map<string, string>) row format delimited fields terminated by '\t' collection items terminated by ',' map keys terminated by ':'" 2. 写入数据 cat cb_map_test.txt 1 a:a,b:b 2 c:c,d:d 3 e:e,f:f hive -e "use dataalgo; load data inpath '/tmp/cb_map_test.txt' overwrite into table cb_test_map" 3. 测试结果 hive -e "use dataalgo; select * from cb_test_map" 1 {"a":"a","b":"b"} 2 {"c":"c","d":"d"} 3 {"e":"e","f":"f"}
相关文章推荐
- TortoiseGit的安装使用
- Android AsyncTask完全解析
- about golang
- 网页设计图片素材网站 收集
- git安装及使用
- 使用ssh private key 免密码登陆服务器的流程(Amazon 的EMR 采用了此方式登陆服务器)
- Hibernate主键生成策略
- org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter.
- 几个关于控件的优先级: UseSystemPasswordChar > PasswordChar > 控件属性设置
- 监听鼠标上下滚动事件
- 简单日志集成
- 【翻译】PHP7——新特性
- asp.net 获取客户端真实Ip
- web 前端学习网站 收集
- linux gdb运行不下去的程序调试方法
- Android-->AndroidManifest.xml 文件 <meta-data> 使用方法
- java编程思想向上转型例子
- does not contain bitcode. You must rebuild it
- 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样
- jqery和js如何判断checkbox是否选中