(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('"value" $1))
(let $5 (StructType $2 $3 $4))
(let $6 '('('"_logical_id" '5609) '('"_id" '"9ca3f050-deb262d8-5c0ad7d-cfc19a46") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $13 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $14 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $13)))
  (let $15 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $16 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $17 (YtTable '"Input" $14 $15 $16 '() (Void) (Void) '"/Root/plato"))
  (let $18 '('"key" '"subkey" '"value"))
  (let $19 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $17 $18 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $19 '())))
))) $6))
(let $8 (DqCnUnionAll (TDqOutput $7 '0)))
(let $9 (ListType (DataType 'Uint64)))
(let $10 (ListType $1))
(let $11 (DqPhyStage '($8) (lambda '($20) (block '(
  (let $21 (Chain1Map (NarrowMap (WideSort (ToFlow $20) '('('0 (Bool 'true)))) (lambda '($26 $27 $28) (AsStruct '('"key" $26) '('"subkey" $27) '('"value" $28)))) (lambda '($29) (block '(
    (let $30 (Uint64 '1))
    (let $31 '('MultiAggregateBy0 (AsList $30 $30)))
    (let $32 (Member $29 '"subkey"))
    (let $33 (Member $29 '"value"))
    (let $34 '('MultiAggregateBy1 (AsList $32 $33)))
    (let $35 (AsStruct $31 $34 '('"key" (Member $29 '"key")) '('"subkey" $32) '('"value" $33)))
    (return '($35 (AsStruct $31 $34)))
  ))) (lambda '($36 $37) (block '(
    (let $38 (Member $36 '"subkey"))
    (let $39 (Member $36 '"value"))
    (let $40 (AsList $38 $39))
    (let $41 (Nth $37 '1))
    (let $42 '('MultiAggregateBy0 (Map (Collect (Zip $40 (Member $41 'MultiAggregateBy0))) (lambda '($45) (Inc (Nth $45 '1))))))
    (let $43 '('MultiAggregateBy1 (Map (Collect (Zip $40 (Member $41 'MultiAggregateBy1))) (lambda '($46) (AggrMax (Nth $46 '0) (Nth $46 '1))))))
    (let $44 (AsStruct $42 $43 '('"key" (Member $36 '"key")) '('"subkey" $38) '('"value" $39)))
    (return '($44 (AsStruct $42 $43)))
  )))))
  (let $22 (StructType '('MultiAggregateBy0 $9) '('MultiAggregateBy1 $10) $2 $3 $4))
  (let $23 (ListType $22))
  (let $24 (VariantType (StructType '('group $23) '('singleRow $22))))
  (let $25 (Condense1 $21 (lambda '($47) (block '(
    (let $48 (Nth $47 '0))
    (let $49 (Variant $48 'singleRow $24))
    (return '((Member $48 '"key") $49))
  ))) (lambda '($50 $51) (AggrNotEquals (Member (Nth $50 '0) '"key") (Nth $51 '0))) (lambda '($52 $53) (block '(
    (let $54 (Nth $52 '0))
    (let $55 (Visit (Nth $53 '1) 'group (lambda '($56) (Variant (Insert $56 $54) 'group $24)) 'singleRow (lambda '($57) (Variant (AsList $57 $54) 'group $24))))
    (return '((Nth $53 '0) $55))
  )))))
  (return (FromFlow (Map (OrderedFlatMap $25 (lambda '($58) (block '(
    (let $59 (Visit (Nth $58 '1) 'group (lambda '($60) (IfPresent (Last $60) (lambda '($61) (OrderedMap (Collect (Map $60 (lambda '($62) (AsStruct '('"key" (Member $62 '"key")) '('"subkey" (Member $62 '"subkey")) '('"value" (Member $62 '"value")))))) (lambda '($63) (AsStruct '('MultiAggregateBy0 (Member $61 'MultiAggregateBy0)) '('MultiAggregateBy1 (Member $61 'MultiAggregateBy1)) '('"key" (Member $63 '"key")) '('"subkey" (Member $63 '"subkey")) '('"value" (Member $63 '"value")))))) (List $23))) 'singleRow (lambda '($64) (AsList $64))))
    (return (Map $59 (lambda '($65) (AsStruct '('MultiAggregateBy0 (Member $65 'MultiAggregateBy0)) '('MultiAggregateBy1 (Member $65 'MultiAggregateBy1))))))
  )))) (lambda '($66) (AsStruct '('"column0" (Member $66 'MultiAggregateBy0)) '('"column1" (Member $66 'MultiAggregateBy1)))))))
))) '('('"_logical_id" '6017) '('"_id" '"9e909def-87ac7bcc-5422aa2f-1b19e5a"))))
(let $12 (DqCnResult (TDqOutput $11 '0) '('"column0" '"column1")))
(return (KqpPhysicalQuery '((KqpPhysicalTx '($7 $11) '($12) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"column0" $9) '('"column1" $10))) '0 '0)) '('('"type" '"query"))))
)
