aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/aggr_factory/avg_if.sql
blob: 7fc60b5b1cecdc00166be46d54f3e2e0f922c23c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* syntax version 1 */
/* postgres can not */
$t = AsList(AsStruct(1 as a),AsStruct(2 as a));
$f = AGGREGATION_FACTORY("avg_if");

select Yql::Aggregate($t, AsTuple(), AsTuple(AsTuple(AsAtom("res"), $f(
    ListItemType(TypeOf($t)), ($z)->{return AsTuple($z.a,$z.a<2)}))));

use plato;
insert into @a select AsTuple(a,a<2) as aa from as_table($t);
commit;
select AGGREGATE_BY(aa,$f) from @a;