Presto-减少结构数组

时间:2018-06-27 02:24:32

标签: amazon-athena presto

我正在尝试减少一组复杂类型,但是我遇到了语法错误(也许甚至不支持此语法?)。

styles

复杂类型在表中定义为SYNTAX_ERROR: line 2:1: Unexpected parameters (array(row(count double,name varchar)), integer, com.facebook.presto.sql.analyzer.TypeSignatureProvider@16881774, com.facebook.presto.sql.analyzer.TypeSignatureProvider@1718b83d) for function reduce. Expected: reduce(array(T), S, function(S,T,S), function(S,R)) T, S, R 。我尝试选择counters array<struct<count:double,name:string>>reduce(counters, 0, (state, counter) -> state + counter.count , s -> s),但是都行不通。

1 个答案:

答案 0 :(得分:1)

您的方法是正确的(使用Presto 0.205测试):

presto:default> desc t;
  Column  |                  Type                  | Extra | Comment
----------+----------------------------------------+-------+---------
 counters | array(row(count double, name varchar)) |       |


presto:default> select * from t;
                  counters
--------------------------------------------
 [{count=1.0, name=a}, {count=2.0, name=b}]

presto:default> select reduce(
        counters, 0,
        (state, counter) -> state + counter.count,
        state -> state) from t;
 _col0
-------
   3.0
(1 row)

您标记了问题prestodbamazon-athena。如果您在雅典娜上尝试此操作,请记住Athena is based on Presto 0.172(于2017年4月发布)