impala,hive行转列

Hive

For Hive, I use collect_set() + concat_ws() from https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF.
But if you want to remove duplicated elements, write your own UDF should be the only choice till now.

Impala

Impala also has a group_concat() but different from mysql

group_concat(string s [, string sep])
Purpose: Returns a single string representing the argument value concatenated together for each row of the result set. If the optional separator string is specified, the separator is added between each pair of concatenated values.
Return type: string

Usage notes: concat() and concat_ws() are appropriate for concatenating the values of multiple columns within the same row, while group_concat() joins together values from different rows.

By default, returns a single string covering the whole result set. To include other columns or values in the result set, or to produce multiple concatenated strings for subsets of rows, include a GROUP BY clause in the query.

group_concat(string s [, string sep]) 和分组函数配合使用,group_concat(字段, 分隔符) ,下面例子:

Rows to Columns

Columns to Rows

Comma Separated String to Rows

UNION [ALL] SELECT seems to be a solution.

MySQL

And…A Stored Procedure or a UDF?

Hive

Lateral View is AWESOME!
I tried explode() which can split an array into rows and before that split() which split string into array.

Presto

Not figured out.

Impala

Not figured out.

Columns to Rows

你可能感兴趣的:(hive)