aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/s-expressions/suites/Scheme/PartitionByValueAndMap.yql
blob: bc7222e7e16243c19c23ca6a60c47ea434d61065 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(
(let x (Read! world (DataSource 'yt 'plato) (Key '('table (String 'Input))) '('key 'subkey 'value) '()))
(let world (Left! x))
(let yt.plato.Input (Right! x))
(let select@0:0_input yt.plato.Input)
(let output (block '(
  (let select@0:0_output (Map select@0:0_input (lambda '(row) (block '(
    (let res (Struct))
    (let res (AddMember res 'foo (Member row 'value)))
    (let res (AddMember res 'bar (Member row 'key)))
    (return res)
)
))))
  (let select@0:0_output (PartitionByKey select@0:0_output (lambda '(row) (block '(
    (let res (Member row 'foo))
    (return res)
)
)) (Void) (Void) (lambda '(stream) (FlatMap stream (lambda '(pair) (block '(
    (let key (Nth pair '0))
    (let group (Collect (Nth pair '1)))
    (let res (FlatMap group (lambda '(row) (block '(
      (let res (Struct))
      (let res (AddMember res 'subkey (ToString (Length group))))
      (let res (AddMember res 'value (Member row 'bar)))
      (let res (AddMember res 'key (Member row 'foo)))
      (let res (AsList res))
      (return res)
)
))))
    (return res)
)))))
))
  (return select@0:0_output)
)
))
(let output (Sort output (Bool 'true) (lambda '(x) (Concat (Member x 'subkey) (Member x 'value)))))
(let sink (DataSink 'result))
(let world (Write! world sink (Key) output '()))
(let world (Commit! world sink))
(return world)
)