在hue中操作hive

来源:互联网 发布:电脑美术软件 编辑:程序博客网 时间:2024/06/06 19:34

创建新表

建表语句如下:

CREATE TABLE IF NOT EXISTS user_collection_9(  user_id string ,  seller_id string ,  product_id string , time string)  ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ; 

hue中向hive导入数据

首先,在文件浏览器中,将你创建表对应的文本导进来,如下图所示:
这里写图片描述

使用如下操作语句将文本数据导入到hive中。
这里写图片描述

hive中将选择的几张表数据导入新表

由于我的三张表结构是一样的,所以直接使用的是下面的操作语句。

CREATE TABLE user_port as SELECT * FROM user_collection_7 UNION ALL select * FROM user_collection_8 UNION all select * FROM user_collection_9

hive中的连接函数

在hive中,group_concat不能使用,使用concat_ws.

CREATE table user_collection_port as select ip as user_id,concat_ws(' ',collect_set(product_id)) as product FROM user_collection_taobao_allall GROUP BY ip having count(*)>2;

使用该函数操作的结果会把每个用户对应的数据连接到一起了,中间使用空格隔开,如下图所示:
这里写图片描述

hue中将hive中的数据导出到本地

下表结构跟上图一样,所以两列直接用了制表符作为分隔符,使用如下语句,你就会发现在“/user/qianyang/”目录下,存在

insert overwrite  directory '/user/qianyang/' row format delimited fields terminated by '\t' select * from user_789collection;

这里写图片描述

可以在线浏览一些这个数据。
这里写图片描述

导出到windows

按照下图操作,便可将该表数据下载到本地。
这里写图片描述

原创粉丝点击