(
(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" '5807) '('"_id" '"8b90cf1-2af1354b-95b6509a-feb7caf4") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $14 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $15 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $14)))
  (let $16 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $17 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $18 (YtTable '"Input" $15 $16 $17 '() (Void) (Void) '"/Root/plato"))
  (let $19 '('"key" '"subkey" '"value"))
  (let $20 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $18 $19 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $20 '())))
))) $6))
(let $8 (DqCnUnionAll (TDqOutput $7 '0)))
(let $9 (DataType 'Uint64))
(let $10 (TupleType $9 $9))
(let $11 (TupleType $1 $1))
(let $12 (DqPhyStage '($8) (lambda '($21) (block '(
  (let $22 (Chain1Map (NarrowMap (WideSort (ToFlow $21) '('('0 (Bool 'true)))) (lambda '($27 $28 $29) (AsStruct '('"key" $27) '('"subkey" $28) '('"value" $29)))) (lambda '($30) (block '(
    (let $31 (Uint64 '1))
    (let $32 '('MultiAggregateBy0 '($31 $31)))
    (let $33 (Member $30 '"subkey"))
    (let $34 (Member $30 '"value"))
    (let $35 '('MultiAggregateBy1 '($33 $34)))
    (let $36 (AsStruct $32 $35 '('"key" (Member $30 '"key")) '('"subkey" $33) '('"value" $34)))
    (return '($36 (AsStruct $32 $35)))
  ))) (lambda '($37 $38) (block '(
    (let $39 (Nth $38 '1))
    (let $40 (Member $39 'MultiAggregateBy0))
    (let $41 '('MultiAggregateBy0 '((Inc (Nth $40 '0)) (Inc (Nth $40 '1)))))
    (let $42 (Member $37 '"subkey"))
    (let $43 (Member $39 'MultiAggregateBy1))
    (let $44 (Member $37 '"value"))
    (let $45 '('MultiAggregateBy1 '((AggrMax $42 (Nth $43 '0)) (AggrMax $44 (Nth $43 '1)))))
    (let $46 (AsStruct $41 $45 '('"key" (Member $37 '"key")) '('"subkey" $42) '('"value" $44)))
    (return '($46 (AsStruct $41 $45)))
  )))))
  (let $23 (StructType '('MultiAggregateBy0 $10) '('MultiAggregateBy1 $11) $2 $3 $4))
  (let $24 (ListType $23))
  (let $25 (VariantType (StructType '('group $24) '('singleRow $23))))
  (let $26 (Condense1 $22 (lambda '($47) (block '(
    (let $48 (Nth $47 '0))
    (let $49 (Variant $48 'singleRow $25))
    (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 $25)) 'singleRow (lambda '($57) (Variant (AsList $57 $54) 'group $25))))
    (return '((Nth $53 '0) $55))
  )))))
  (return (FromFlow (Map (OrderedFlatMap $26 (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 $24))) '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" '6215) '('"_id" '"895d38d5-d1a02f87-68fa6fc3-75631ea3"))))
(let $13 (DqCnResult (TDqOutput $12 '0) '('"column0" '"column1")))
(return (KqpPhysicalQuery '((KqpPhysicalTx '($7 $12) '($13) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"column0" $10) '('"column1" $11))) '0 '0)) '('('"type" '"query"))))
)
