(
(let $1 (OptionalType (DataType 'Int32)))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('"value" (DataType 'String)))
(let $5 (StructType $2 $3 $4))
(let $6 '('('"_logical_id" '5795) '('"_id" '"a5a2e769-7c7259ec-33c6ad80-c39c3c2b") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $18 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $19 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $18)))
  (let $20 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $21 (YtStat '('Id '"Input") '('RecordsCount '"10") '('DataSize '"420") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $22 (YtTable '"Input" $19 $20 $21 '() (Void) (Void) '"/Root/plato"))
  (let $23 '('"key" '"subkey" '"value"))
  (let $24 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $22 $23 (Void) (Void))) '()))))
  (let $25 (lambda '($26 $27 $28) (SafeCast $26 $1) (SafeCast $27 $1) $28))
  (return (FromFlow (WideMap (DqReadWideWrap $24 '()) $25)))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('0) '0 '"HashV2"))
(let $9 (DataType 'Int64))
(let $10 (OptionalType $9))
(let $11 (StructType '('"column2" $10) $2 $3 '('"subkey_sum" $10) $4))
(let $12 '('('"_logical_id" '6270) '('"_id" '"f9f0002f-66df9f06-c2a94cd0-4a32cab4") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($8) (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 (lambda '($64) (Just (SafeCast $64 $9))))
    (let $50 (Nothing $10))
    (let $51 (Chain1Map $48 (lambda '($56) (block '(
      (let $57 (Member $56 '"subkey"))
      (let $58 (IfPresent $57 $49 $50))
      (let $59 '('Sum0 $58))
      (let $60 (Member $56 '"key"))
      (let $61 (IfPresent $60 $49 $50))
      (let $62 '('Sum1 $61))
      (let $63 (AsStruct $59 $62 '('"key" $60) '('"subkey" $57) '('"value" (Member $56 '"value"))))
      (return '($63 (AsStruct $59 $62)))
    ))) (lambda '($65 $66) (block '(
      (let $67 (Member $65 '"subkey"))
      (let $68 (IfPresent $67 $49 $50))
      (let $69 (Nth $66 '1))
      (let $70 '('Sum0 (AggrAdd $68 (Member $69 'Sum0))))
      (let $71 (Member $65 '"key"))
      (let $72 (IfPresent $71 $49 $50))
      (let $73 '('Sum1 (AggrAdd $72 (Member $69 'Sum1))))
      (let $74 (AsStruct $70 $73 '('"key" $71) '('"subkey" $67) '('"value" (Member $65 '"value"))))
      (return '($74 (AsStruct $70 $73)))
    )))))
    (let $52 (StructType '('Sum0 $10) '('Sum1 $10) $2 $3 $4))
    (let $53 (ListType $52))
    (let $54 (VariantType (StructType '('group $53) '('singleRow $52))))
    (let $55 (Condense1 $51 (lambda '($75) (block '(
      (let $76 (Nth $75 '0))
      (let $77 (Variant $76 'singleRow $54))
      (return '((Member $76 '"value") $77))
    ))) (lambda '($78 $79) (AggrNotEquals (Member (Nth $78 '0) '"value") (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 $54)) 'singleRow (lambda '($85) (Variant (AsList $85 $82) 'group $54))))
      (return '((Nth $81 '0) $83))
    )))))
    (return (OrderedFlatMap $55 (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)) '('Sum1 (Member $88 'Sum1)) '('"key" (Member $90 '"key")) '('"subkey" (Member $90 '"subkey")) '('"value" (Member $90 '"value")))))) (List $53))) 'singleRow (lambda '($91) (AsList $91))))))
  )))))
  (let $33 (Sort (Map $32 (lambda '($92) (AsStruct '('"column2" (Member $92 'Sum1)) '('"key" (Member $92 '"key")) '('"subkey" (Member $92 '"subkey")) '('"subkey_sum" (Member $92 'Sum0)) '('"value" (Member $92 '"value"))))) '($31 $31) (lambda '($93) '((Member $93 '"key") (Member $93 '"subkey")))))
  (let $34 (lambda '($94) (Member $94 '"column2") (Member $94 '"key") (Member $94 '"subkey") (Member $94 '"subkey_sum") (Member $94 '"value")))
  (return (FromFlow (ExpandMap $33 $34)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('1 '"Asc") '('"2" '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($95) (FromFlow (NarrowMap (ToFlow $95) (lambda '($96 $97 $98 $99 $100) (AsStruct '('"column2" $96) '('"key" $97) '('"subkey" $98) '('"subkey_sum" $99) '('"value" $100)))))) '('('"_logical_id" '6282) '('"_id" '"80ee9105-3eb04885-8606a407-3bfcad68"))))
(let $16 '($7 $13 $15))
(let $17 (DqCnResult (TDqOutput $15 '0) '()))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($17) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
