(
(let $1 (DataType 'String))
(let $2 '('"subkey" $1))
(let $3 '('"value" $1))
(let $4 (StructType '('"key" $1) $2 $3))
(let $5 '('('"_logical_id" '8349) '('"_id" '"70865a7-d5cafd9d-61b1ab40-2d2e4d6d") '('"_wide_channels" $4)))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $27 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $28 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $27)))
  (let $29 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $30 (YtStat '('Id '"Input") '('RecordsCount '"30") '('DataSize '"1170") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $31 (YtTable '"Input" $28 $29 $30 '() (Void) (Void) '"/Root/plato"))
  (let $32 '('"key" '"subkey" '"value"))
  (let $33 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $31 $32 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $33 '())))
))) $5))
(let $7 (DqCnHashShuffle (TDqOutput $6 '0) '('0) '0 '"HashV2"))
(let $8 (Bool 'true))
(let $9 (ListType $1))
(let $10 (List $9))
(let $11 (DataType 'Uint64))
(let $12 (OptionalType $11))
(let $13 (Nothing $12))
(let $14 (StructType '('AggregateListDistinct0 $9) '('Count0 $11) '('Sum0 $12) $2 $3))
(let $15 '('('"_logical_id" '8732) '('"_id" '"f1a7c9eb-44e653c0-8d1a4ce6-779458ad") '('"_wide_channels" $14)))
(let $16 (DqPhyStage '($7) (lambda '($34) (block '(
  (let $35 (NarrowSqueezeToDict (ToFlow $34) (lambda '($38 $39 $40) $38) (lambda '($41 $42 $43) (AsStruct '('"key" $41) '('"subkey" $42) '('"value" $43))) '('Auto 'Many)))
  (let $36 (Chopper (OrderedFlatMap $35 (lambda '($44) (OrderedFlatMap (DictPayloads $44) (lambda '($45) (Sort $45 $8 (lambda '($46) (Member $46 '"value"))))))) (lambda '($47) (Member $47 '"key")) (lambda '($48 $49) (AggrNotEquals $48 (Member $49 '"key"))) (lambda '($50 $51) (block '(
    (let $52 '('AggregateListDistinct0 $10))
    (let $53 '('Count0 (Uint64 '0)))
    (let $54 '('Sum0 $13))
    (let $55 (Chain1Map $51 (lambda '($56) (block '(
      (let $57 (AsStruct $52 $53 $54 '('"key" (Member $56 '"key")) '('"subkey" (Member $56 '"subkey")) '('"value" (Member $56 '"value"))))
      (let $58 (AsStruct '('AggregateListDistinct0 (Void)) '('Count0 (Void)) '('Sum0 (Void))))
      (return '($57 $58))
    ))) (lambda '($59 $60) (block '(
      (let $61 (AsStruct $52 $53 $54 '('"key" (Member $59 '"key")) '('"subkey" (Member $59 '"subkey")) '('"value" (Member $59 '"value"))))
      (return '($61 (Nth $60 '1)))
    )))))
    (return (OrderedMap $55 (lambda '($62) (block '(
      (let $63 (Nth $62 '0))
      (return (AsStruct '('AggregateListDistinct0 (Member $63 'AggregateListDistinct0)) '('Count0 (Member $63 'Count0)) '('Sum0 (Member $63 'Sum0)) '('"subkey" (Member $63 '"subkey")) '('"value" (Member $63 '"value"))))
    )))))
  )))))
  (let $37 (lambda '($64) (Member $64 'AggregateListDistinct0) (Member $64 'Count0) (Member $64 'Sum0) (Member $64 '"subkey") (Member $64 '"value")))
  (return (FromFlow (ExpandMap $36 $37)))
))) $15))
(let $17 (DqCnUnionAll (TDqOutput $16 '0)))
(let $18 '"agglist_distinct1")
(let $19 (StructType '('"agglist2" $9) '($18 $9) '('"count1" $11) '('"sum1" $12) '('"sum2" $12) $3))
(let $20 '('('"_logical_id" '9116) '('"_id" '"3884720c-a2ddc017-e3b69da2-c3759716") '('"_wide_channels" $19)))
(let $21 (DqPhyStage '($17) (lambda '($65) (block '(
  (let $66 '('AggregateList0 $10))
  (let $67 '('Sum1 $13))
  (let $68 (Chain1Map (NarrowMap (ToFlow $65) (lambda '($71 $72 $73 $74 $75) (AsStruct '('AggregateListDistinct0 $71) '('Count0 $72) '('Sum0 $73) '('"subkey" $74) '('"value" $75)))) (lambda '($76) (block '(
    (let $77 (AsStruct $66 '('AggregateListDistinct0 (Member $76 'AggregateListDistinct0)) '('Count0 (Member $76 'Count0)) '('Sum0 (Member $76 'Sum0)) $67 '('"subkey" (Member $76 '"subkey")) '('"value" (Member $76 '"value"))))
    (return '($77 (AsStruct '('AggregateList0 (Void)) '('Sum1 (Void)))))
  ))) (lambda '($78 $79) (block '(
    (let $80 (AsStruct $66 '('AggregateListDistinct0 (Member $78 'AggregateListDistinct0)) '('Count0 (Member $78 'Count0)) '('Sum0 (Member $78 'Sum0)) $67 '('"subkey" (Member $78 '"subkey")) '('"value" (Member $78 '"value"))))
    (return '($80 (Nth $79 '1)))
  )))))
  (let $69 (Sort (Map $68 (lambda '($81) (block '(
    (let $82 (Nth $81 '0))
    (let $83 (Sort (Member $82 'AggregateListDistinct0) $8 (lambda '($84) $84)))
    (return (AsStruct '('"agglist2" (Member $82 'AggregateList0)) '($18 $83) '('"count1" (Member $82 'Count0)) '('"sum1" (Member $82 'Sum0)) '('"sum2" (Member $82 'Sum1)) '('"value" (Member $82 '"value"))))
  )))) $8 (lambda '($85) (Member $85 '"value"))))
  (let $70 (lambda '($86) (Member $86 '"agglist2") (Member $86 $18) (Member $86 '"count1") (Member $86 '"sum1") (Member $86 '"sum2") (Member $86 '"value")))
  (return (FromFlow (ExpandMap $69 $70)))
))) $20))
(let $22 (DqCnMerge (TDqOutput $21 '0) '('('"5" '"Asc"))))
(let $23 (DqPhyStage '($22) (lambda '($87) (FromFlow (NarrowMap (ToFlow $87) (lambda '($88 $89 $90 $91 $92 $93) (AsStruct '('"agglist2" $88) '($18 $89) '('"count1" $90) '('"sum1" $91) '('"sum2" $92) '('"value" $93)))))) '('('"_logical_id" '9128) '('"_id" '"f4a62656-ba9d4bc8-64fd984-af7bf79b"))))
(let $24 '($6 $16 $21 $23))
(let $25 '('"value" '"sum1" '"count1" $18 '"sum2" '"agglist2"))
(let $26 (DqCnResult (TDqOutput $23 '0) $25))
(return (KqpPhysicalQuery '((KqpPhysicalTx $24 '($26) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $19) '0 '0)) '('('"type" '"query"))))
)
