Athena 相当于 Presto 在数组列上的 find_first_index

问题描述 投票:0回答:1

find_first_index(数组(E), 函数(T, 布尔值)) → BIGINT#

返回数组第一个元素的索引,该元素对于 function(T,boolean) 返回 true。 如果不存在这样的元素,则返回 NULL。

AWS athena 中不存在此记录的 presto 函数。有没有好的替代方案?

sql amazon-web-services amazon-athena presto trino
1个回答
0
投票

Amazon Athena 基于 Presto 0.217(v.2 引擎 - docs)或 Trino(v.3 引擎 - docs),并且

find_first_index
是在 Presto 0.280 中引入的,在这两种情况下
find_first_index
不可用,但您可以通过组合
array_position
transform
来模拟它(这可能不会那么有效)。沿着这些思路:

select array_position(
      trasnform(array_col, el -> if(some_condition, 1, 0),
      1
   )) 
from ...
© www.soinside.com 2019 - 2024. All rights reserved.