【问题标题】:AWS Athena - Apply filter and then compute percentilesAWS Athena - 应用过滤器然后计算百分位数
【发布时间】:2018-06-29 08:27:06
【问题描述】:

我正在使用 AWS Athena 来计算一些指标。我有一个这样的数据集:

sessionumber 0 10 -1 10 2 -10 10

我正在尝试计算该值的百分位数,但仅针对有效值的子集。一个有效的值是 sessionnumber > 1 所以我试过了:

with testfun AS 
    (SELECT filter(array_agg(sessionnumber), x -> x >= 1) as validvalues 
     FROM "mydate")

SELECT (percentiles(validvalues, 0.25) FROM testfun

但我收到以下错误:

SYNTAX_ERROR: line 17:10: Unexpected parameters (array(integer), double) for function approx_percentile. Expected: approx_percentile(bigint, double) , approx_percentile(bigint, bigint, double) , approx_percentile(bigint, bigint, double, double) , approx_percentile(bigint, array(double)) , approx_percentile(bigint, bigint, array(double)) , approx_percentile(double, double) , approx_percentile(double, bigint, double, double) , approx_percentile(double, bigint, double) , approx_percentile(double, array(double)) , approx_percentile(double, bigint, array(double)) , approx_percentile(real, double) , approx_percentile(real, bigint, double, double) , approx_percentile(real, bigint, double) , approx_percentile(real, array(double)) , approx_percentile(real, bigint, array(double))

我理解我的错误,但我找不到使用 AWS Athena / PrestoDB 进行修复的方法。甚至有可能做这样的事情吗?

【问题讨论】:

    标签: amazon-web-services amazon-athena presto


    【解决方案1】:

    我找到了解决方法,在这里分享一下:

    WITH validValues AS 
    (SELECT approx_percentile(sessionnumber, ARRAY[0.25,0.50,0.75,0.95, 0.99]) as percentiles from (SELECT sessionnumber from "20180407" where sessionnumber >= 1))
    
    SELECT percentiles FROM testfun, validValues 
    

    【讨论】:

      猜你喜欢
      • 2022-07-21
      • 2016-07-28
      • 2021-01-13
      • 2011-12-29
      • 2013-06-20
      • 1970-01-01
      • 2017-08-29
      • 2012-10-28
      • 2021-02-26
      相关资源
      最近更新 更多