(
(let $1 (DataType 'String))
(let $2 '('"value" $1))
(let $3 (StructType '('"key" $1) '('"subkey" $1) $2))
(let $4 '('('"_logical_id" '13744) '('"_id" '"137b63c5-f365da-2e80a41e-c90c5efa") '('"_wide_channels" $3)))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $19 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $20 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $19)))
  (let $21 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $22 (YtStat '('Id '"Input") '('RecordsCount '"30") '('DataSize '"1170") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $23 (YtTable '"Input" $20 $21 $22 '() (Void) (Void) '"/Root/plato"))
  (let $24 '('"key" '"subkey" '"value"))
  (let $25 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $23 $24 (Void) (Void))) '()))))
  (return (FromFlow (WideFilter (DqReadWideWrap $25 '()) (lambda '($26 $27 $28) (== $26 (String '1))))))
))) $4))
(let $6 (DqCnHashShuffle (TDqOutput $5 '0) '('0) '0 '"HashV2"))
(let $7 (ListType $1))
(let $8 (DataType 'Uint64))
(let $9 (OptionalType $8))
(let $10 '"agglist_distinct1")
(let $11 (StructType '('"agglist2" $7) '($10 $7) '('"count1" $8) '('"sum1" $9) '('"sum2" $9) $2))
(let $12 '('('"_logical_id" '15038) '('"_id" '"26c8f2d1-1c6fd2ed-9e08206c-3803043a") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($6) (lambda '($29) (block '(
  (let $30 (NarrowSqueezeToDict (ToFlow $29) (lambda '($35 $36 $37) $35) (lambda '($38 $39 $40) (AsStruct '('"key" $38) '('"subkey" $39) '('"value" $40))) '('Auto 'Many)))
  (let $31 (Bool 'true))
  (let $32 (Chopper (OrderedFlatMap $30 (lambda '($41) (OrderedFlatMap (DictPayloads $41) (lambda '($42) (Sort $42 $31 (lambda '($43) (Member $43 '"value"))))))) (lambda '($44) (Member $44 '"key")) (lambda '($45 $46) (AggrNotEquals $45 (Member $46 '"key"))) (lambda '($47 $48) (block '(
    (let $49 (FromFlow $48))
    (let $50 (Uint64 '"5"))
    (let $51 (QueueCreate $3 (Uint64 '"7") $50 (DependsOn $49)))
    (let $52 (Uint64 '0))
    (let $53 (Uint64 '"3"))
    (let $54 (lambda '($91) $91))
    (let $55 (lambda '($92) (AsList (Member $92 '"subkey"))))
    (let $56 (lambda '($93 $94) (Insert $94 (Member $93 '"subkey"))))
    (let $57 (List $7))
    (let $58 (lambda '($95) (block '(
      (let $96 (DataType 'Uint32))
      (let $97 (TupleType (TupleType $1 $96) (StructType) $1))
      (let $98 (ResourceType '"Set.SetResource.String"))
      (let $99 '($98))
      (let $100 '($1))
      (let $101 (CallableType '() $99 $100 '($96)))
      (let $102 '('('"strict")))
      (let $103 (Udf '"Set.Create" (Void) $97 '"" $101 (VoidType) '"" $102))
      (let $104 (DependsOn (Uint32 '1)))
      (return (NamedApply $103 '((Member $95 '"subkey") (Uint32 '0)) (AsStruct) $104))
    ))))
    (let $59 (lambda '($105 $106) (block '(
      (let $107 (TupleType (TupleType (ResourceType '"Set.SetResource.String") $1) (StructType) $1))
      (let $108 (CallableType '() '((ResourceType '"Set.SetResource.String")) '((ResourceType '"Set.SetResource.String")) '($1)))
      (let $109 (Udf '"Set.AddValue" (Void) $107 '"" $108 (VoidType) '"" '('('"strict"))))
      (return (NamedApply $109 '($106 (Member $105 '"subkey")) (AsStruct) (DependsOn (Uint32 '1))))
    ))))
    (let $60 (lambda '($110) (block '(
      (let $111 (TupleType (TupleType (ResourceType '"Set.SetResource.String")) (StructType) $1))
      (let $112 (CallableType '() '($7) '((ResourceType '"Set.SetResource.String"))))
      (let $113 (Udf '"Set.GetResult" (Void) $111 '"" $112 (VoidType) '"" '('('"strict"))))
      (return (Apply $113 $110))
    ))))
    (let $61 (lambda '($114) (Uint64 '1)))
    (let $62 (lambda '($115 $116) (Inc $116)))
    (let $63 (lambda '($117) (block '(
      (let $118 (OptionalType (DataType 'Uint32)))
      (return (SafeCast (Unwrap (SafeCast (Member $117 '"subkey") $118)) $8))
    ))))
    (let $64 (lambda '($119 $120) (AggrAdd (SafeCast (Unwrap (SafeCast (Member $119 '"subkey") (OptionalType (DataType 'Uint32)))) $8) $120)))
    (let $65 (Nothing $9))
    (let $66 (lambda '($121) (block '(
      (let $122 (lambda '($123) (Just (SafeCast $123 $8))))
      (return (IfPresent (SafeCast (Member $121 '"subkey") (OptionalType (DataType 'Uint32))) $122 $65))
    ))))
    (let $67 (lambda '($124 $125) (block '(
      (let $126 (IfPresent (SafeCast (Member $124 '"subkey") (OptionalType (DataType 'Uint32))) (lambda '($123) (Just (SafeCast $123 $8))) $65))
      (return (AggrAdd $126 $125))
    ))))
    (let $68 (Chain1Map (ToFlow (PreserveStream $49 $51 $52)) (lambda '($69) (block '(
      (let $70 (DependsOn $69))
      (let $71 (QueueRange $51 $53 $50 $70))
      (let $72 (FlatMap $71 $54))
      (let $73 (Fold1 $72 $55 $56))
      (let $74 (QueueRange $51 $52 $53 $70))
      (let $75 (FlatMap $74 $54))
      (let $76 (DataType 'Uint32))
      (let $77 (ResourceType '"Set.SetResource.String"))
      (let $78 '($77))
      (let $79 '($1))
      (let $80 '('('"strict")))
      (let $81 (DependsOn (Uint32 '1)))
      (let $82 (Fold1 $75 $58 $59))
      (let $83 (IfPresent $82 $60 $57))
      (let $84 (Fold1 $75 $61 $62))
      (let $85 (OptionalType $76))
      (let $86 (Fold1 $75 $63 $64))
      (let $87 (lambda '($123) (Just (SafeCast $123 $8))))
      (let $88 (Fold1 $72 $66 $67))
      (let $89 (AsStruct '('AggregateList0 (Coalesce $73 $57)) '('AggregateListDistinct0 $83) '('Count0 (Coalesce $84 $52)) '('Sum0 $86) '('Sum1 (Coalesce $88 $65)) '('"key" (Member $69 '"key")) '('"subkey" (Member $69 '"subkey")) '('"value" (Member $69 '"value"))))
      (let $90 (AsStruct '('AggregateList0 (Void)) '('AggregateListDistinct0 (Void)) '('Count0 (Void)) '('Sum0 (Void)) '('Sum1 (Void))))
      (return '($89 $90))
    ))) (lambda '($127 $128) (block '(
      (let $129 (DependsOn $127))
      (let $130 (QueueRange $51 $53 $50 $129))
      (let $131 (FlatMap $130 $54))
      (let $132 (Fold1 $131 $55 $56))
      (let $133 (QueueRange $51 $52 $53 $129))
      (let $134 (FlatMap $133 $54))
      (let $135 (Fold1 $134 $58 $59))
      (let $136 (IfPresent $135 $60 $57))
      (let $137 (Fold1 $134 $61 $62))
      (let $138 (Fold1 $134 $63 $64))
      (let $139 (Fold1 $131 $66 $67))
      (let $140 (AsStruct '('AggregateList0 (Coalesce $132 $57)) '('AggregateListDistinct0 $136) '('Count0 (Coalesce $137 $52)) '('Sum0 $138) '('Sum1 (Coalesce $139 $65)) '('"key" (Member $127 '"key")) '('"subkey" (Member $127 '"subkey")) '('"value" (Member $127 '"value"))))
      (return '($140 (Nth $128 '1)))
    )))))
    (return (OrderedMap $68 (lambda '($141) (block '(
      (let $142 (Nth $141 '0))
      (return (AsStruct '('AggregateList0 (Member $142 'AggregateList0)) '('AggregateListDistinct0 (Member $142 'AggregateListDistinct0)) '('Count0 (Member $142 'Count0)) '('Sum0 (Member $142 'Sum0)) '('Sum1 (Member $142 'Sum1)) '('"value" (Member $142 '"value"))))
    )))))
  )))))
  (let $33 (Sort (Map $32 (lambda '($143) (block '(
    (let $144 (Sort (Member $143 'AggregateListDistinct0) $31 (lambda '($145) $145)))
    (return (AsStruct '('"agglist2" (Member $143 'AggregateList0)) '($10 $144) '('"count1" (Member $143 'Count0)) '('"sum1" (Member $143 'Sum0)) '('"sum2" (Member $143 'Sum1)) '('"value" (Member $143 '"value"))))
  )))) $31 (lambda '($146) (Member $146 '"value"))))
  (let $34 (lambda '($147) (Member $147 '"agglist2") (Member $147 $10) (Member $147 '"count1") (Member $147 '"sum1") (Member $147 '"sum2") (Member $147 '"value")))
  (return (FromFlow (ExpandMap $33 $34)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('"5" '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($148) (FromFlow (NarrowMap (ToFlow $148) (lambda '($149 $150 $151 $152 $153 $154) (AsStruct '('"agglist2" $149) '($10 $150) '('"count1" $151) '('"sum1" $152) '('"sum2" $153) '('"value" $154)))))) '('('"_logical_id" '15050) '('"_id" '"34134d39-a4c967a0-2db1faaa-af880541"))))
(let $16 '($5 $13 $15))
(let $17 '('"value" '"sum1" '"count1" $10 '"sum2" '"agglist2"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
