hive splict, explode, lateral view, concat_ws
hive> create table arrays (x array<string>)
> row format delimited fields terminated by '\001'
> collection items terminated by '\002'
> ;
OK
Time taken: 0.574 seconds
hive> show tables;
OK
arrays
jigou
Time taken: 0.15 seconds, Fetched: 2 row(s)
hive> show create table arrays;
OK
CREATE TABLE `arrays`(
`x` array<string>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\u0001'
COLLECTION ITEMS TERMINATED BY '\u0002'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://hdp1.hadoop.test:8020/apps/hive/warehouse/zhangchao.db/arrays'
TBLPROPERTIES (
'transient_lastDdlTime'='1441481876')
Time taken: 0.399 seconds, Fetched: 13 row(s)
hive> load data local inpath './arrays.text' into arrays;
FAILED: ParseException line 1:44 missing TABLE at 'arrays' near '<EOF>'
hive> load data local inpath './arrays.text' into table arrays;
FAILED: SemanticException Line 1:23 Invalid path ''./arrays.text'': No files matching path file:/usr/java/arrays.text
hive> load data local inpath '/home/zhangchao/arrays.text' into table arrays;
Loading data to table zhangchao.arrays
Table zhangchao.arrays stats: [numFiles=1, totalSize=10]
OK
Time taken: 1.322 seconds
hive> select * from arrays;
OK
["a","b"]
["c","d","e"]
Time taken: 1.076 seconds, Fetched: 2 row(s)
hive> select explode(x) as xx from arrays;
Query ID = zhangchao_20150906052727_87971c63-6a8a-4a15-9465-2564cf22c837
Total jobs = 1
Launching Job 1 out of 1 Status: Running (Executing on YARN cluster with App id application_1440440163499_0008) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 3 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 11.95 s
--------------------------------------------------------------------------------
OK
a
b
c
d
e
Time taken: 19.465 seconds, Fetched: 5 row(s)
hive> select concat_ws(',', '1','2','3','4') from arrays;
OK
1,2,3,4
1,2,3,4
Time taken: 0.107 seconds, Fetched: 2 row(s)
hive> select split(concat_ws(',', '1','2','3','4'),',') from arrays;
OK
["1","2","3","4"]
["1","2","3","4"]
Time taken: 0.128 seconds, Fetched: 2 row(s)
hive> select split(concat_ws(',', '1','2','3','4'),',')[3] from arrays;
OK
4
4
Time taken: 0.116 seconds, Fetched: 2 row(s)
hive> select explode(split(concat_ws(',', '1','2','3','4'),',')) from arrays;
Query ID = zhangchao_20150906063535_e0067b77-0481-48aa-b3dc-055a7e6b6c3c
Total jobs = 1
Launching Job 1 out of 1 Status: Running (Executing on YARN cluster with App id application_1440440163499_0012) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 1 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 10.51 s
--------------------------------------------------------------------------------
OK
1
2
3
4
1
2
3
4
Time taken: 11.757 seconds, Fetched: 8 row(s)
hive> select * ,sp from arrays lateral view explode(split(concat_ws(',','1','2','3','4'),',')) a as sp;
Query ID = zhangchao_20150906064040_c275e654-c7d1-45d2-86a8-18fb5506d4f2
Total jobs = 1
Launching Job 1 out of 1 Status: Running (Executing on YARN cluster with App id application_1440440163499_0012) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 1 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 5.94 s
--------------------------------------------------------------------------------
OK
["a","b"] 1 1
["a","b"] 2 2
["a","b"] 3 3
["a","b"] 4 4
["c","d","e"] 1 1
["c","d","e"] 2 2
["c","d","e"] 3 3
["c","d","e"] 4 4
Time taken: 6.906 seconds, Fetched: 8 row(s)
hive> select 'xx' ,sp from arrays lateral view explode(split(concat_ws(',','1','2','3','4'),',')) a as sp;
Query ID = zhangchao_20150906064545_f1ce3669-80ff-45a5-a1a8-6211f56d77bd
Total jobs = 1
Launching Job 1 out of 1 Status: Running (Executing on YARN cluster with App id application_1440440163499_0012) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 2 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 7.20 s
--------------------------------------------------------------------------------
OK
xx 1
xx 2
xx 3
xx 4
xx 1
xx 2
xx 3
xx 4
Time taken: 8.23 seconds, Fetched: 8 row(s)
hive> select * from lateral_test;
OK
999
Time taken: 0.087 seconds, Fetched: 1 row(s)
hive> select * , sp from lateral_test lateral view explode(split(concat_ws(',','1','2','3','4','5'),',')) as sp;
FAILED: ParseException line 1:104 extraneous input 'sp' expecting EOF near '<EOF>'
hive> select * , sp from lateral_test lateral view explode(split(concat_ws(',','1','2','3','4','5'),',')) a as sp;
Query ID = zhangchao_20150906065252_ed187ad7-b400-4b71-add9-c7dc005f4af1
Total jobs = 1
Launching Job 1 out of 1
Tez session was closed. Reopening...
Session re-established. Status: Running (Executing on YARN cluster with App id application_1440440163499_0014) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 1 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 7.21 s
--------------------------------------------------------------------------------
OK
999 1 1
999 2 2
999 3 3
999 4 4
999 5 5
Time taken: 16.504 seconds, Fetched: 5 row(s)
hive> select lateral_test.* , sp from lateral_test lateral view explode(split(concat_ws(',','1','2','3','4','5'),',')) a as sp;
Query ID = zhangchao_20150906065757_2db20ede-33d6-467f-886c-574a06995041
Total jobs = 1
Launching Job 1 out of 1 Status: Running (Executing on YARN cluster with App id application_1440440163499_0014) --------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 0 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 7.01 s
--------------------------------------------------------------------------------
OK
999 1
999 2
999 3
999 4
999 5
Time taken: 8.257 seconds, Fetched: 5 row(s)
hive splict, explode, lateral view, concat_ws的更多相关文章
- hive中的lateral view 与 explode函数的使用
hive中的lateral view 与 explode函数的使用 背景介绍: explode与lateral view在关系型数据库中本身是不该出现的. 因为他的出现本身就是在操作不满足第一范式的数 ...
- hive中,lateral view 与 explode函数
hive中常规处理json数据,array类型json用get_json_object(#,"$.#")这个方法足够了,map类型复合型json就需要通过数据处理才能解析. exp ...
- Hive之侧视图(Lateral View)
Lateral View和UDTF类功能函数一起使用,表中的每一行和UDTF函数输出的每一行进行连接,生成一张新的虚拟表,可以对UDTF产生的记录设置字段名称,新加的字段可以使用在sort by,gr ...
- hive中的 lateral view
lateral view用于和split, explode等UDTF一起使用,它能够将一列数据拆成多行数据,在此基础上可以对拆分后的数据进行聚合. 一个简单的例子,假设我们有一张表pageAds,它有 ...
- hive lateral view 与 explode详解
ref:https://blog.csdn.net/bitcarmanlee/article/details/51926530 1.explode hive wiki对于expolde的解释如下: e ...
- lateral view
原文地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LateralView# lateral view用于和spl ...
- hive之案例分析(grouping sets,lateral view explode, concat_ws)
有这样一组搜索结果数据: 租户,平台, 登录用户, 搜索关键词, 搜索的商品结果List {"tenantcode":"", "platform&qu ...
- Hive之explode和lateral view
Hive之explode 一. explode, 行转列. 1.1. 用于array类型的数据 table_name 表名 array_col 为数组类型的字段 new_col array_col被e ...
- Hive lateral view explode
select 'hello', x from dual lateral view explode(array(1,2,3,4,5)) vt as x 结果是: hello 1 hello 2 ...
随机推荐
- flume-elasticsearch-sink indexName
- C#的ThreadStart 和 Thread
多线程,new Thread(t1);和new Thread(new ThreadStart(t1));有什么区别 没有区别. 前者,是c#的语法.也就是说是编译器帮你改写为第二种形式. 因此你要搞清 ...
- 规避javascript多人开发函数重名问题
命名空间 封闭空间 js模块化mvc(数据层.表现层.控制层) seajs 变量转换成对象的属性 对象化
- Android 建立手机与手表数据同步机制总结
Android Wear 数据同步机制总结 当手机与手表建立蓝牙连接之后.数据就能够通过Google Play Service进行传输. 同步数据对象Data Item DataItem提供手机与手表 ...
- openerp 7.0邮件多用户发送失败问题 解决方法
方法一(推荐): 修改代码/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_mail_server.py #425 line: #mail_ ...
- Oracle11g口令过期的解决
今天发现服务器上的Oracle11g突然登录不上去了,提示ORA-28002错误,说是口令过期. 1. 用DBA账户登录SQL PLUS.我用的是SYS. 2. 系统会提示口令失效,但是会马上让你重置 ...
- 安全删除linux旧内核的方法
我们在用yum升级系统之后,希望往往会为我们保持旧的内核文件,这样以防在出现硬件或者软件冲突的时候我们能够返回到旧的内核文件继续使用,如果我们想要安全的删除旧的内核文件,可以follow下面的方法. ...
- 使用Idea添加PYTHONPATH的一种方案
工作中我们常常需要更改PYTHONPATH,为项目添加一些依赖. 而不同的项目依赖的PYTHONPATH是不一样的,这就导致项目之间的PYTHONPATH发生混乱. 另一方面,有的电脑上PYTHON2 ...
- Quick Touch – 在 iOS 设备运行的 “Touch Bar”
关于 Quick Touch & Touch Bar Touch Bar 其实就是在原来 MBP 的按键区顶部新增了一个长条形的OLED触控屏,提供一些常用的快捷键.(iMessage 选表情 ...
- 消息队列状态:struct msqid_ds
Linux的消息队列(queue)实质上是一个链表, 它有消息队列标识符(queue ID). msgget创建一个新队列或打开一个存在的队列; msgsnd向队列末端添加一条新消息; msgrcv从 ...