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