我有两张table:
create table a (
`1` array<string>);
create table b (
`1` array<int>);
我想把表a放在表b中(表b是空的):
insert into table b
select * from a;
执行此操作时,出现以下错误:
FAILED: SemanticException [Error 10044]: Line 1:18 Cannot insert into
target table because column number/types are different 'b': Cannot
convert column 0 from array<string> to array<int>.
然而,如果字段仅为类型,则不会出现此错误 string
以及 int
.
有没有一种方法可以对数组进行强制转换?
3条答案
按热度按时间yrdbyhpb1#
有没有一种方法可以对数组进行强制转换?
不容易。如果知道数组的大小,可以手动强制转换数组,但如果不知道,则可能需要使用结构。看看我对这个问题的回答。
另外:我不能对另一个答案进行向下投票,但对于包含多个数组的嵌套选择则失败。
它不强制转换数组元素并重建原始数组,而是强制转换所有元素,然后将其合并到单个数组中。例子:
t1rydlwq2#
使用重新组装阵列
explode()
以及collect_list()
.初始字符串数组示例:
转换数组:
结果:
如果您想在insert+select查询中添加更多的列,那么使用
lateral view [outer]
:muk1a3rh3#
brickhouse震击器比铸造它们并收集它们作为一个列表要快得多。将此jar添加到hdfs位置。
使用下面的链接下载brick house jar