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