(
(let $1 (OptionalType (DataType 'Uint32)))
(let $2 '('"age" $1))
(let $3 '('"name" (DataType 'String)))
(let $4 '('"region" $1))
(let $5 (StructType $2 $3 $4))
(let $6 '('('"_logical_id" '4434) '('"_id" '"588d6990-f505238f-1658671f-6f8616d3") '('"_wide_channels" $5)))
(let $7 (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 '"12") '('DataSize '"525") '('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))) '()))))
  (let $26 (lambda '($27 $28 $29) (SafeCast $27 $1) $29 (SafeCast $28 $1)))
  (return (FromFlow (WideMap (DqReadWideWrap $25 '()) $26)))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('"2") '0 '"HashV2"))
(let $9 (DataType 'Uint64))
(let $10 (OptionalType $9))
(let $11 (StructType $3 $4 '('"sum1" $10)))
(let $12 '('('"_logical_id" '4966) '('"_id" '"acb123d8-b83833b0-41fbf665-64fdfc52") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($8) (lambda '($30) (block '(
  (let $31 (NarrowSqueezeToDict (ToFlow $30) (lambda '($36 $37 $38) $38) (lambda '($39 $40 $41) (AsStruct '('"age" $39) '('"name" $40) '('"region" $41))) '('Auto 'Many)))
  (let $32 (Bool 'true))
  (let $33 (Chopper (OrderedFlatMap $31 (lambda '($42) (OrderedFlatMap (DictPayloads $42) (lambda '($43) (Sort $43 $32 (lambda '($44) (Member $44 '"name"))))))) (lambda '($45) (Member $45 '"region")) (lambda '($46 $47) (AggrNotEquals $46 (Member $47 '"region"))) (lambda '($48 $49) (block '(
    (let $50 (lambda '($62) (Just (SafeCast $62 $9))))
    (let $51 (Nothing $10))
    (let $52 (Chain1Map $49 (lambda '($57) (block '(
      (let $58 (Member $57 '"age"))
      (let $59 (IfPresent $58 $50 $51))
      (let $60 '('Sum0 $59))
      (let $61 (AsStruct $60 '('"age" $58) '('"name" (Member $57 '"name")) '('"region" (Member $57 '"region"))))
      (return '($61 (AsStruct $60)))
    ))) (lambda '($63 $64) (block '(
      (let $65 (Member $63 '"age"))
      (let $66 (IfPresent $65 $50 $51))
      (let $67 '('Sum0 (AggrAdd $66 (Member (Nth $64 '1) 'Sum0))))
      (let $68 (AsStruct $67 '('"age" $65) '('"name" (Member $63 '"name")) '('"region" (Member $63 '"region"))))
      (return '($68 (AsStruct $67)))
    )))))
    (let $53 (StructType '('Sum0 $10) $2 $3 $4))
    (let $54 (ListType $53))
    (let $55 (VariantType (StructType '('group $54) '('singleRow $53))))
    (let $56 (Condense1 $52 (lambda '($69) (block '(
      (let $70 (Nth $69 '0))
      (let $71 (Variant $70 'singleRow $55))
      (return '((Member $70 '"name") $71))
    ))) (lambda '($72 $73) (AggrNotEquals (Member (Nth $72 '0) '"name") (Nth $73 '0))) (lambda '($74 $75) (block '(
      (let $76 (Nth $74 '0))
      (let $77 (Visit (Nth $75 '1) 'group (lambda '($78) (Variant (Insert $78 $76) 'group $55)) 'singleRow (lambda '($79) (Variant (AsList $79 $76) 'group $55))))
      (return '((Nth $75 '0) $77))
    )))))
    (return (OrderedFlatMap $56 (lambda '($80) (block '(
      (let $81 (Visit (Nth $80 '1) 'group (lambda '($82) (IfPresent (Last $82) (lambda '($83) (OrderedMap (Collect (Map $82 (lambda '($84) (AsStruct '('"age" (Member $84 '"age")) '('"name" (Member $84 '"name")) '('"region" (Member $84 '"region")))))) (lambda '($85) (AsStruct '('Sum0 (Member $83 'Sum0)) '('"age" (Member $85 '"age")) '('"name" (Member $85 '"name")) '('"region" (Member $85 '"region")))))) (List $54))) 'singleRow (lambda '($86) (AsList $86))))
      (return (Map $81 (lambda '($87) (AsStruct '('Sum0 (Member $87 'Sum0)) '('"name" (Member $87 '"name")) '('"region" (Member $87 '"region"))))))
    )))))
  )))))
  (let $34 (Sort (Map $33 (lambda '($88) (AsStruct '('"name" (Member $88 '"name")) '('"region" (Member $88 '"region")) '('"sum1" (Member $88 'Sum0))))) '($32 $32) (lambda '($89) '((Member $89 '"region") (Member $89 '"name")))))
  (let $35 (lambda '($90) (Member $90 '"name") (Member $90 '"region") (Member $90 '"sum1")))
  (return (FromFlow (ExpandMap $34 $35)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('1 '"Asc") '('0 '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($91) (FromFlow (NarrowMap (ToFlow $91) (lambda '($92 $93 $94) (AsStruct '('"name" $92) '('"region" $93) '('"sum1" $94)))))) '('('"_logical_id" '4978) '('"_id" '"2640d628-9fcda4df-2e45295c-74cbfbca"))))
(let $16 '($7 $13 $15))
(let $17 '('"region" '"name" '"sum1"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
