【问题标题】:Presto - reducing an array of structsPresto - 减少结构数组
【发布时间】:2018-12-05 19:30:01
【问题描述】:

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

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)reduce(counters, 0, (state, counter) -> state + counter['count'] , s -> s),但都不起作用。

【问题讨论】:

    标签: amazon-athena presto


    【解决方案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 上尝试此功能,请记住 Athena is based on Presto 0.172(2017 年 4 月发布)

    【讨论】:

    • 我可以用同样的方式连接字符串,而不是对整数求和吗?一旦我将reduce的输入函数的返回值更改为字符串,它就会给我Unexpected parameters错误
    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 2021-03-10
    • 2020-04-12
    • 2018-10-23
    • 2022-01-20
    • 2017-07-17
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多