gpt4 book ai didi

sql - Hive - 在 JOIN 条件下爆炸

转载 作者:可可西里 更新时间:2023-11-01 16:24:47 24 4
gpt4 key购买 nike

我想在连接条件下对列进行爆炸。

select
t1.a,t2.b, t2.c
from table1 AS t1
join (select b,LATERAL VIEW explode(ABCD) AS c from person) AS t2 ON (t1.c=t2.c)

但是,这个查询失败了。我怀疑子查询没有按预期工作。在子查询中,我选择了两列,一列是b列,另一列是c列,这是一个爆炸。

这样子查询的写法对吗?如果错了,我该如何实现。

错误:

Error while compiling statement: FAILED: SemanticException Cannot do equality join on different types: string and map<bigint,array<string>>

最佳答案

CREATE TABLE people(b int,abcd array<String> ); 

INSERT INTO people SELECT 1, ARRAY("bob", "alice", "tom") from dummy limit 1;
INSERT INTO people SELECT 2, ARRAY("john", "mike", "jack") from dummy limit 1;

create table table1(name string, salary int);
insert into table1 values("bob",1000);
insert into table1 values("alice",500);

hive> select b,c from people LATERAL VIEW explode(ABCD) ep AS c;
OK
1 bob
1 alice
1 tom
2 john
2 mike
2 jack


hive> select
t1.salary,t2.b, t2.c
from table1 AS t1
join (select b,c from people LATERAL VIEW explode(ABCD) ep AS c) AS t2 ON (t1.name=t2.c)

OK
1000 1 bob
500 1 alice

关于sql - Hive - 在 JOIN 条件下爆炸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41562824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com