9

I'm trying to append one variable from several tables together (aka row-bind, concatenate) to make one longer table with a single column in Hive. I think this is possible using UNION ALL based on this question ( HiveQL UNION ALL ), but I'm not sure an efficient way to accomplish this?

The pseudocode would look something like this:

CREATE TABLE tmp_combined AS
SELECT b.var1 FROM tmp_table1 b
UNION ALL
SELECT c.var1 FROM tmp_table2 c
UNION ALL
SELECT d.var1 FROM tmp_table3 d
UNION ALL
SELECT e.var1 FROM tmp_table4 e
UNION ALL
SELECT f.var1 FROM tmp_table5 f
UNION ALL
SELECT g.var1 FROM tmp_table6 g
UNION ALL
SELECT h.var1 FROM tmp_table7 h;

Any help is appreciated!

4

3 回答 3

34

尝试以下编码...

Select * into tmp_combined  from 
(
    SELECT b.var1 FROM tmp_table1 b
    UNION ALL
    SELECT c.var1 FROM tmp_table2 c
    UNION ALL
    SELECT d.var1 FROM tmp_table3 d
    UNION ALL
    SELECT e.var1 FROM tmp_table4 e
    UNION ALL
    SELECT f.var1 FROM tmp_table5 f
    UNION ALL
    SELECT g.var1 FROM tmp_table6 g
    UNION ALL
    SELECT h.var1 FROM tmp_table7 h
) CombinedTable 

与语句一起使用:set hive.exec.parallel=true

这将同时执行不同的选择,否则它将是一步一步的。

于 2013-04-24T12:16:49.890 回答
3

我会说这是进行行绑定的既简单又有效的方法,至少,这就是我将在我的代码中使用的方法。顺便说一句,如果您直接输入伪代码,可能会导致一些语法错误,您可以尝试:

create table join_table as
select * from
(select ...
join all
select
join all
select...) tmp;
于 2013-07-19T20:43:19.567 回答
2

我做了同样的概念,但对于不同的表employeelocation我相信这可能会对你有所帮助:

DATA:Table_e-employee
empid empname
13  Josan
8   Alex
3   Ram
17  Babu
25  John

Table_l-location
empid emplocation
13  San Jose
8   Los Angeles
3   Pune,IN
17  Chennai,IN
39  Banglore,IN

hive> SELECT e.empid AS a ,e.empname AS b FROM employee e 
UNION ALL 
SELECT l.empid AS a,l.emplocation AS b FROM location l;

带有别名a和 的输出b

13  San Jose
8   Los Angeles
3   Pune,IN
17  Chennai,IN
39  Banglore,IN
13  Josan
8   Alex
3   Ram
17  Babu
25  John
于 2015-05-29T03:47:57.407 回答