(
(let $1 (DataType 'String))
(let $2 '('"value" $1))
(let $3 (StructType '('"key" $1) '('"subkey" $1) $2))
(let $4 '('('"_logical_id" '13744) '('"_id" '"2e0f9d7f-2de247ac-48830c73-dcb627d8") '('"_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" '"caab2e35-f03eabfb-bc11148f-1c8a9570") '('"_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 '0))
    (let $51 (QueueCreate $3 (Uint64 '"7") $50 (DependsOn $49)))
    (let $52 (Uint64 '1))
    (let $53 (Uint64 '"3"))
    (let $54 (lambda '($92) $92))
    (let $55 (lambda '($93) (AsList (Member $93 '"subkey"))))
    (let $56 (lambda '($94 $95) (Insert $95 (Member $94 '"subkey"))))
    (let $57 (List $7))
    (let $58 (Uint64 '"6"))
    (let $59 (lambda '($96) (block '(
      (let $97 (DataType 'Uint32))
      (let $98 (TupleType (TupleType $1 $97) (StructType) $1))
      (let $99 (ResourceType '"Set.SetResource.String"))
      (let $100 '($99))
      (let $101 '($1))
      (let $102 (CallableType '() $100 $101 '($97)))
      (let $103 '('('"strict")))
      (let $104 (Udf '"Set.Create" (Void) $98 '"" $102 (VoidType) '"" $103))
      (let $105 (DependsOn (Uint32 '1)))
      (return (NamedApply $104 '((Member $96 '"subkey") (Uint32 '0)) (AsStruct) $105))
    ))))
    (let $60 (lambda '($106 $107) (block '(
      (let $108 (TupleType (TupleType (ResourceType '"Set.SetResource.String") $1) (StructType) $1))
      (let $109 (CallableType '() '((ResourceType '"Set.SetResource.String")) '((ResourceType '"Set.SetResource.String")) '($1)))
      (let $110 (Udf '"Set.AddValue" (Void) $108 '"" $109 (VoidType) '"" '('('"strict"))))
      (return (NamedApply $110 '($107 (Member $106 '"subkey")) (AsStruct) (DependsOn (Uint32 '1))))
    ))))
    (let $61 (lambda '($111) (block '(
      (let $112 (TupleType (TupleType (ResourceType '"Set.SetResource.String")) (StructType) $1))
      (let $113 (CallableType '() '($7) '((ResourceType '"Set.SetResource.String"))))
      (let $114 (Udf '"Set.GetResult" (Void) $112 '"" $113 (VoidType) '"" '('('"strict"))))
      (return (Apply $114 $111))
    ))))
    (let $62 (lambda '($115) $52))
    (let $63 (lambda '($116 $117) (Inc $117)))
    (let $64 (lambda '($118) (block '(
      (let $119 (OptionalType (DataType 'Uint32)))
      (return (SafeCast (Unwrap (SafeCast (Member $118 '"subkey") $119)) $8))
    ))))
    (let $65 (lambda '($120 $121) (AggrAdd (SafeCast (Unwrap (SafeCast (Member $120 '"subkey") (OptionalType (DataType 'Uint32)))) $8) $121)))
    (let $66 (Nothing $9))
    (let $67 (lambda '($122) (block '(
      (let $123 (lambda '($124) (Just (SafeCast $124 $8))))
      (return (IfPresent (SafeCast (Member $122 '"subkey") (OptionalType (DataType 'Uint32))) $123 $66))
    ))))
    (let $68 (lambda '($125 $126) (block '(
      (let $127 (IfPresent (SafeCast (Member $125 '"subkey") (OptionalType (DataType 'Uint32))) (lambda '($124) (Just (SafeCast $124 $8))) $66))
      (return (AggrAdd $127 $126))
    ))))
    (let $69 (Chain1Map (ToFlow (PreserveStream $49 $51 (Uint64 '"5"))) (lambda '($70) (block '(
      (let $71 (DependsOn $70))
      (let $72 (QueueRange $51 $52 $53 $71))
      (let $73 (FlatMap $72 $54))
      (let $74 (Fold1 $73 $55 $56))
      (let $75 (QueueRange $51 $53 $58 $71))
      (let $76 (FlatMap $75 $54))
      (let $77 (DataType 'Uint32))
      (let $78 (ResourceType '"Set.SetResource.String"))
      (let $79 '($78))
      (let $80 '($1))
      (let $81 '('('"strict")))
      (let $82 (DependsOn (Uint32 '1)))
      (let $83 (Fold1 $76 $59 $60))
      (let $84 (IfPresent $83 $61 $57))
      (let $85 (Fold1 $76 $62 $63))
      (let $86 (OptionalType $77))
      (let $87 (Fold1 $76 $64 $65))
      (let $88 (lambda '($124) (Just (SafeCast $124 $8))))
      (let $89 (Fold1 $73 $67 $68))
      (let $90 (AsStruct '('AggregateList0 (Coalesce $74 $57)) '('AggregateListDistinct0 $84) '('Count0 (Coalesce $85 $50)) '('Sum0 $87) '('Sum1 (Coalesce $89 $66)) '('"key" (Member $70 '"key")) '('"subkey" (Member $70 '"subkey")) '('"value" (Member $70 '"value"))))
      (let $91 (AsStruct '('AggregateList0 (Void)) '('AggregateListDistinct0 (Void)) '('Count0 (Void)) '('Sum0 (Void)) '('Sum1 (Void))))
      (return '($90 $91))
    ))) (lambda '($128 $129) (block '(
      (let $130 (DependsOn $128))
      (let $131 (QueueRange $51 $52 $53 $130))
      (let $132 (FlatMap $131 $54))
      (let $133 (Fold1 $132 $55 $56))
      (let $134 (QueueRange $51 $53 $58 $130))
      (let $135 (FlatMap $134 $54))
      (let $136 (Fold1 $135 $59 $60))
      (let $137 (IfPresent $136 $61 $57))
      (let $138 (Fold1 $135 $62 $63))
      (let $139 (Fold1 $135 $64 $65))
      (let $140 (Fold1 $132 $67 $68))
      (let $141 (AsStruct '('AggregateList0 (Coalesce $133 $57)) '('AggregateListDistinct0 $137) '('Count0 (Coalesce $138 $50)) '('Sum0 $139) '('Sum1 (Coalesce $140 $66)) '('"key" (Member $128 '"key")) '('"subkey" (Member $128 '"subkey")) '('"value" (Member $128 '"value"))))
      (return '($141 (Nth $129 '1)))
    )))))
    (return (OrderedMap $69 (lambda '($142) (block '(
      (let $143 (Nth $142 '0))
      (return (AsStruct '('AggregateList0 (Member $143 'AggregateList0)) '('AggregateListDistinct0 (Member $143 'AggregateListDistinct0)) '('Count0 (Member $143 'Count0)) '('Sum0 (Member $143 'Sum0)) '('Sum1 (Member $143 'Sum1)) '('"value" (Member $143 '"value"))))
    )))))
  )))))
  (let $33 (Sort (Map $32 (lambda '($144) (block '(
    (let $145 (Sort (Member $144 'AggregateListDistinct0) $31 (lambda '($146) $146)))
    (return (AsStruct '('"agglist2" (Member $144 'AggregateList0)) '($10 $145) '('"count1" (Member $144 'Count0)) '('"sum1" (Member $144 'Sum0)) '('"sum2" (Member $144 'Sum1)) '('"value" (Member $144 '"value"))))
  )))) $31 (lambda '($147) (Member $147 '"value"))))
  (let $34 (lambda '($148) (Member $148 '"agglist2") (Member $148 $10) (Member $148 '"count1") (Member $148 '"sum1") (Member $148 '"sum2") (Member $148 '"value")))
  (return (FromFlow (ExpandMap $33 $34)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('"5" '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($149) (FromFlow (NarrowMap (ToFlow $149) (lambda '($150 $151 $152 $153 $154 $155) (AsStruct '('"agglist2" $150) '($10 $151) '('"count1" $152) '('"sum1" $153) '('"sum2" $154) '('"value" $155)))))) '('('"_logical_id" '15050) '('"_id" '"ecec4cb5-c4db0432-7580703a-a26b0b1c"))))
(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"))))
)
