(
(let $1 (OptionalType (DataType 'Int32)))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 (DataType 'String))
(let $5 '('"value" $4))
(let $6 (StructType $2 $3 $5))
(let $7 '('('"_logical_id" '5860) '('"_id" '"74539548-d85d8d7d-77a11ef-46c1e5b3") '('"_wide_channels" $6)))
(let $8 (DqPhyStage '() (lambda '() (block '(
  (let $20 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $21 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $20)))
  (let $22 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $23 (YtStat '('Id '"Input") '('RecordsCount '"10") '('DataSize '"420") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $24 (YtTable '"Input" $21 $22 $23 '() (Void) (Void) '"/Root/plato"))
  (let $25 '('"key" '"subkey" '"value"))
  (let $26 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $24 $25 (Void) (Void))) '()))))
  (let $27 (lambda '($28 $29 $30) (SafeCast $28 $1) (SafeCast $29 $1) $30))
  (return (FromFlow (WideMap (DqReadWideWrap $26 '()) $27)))
))) $7))
(let $9 (DqCnHashShuffle (TDqOutput $8 '0) '('0) '0 '"HashV2"))
(let $10 (DataType 'Int64))
(let $11 (OptionalType $10))
(let $12 (StructType '('"column2" $11) '('"subkey_sum" $11) '('"t.key" $1) '('"t.subkey" $1) '('"t.value" $4)))
(let $13 '('('"_logical_id" '6335) '('"_id" '"e911a670-68f9509e-4ff8ce57-70d97402") '('"_wide_channels" $12)))
(let $14 (DqPhyStage '($9) (lambda '($31) (block '(
  (let $32 (NarrowSqueezeToDict (ToFlow $31) (lambda '($37 $38 $39) $37) (lambda '($40 $41 $42) (AsStruct '('"key" $40) '('"subkey" $41) '('"value" $42))) '('Auto 'Many)))
  (let $33 (Bool 'true))
  (let $34 (Chopper (OrderedFlatMap $32 (lambda '($43) (OrderedFlatMap (DictPayloads $43) (lambda '($44) (Sort $44 $33 (lambda '($45) (Member $45 '"value"))))))) (lambda '($46) (Member $46 '"key")) (lambda '($47 $48) (AggrNotEquals $47 (Member $48 '"key"))) (lambda '($49 $50) (block '(
    (let $51 (lambda '($66) (Just (SafeCast $66 $10))))
    (let $52 (Nothing $11))
    (let $53 (Chain1Map $50 (lambda '($58) (block '(
      (let $59 (Member $58 '"subkey"))
      (let $60 (IfPresent $59 $51 $52))
      (let $61 '('Sum0 $60))
      (let $62 (Member $58 '"key"))
      (let $63 (IfPresent $62 $51 $52))
      (let $64 '('Sum1 $63))
      (let $65 (AsStruct $61 $64 '('"key" $62) '('"subkey" $59) '('"value" (Member $58 '"value"))))
      (return '($65 (AsStruct $61 $64)))
    ))) (lambda '($67 $68) (block '(
      (let $69 (Member $67 '"subkey"))
      (let $70 (IfPresent $69 $51 $52))
      (let $71 (Nth $68 '1))
      (let $72 '('Sum0 (AggrAdd $70 (Member $71 'Sum0))))
      (let $73 (Member $67 '"key"))
      (let $74 (IfPresent $73 $51 $52))
      (let $75 '('Sum1 (AggrAdd $74 (Member $71 'Sum1))))
      (let $76 (AsStruct $72 $75 '('"key" $73) '('"subkey" $69) '('"value" (Member $67 '"value"))))
      (return '($76 (AsStruct $72 $75)))
    )))))
    (let $54 (StructType '('Sum0 $11) '('Sum1 $11) $2 $3 $5))
    (let $55 (ListType $54))
    (let $56 (VariantType (StructType '('group $55) '('singleRow $54))))
    (let $57 (Condense1 $53 (lambda '($77) (block '(
      (let $78 (Nth $77 '0))
      (let $79 (Variant $78 'singleRow $56))
      (return '((Member $78 '"value") $79))
    ))) (lambda '($80 $81) (AggrNotEquals (Member (Nth $80 '0) '"value") (Nth $81 '0))) (lambda '($82 $83) (block '(
      (let $84 (Nth $82 '0))
      (let $85 (Visit (Nth $83 '1) 'group (lambda '($86) (Variant (Insert $86 $84) 'group $56)) 'singleRow (lambda '($87) (Variant (AsList $87 $84) 'group $56))))
      (return '((Nth $83 '0) $85))
    )))))
    (return (OrderedFlatMap $57 (lambda '($88) (Visit (Nth $88 '1) 'group (lambda '($89) (IfPresent (Last $89) (lambda '($90) (OrderedMap (Collect (Map $89 (lambda '($91) (AsStruct '('"key" (Member $91 '"key")) '('"subkey" (Member $91 '"subkey")) '('"value" (Member $91 '"value")))))) (lambda '($92) (AsStruct '('Sum0 (Member $90 'Sum0)) '('Sum1 (Member $90 'Sum1)) '('"key" (Member $92 '"key")) '('"subkey" (Member $92 '"subkey")) '('"value" (Member $92 '"value")))))) (List $55))) 'singleRow (lambda '($93) (AsList $93))))))
  )))))
  (let $35 (Sort (Map $34 (lambda '($94) (AsStruct '('"column2" (Member $94 'Sum1)) '('"subkey_sum" (Member $94 'Sum0)) '('"t.key" (Member $94 '"key")) '('"t.subkey" (Member $94 '"subkey")) '('"t.value" (Member $94 '"value"))))) '($33 $33) (lambda '($95) '((Member $95 '"t.key") (Member $95 '"t.subkey")))))
  (let $36 (lambda '($96) (Member $96 '"column2") (Member $96 '"subkey_sum") (Member $96 '"t.key") (Member $96 '"t.subkey") (Member $96 '"t.value")))
  (return (FromFlow (ExpandMap $35 $36)))
))) $13))
(let $15 (DqCnMerge (TDqOutput $14 '0) '('('"2" '"Asc") '('"3" '"Asc"))))
(let $16 (DqPhyStage '($15) (lambda '($97) (FromFlow (NarrowMap (ToFlow $97) (lambda '($98 $99 $100 $101 $102) (AsStruct '('"column2" $98) '('"subkey_sum" $99) '('"t.key" $100) '('"t.subkey" $101) '('"t.value" $102)))))) '('('"_logical_id" '6347) '('"_id" '"4adbaa51-f52e0edf-a3cd5513-edb8ff78"))))
(let $17 '($8 $14 $16))
(let $18 '('"t.key" '"t.subkey" '"t.value" '"subkey_sum" '"column2"))
(let $19 (DqCnResult (TDqOutput $16 '0) $18))
(return (KqpPhysicalQuery '((KqpPhysicalTx $17 '($19) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $12) '0 '0)) '('('"type" '"query"))))
)
