huor
发布于

OushuDB与Hive中的列转行处理

OushuDB 中的列转行处理:

# create table t1 (id int,name text);
# insert into t1 (id,name) values (1,'a,b,c'),(2,'d,e,f');
# select id, regexp_split_to_table(name, ',') from t1;
 id | regexp_split_to_table
----+-----------------------
  1 | a
  1 | b
  1 | c
  2 | d
  2 | e
  2 | f
(6 rows)

Hive 中的列转行处理:

create table t2 (id int, name string);
insert into t2 values (1, 'a,b,c'), (2, 'd,e,f');
select id, colAliasName from t2 t lateral view explode(split(t.name,',')) tableAliasName as colAliasName;
+----+--------------+
| id | colaliasname |
+----+--------------+
|  1 | a            |
|  1 | b            |
|  1 | c            |
|  2 | d            |
|  2 | e            |
|  2 | f            |
+----+--------------+
评论
    test