Convert hive columns to rows (collect_set ())

Source: Internet
Author: User
I. Problems

How does hive

A B 1
A B 2
A B 3
C d 4
C d 5
C d 6

Changed:

A B 1, 2, 3
C d 4, 5, 6


Ii. Data

Test.txt

A B 1
A B 2
A B 3
C d 4
C d 5
C d 6


Iii. Answer

1. Create a table

Drop table tmp_jiangzl_test;
Create Table tmp_jiangzl_test
(
Col1 string,
Col2 string,
Col3 string
)
Row format delimited fields terminated by '\ t'
Stored as textfile;


Load data local inpath '/home/jiangzl/Shell/test.txt' into Table tmp_jiangzl_test;

2. Processing

Select col1, col2, concat_ws (',', collect_set (col3 ))
From tmp_jiangzl_test
Group by col1, col2;

4. About us


Author: Jiang Zhonglian, one of the pioneers of data

QQ: 248087140

Motto:

You are awesome in your field,

And with a group of white ones,

Others will respect you from the heart.

-- Click to join us.


Group blog address: http://my.oschina.net/dataRunner/blog/295960

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.