(
(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" '11291) '('"_id" '"5384d783-d172535-7bb5fcf0-c9da6202") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $20 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $21 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $20)))
  (let $22 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $23 (YtStat '('Id '"Input") '('RecordsCount '"9") '('DataSize '"369") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $24 (YtTable '"Input" $21 $22 $23 '() (Void) (Void) '"/Root/plato"))
  (let $25 '('"key" '"subkey" '"value"))
  (let $26 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $24 $25 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $26 '())))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('"2") '0 '"HashV2"))
(let $9 (DataType 'Int64))
(let $10 (OptionalType $9))
(let $11 (StructType $2 $3 '('"subkey_sum" $10) '('"subkey_sum_ansi" $10) '('"subkey_sum_next" $10) $4))
(let $12 '('('"_logical_id" '12358) '('"_id" '"8b6a450e-ea8a388-9d1d706-80e71636") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($8) (lambda '($27) (block '(
  (let $28 (NarrowSqueezeToDict (ToFlow $27) (lambda '($34 $35 $36) $36) (lambda '($37 $38 $39) (AsStruct '('"key" $37) '('"subkey" $38) '('"value" $39))) '('Auto 'Many)))
  (let $29 (Bool 'true))
  (let $30 (Chopper (OrderedFlatMap $28 (lambda '($40) (OrderedFlatMap (DictPayloads $40) (lambda '($41) (Sort $41 $29 (lambda '($42) (Member $42 '"key"))))))) (lambda '($43) (Member $43 '"value")) (lambda '($44 $45) (AggrNotEquals $44 (Member $45 '"value"))) (lambda '($46 $47) (block '(
    (let $48 (FromFlow $47))
    (let $49 (OptionalType (DataType 'Int32)))
    (let $50 (lambda '($68) (Just (SafeCast $68 $9))))
    (let $51 (Nothing $10))
    (let $52 (Chain1Map $48 (lambda '($63) (block '(
      (let $64 (Member $63 '"subkey"))
      (let $65 (IfPresent (SafeCast $64 $49) $50 $51))
      (let $66 '('Sum0 $65))
      (let $67 (AsStruct $66 '('"key" (Member $63 '"key")) '('"subkey" $64) '('"value" (Member $63 '"value"))))
      (return '($67 (AsStruct $66)))
    ))) (lambda '($69 $70) (block '(
      (let $71 (Member $69 '"subkey"))
      (let $72 (IfPresent (SafeCast $71 $49) $50 $51))
      (let $73 '('Sum0 (AggrAdd $72 (Member (Nth $70 '1) 'Sum0))))
      (let $74 (AsStruct $73 '('"key" (Member $69 '"key")) '('"subkey" $71) '('"value" (Member $69 '"value"))))
      (return '($74 (AsStruct $73)))
    )))))
    (let $53 (StructType '('Sum0 $10) $2 $3 $4))
    (let $54 (ListType $53))
    (let $55 (VariantType (StructType '('group $54) '('singleRow $53))))
    (let $56 (Condense1 $52 (lambda '($75) (block '(
      (let $76 (Nth $75 '0))
      (let $77 (Variant $76 'singleRow $55))
      (return '((Member $76 '"key") $77))
    ))) (lambda '($78 $79) (AggrNotEquals (Member (Nth $78 '0) '"key") (Nth $79 '0))) (lambda '($80 $81) (block '(
      (let $82 (Nth $80 '0))
      (let $83 (Visit (Nth $81 '1) 'group (lambda '($84) (Variant (Insert $84 $82) 'group $55)) 'singleRow (lambda '($85) (Variant (AsList $85 $82) 'group $55))))
      (return '((Nth $81 '0) $83))
    )))))
    (let $57 (QueueCreate $53 (Uint64 '"3") (Uint64 '0) (DependsOn $48)))
    (let $58 (Uint64 '1))
    (let $59 (Uint64 '"2"))
    (let $60 (lambda '($99) $99))
    (let $61 (lambda '($100 $101) (block '(
      (let $102 (IfPresent (SafeCast (Member $100 '"subkey") $49) $50 $51))
      (return (AggrAdd $102 $101))
    ))))
    (let $62 (Chain1Map (ToFlow (PreserveStream (OrderedFlatMap $56 (lambda '($86) (Visit (Nth $86 '1) 'group (lambda '($87) (IfPresent (Last $87) (lambda '($88) (OrderedMap (Collect (Map $87 (lambda '($89) (AsStruct '('"key" (Member $89 '"key")) '('"subkey" (Member $89 '"subkey")) '('"value" (Member $89 '"value")))))) (lambda '($90) (AsStruct '('Sum0 (Member $88 'Sum0)) '('"key" (Member $90 '"key")) '('"subkey" (Member $90 '"subkey")) '('"value" (Member $90 '"value")))))) (List $54))) 'singleRow (lambda '($91) (AsList $91))))) $57 $58)) (lambda '($92) (block '(
      (let $93 (Member $92 '"subkey"))
      (let $94 (IfPresent (SafeCast $93 $49) $50 $51))
      (let $95 '('Sum1 $94))
      (let $96 (QueueRange $57 $58 $59 (DependsOn $92)))
      (let $97 (Fold (FlatMap $96 $60) $94 $61))
      (let $98 (AsStruct '('Sum0 (Member $92 'Sum0)) $95 '('Sum2 $97) '('"key" (Member $92 '"key")) '('"subkey" $93) '('"value" (Member $92 '"value"))))
      (return '($98 (AsStruct $95 '('Sum2 $94))))
    ))) (lambda '($103 $104) (block '(
      (let $105 (Member $103 '"subkey"))
      (let $106 (IfPresent (SafeCast $105 $49) $50 $51))
      (let $107 (Nth $104 '1))
      (let $108 '('Sum1 (AggrAdd $106 (Member $107 'Sum1))))
      (let $109 (QueueRange $57 $58 $59 (DependsOn $103)))
      (let $110 (AggrAdd $106 (Member $107 'Sum2)))
      (let $111 (Fold (FlatMap $109 $60) $110 $61))
      (let $112 (AsStruct '('Sum0 (Member $103 'Sum0)) $108 '('Sum2 $111) '('"key" (Member $103 '"key")) '('"subkey" $105) '('"value" (Member $103 '"value"))))
      (return '($112 (AsStruct $108 '('Sum2 $110))))
    )))))
    (return (OrderedMap $62 (lambda '($113) (Nth $113 '0))))
  )))))
  (let $31 '($29 $29 $29))
  (let $32 (Sort (Map $30 (lambda '($114) (AsStruct '('"key" (Member $114 '"key")) '('"subkey" (Member $114 '"subkey")) '('"subkey_sum" (Member $114 'Sum1)) '('"subkey_sum_ansi" (Member $114 'Sum0)) '('"subkey_sum_next" (Member $114 'Sum2)) '('"value" (Member $114 '"value"))))) $31 (lambda '($115) '((Member $115 '"value") (Member $115 '"key") (Member $115 '"subkey")))))
  (let $33 (lambda '($116) (Member $116 '"key") (Member $116 '"subkey") (Member $116 '"subkey_sum") (Member $116 '"subkey_sum_ansi") (Member $116 '"subkey_sum_next") (Member $116 '"value")))
  (return (FromFlow (ExpandMap $32 $33)))
))) $12))
(let $14 '('('"5" '"Asc") '('0 '"Asc") '('1 '"Asc")))
(let $15 (DqCnMerge (TDqOutput $13 '0) $14))
(let $16 (DqPhyStage '($15) (lambda '($117) (FromFlow (NarrowMap (ToFlow $117) (lambda '($118 $119 $120 $121 $122 $123) (AsStruct '('"key" $118) '('"subkey" $119) '('"subkey_sum" $120) '('"subkey_sum_ansi" $121) '('"subkey_sum_next" $122) '('"value" $123)))))) '('('"_logical_id" '12370) '('"_id" '"83184159-1de5de4a-d17a2d9a-c4e0392a"))))
(let $17 '($7 $13 $16))
(let $18 '('"value" '"key" '"subkey" '"subkey_sum_ansi" '"subkey_sum" '"subkey_sum_next"))
(let $19 (DqCnResult (TDqOutput $16 '0) $18))
(return (KqpPhysicalQuery '((KqpPhysicalTx $17 '($19) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
