aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/aggr_factory/max_by.sql
blob: 0e7cfaf37fc5c2c3f234c21cc3f1c5dd0c870f29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* syntax version 1 */
/* postgres can not */
$t = AsList(
    AsStruct(1 as key, 200 as value),
    AsStruct(2 as key, 100 as value)
);

$f = AGGREGATION_FACTORY("maxby");

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

$f = AGGREGATION_FACTORY("maxby", 10);

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

use plato;
insert into @a select AsTuple(value, key) as vk from as_table($t);
commit;
select AGGREGATE_BY(vk, $f) from @a;