[英]how to get slice of an array in AWS Athena?
I have an array of unknown length in AWS Athena.我在 AWS Athena 中有一个长度未知的数组。 I want to get all elements expect for the first one and concatenate into a string.
我想获取第一个元素所期望的所有元素并连接成一个字符串。
I can do with a known length, but I don't see how for unknown length.我可以使用已知长度,但我不知道如何使用未知长度。 In this example:
在这个例子中:
select this_arr, second, array_join(myslice, ' ') as myslice_joined
from
(select this_arr, element_at(this_arr, 2) as second, slice(this_arr, 2, 4) as myslice
from
(select array ['one','two','three', 'four'] as this_arr));
What I want is myslice_joined.我想要的是 myslice_joined。 I could use slice because I knew it had four elements, but what if it's more?
我可以使用 slice 因为我知道它有四个元素,但如果它更多呢? Slice does not take a -1 as the last element, as you can do elsewhere.
Slice 不像其他地方那样将 -1 作为最后一个元素。
You can use cardinality
to determine the array length:您可以使用
cardinality
来确定数组长度:
select this_arr,
second,
array_join(myslice, ' ') as myslice_joined
from (
select this_arr,
element_at(this_arr, 2) as second,
slice(this_arr, 2, cardinality(this_arr)) as myslice
from (
select array [ 'one', 'two', 'three', 'four' ] as this_arr
)
);
Output: Output:
this_arr ![]() |
second![]() |
myslice_joined ![]() |
---|---|---|
[one, two, three, four] ![]() |
two![]() |
two three four![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.