(
(let $1 (OptionalType (DataType 'Uint32)))
(let $2 '('"age" $1))
(let $3 '('"age_decade" (OptionalType (DataType 'Int32))))
(let $4 '('"name" (DataType 'String)))
(let $5 '('"region" $1))
(let $6 (StructType $2 $3 $4 $5))
(let $7 '('('"_logical_id" '9072) '('"_id" '"8ff74df5-80ab64c6-6dd090c3-a19bdb67") '('"_wide_channels" $6)))
(let $8 (DqPhyStage '() (lambda '() (block '(
  (let $29 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $30 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $29)))
  (let $31 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $32 (YtStat '('Id '"Input") '('RecordsCount '"12") '('DataSize '"525") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $33 (YtTable '"Input" $30 $31 $32 '() (Void) (Void) '"/Root/plato"))
  (let $34 '('"key" '"subkey" '"value"))
  (let $35 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $33 $34 (Void) (Void))) '()))))
  (let $36 (lambda '($37 $38 $39) (block '(
    (let $40 (SafeCast $37 $1))
    (return $40 (/ $40 (Int32 '"10")) $39 (SafeCast $38 $1))
  ))))
  (return (FromFlow (WideMap (DqReadWideWrap $35 '()) $36)))
))) $7))
(let $9 (DqCnHashShuffle (TDqOutput $8 '0) '('"3") '0 '"HashV2"))
(let $10 '('Auto 'Many))
(let $11 (Bool 'true))
(let $12 (DataType 'Uint64))
(let $13 (lambda '($70) (Just (SafeCast $70 $12))))
(let $14 (OptionalType $12))
(let $15 (Nothing $14))
(let $16 '('Sum0 $14))
(let $17 (StructType $16 $2 $3 $4 $5))
(let $18 '('('"_logical_id" '9146) '('"_id" '"509daa0c-5f7d5364-3f0dcd7a-2c642963") '('"_partition_mode" '"aggregate") '('"_wide_channels" $17)))
(let $19 (DqPhyStage '($9) (lambda '($41) (block '(
  (let $42 (NarrowSqueezeToDict (ToFlow $41) (lambda '($45 $46 $47 $48) $48) (lambda '($49 $50 $51 $52) (AsStruct '('"age" $49) '('"age_decade" $50) '('"name" $51) '('"region" $52))) $10))
  (let $43 (Chopper (OrderedFlatMap $42 (lambda '($53) (OrderedFlatMap (DictPayloads $53) (lambda '($54) (Sort $54 $11 (lambda '($55) (Member $55 '"name"))))))) (lambda '($56) (Member $56 '"region")) (lambda '($57 $58) (AggrNotEquals $57 (Member $58 '"region"))) (lambda '($59 $60) (block '(
    (let $61 (Chain1Map $60 (lambda '($65) (block '(
      (let $66 (Member $65 '"age"))
      (let $67 (IfPresent $66 $13 $15))
      (let $68 '('Sum0 $67))
      (let $69 (AsStruct $68 '('"age" $66) '('"age_decade" (Member $65 '"age_decade")) '('"name" (Member $65 '"name")) '('"region" (Member $65 '"region"))))
      (return '($69 (AsStruct $68)))
    ))) (lambda '($71 $72) (block '(
      (let $73 (Member $71 '"age"))
      (let $74 (IfPresent $73 $13 $15))
      (let $75 '('Sum0 (AggrAdd $74 (Member (Nth $72 '1) 'Sum0))))
      (let $76 (AsStruct $75 '('"age" $73) '('"age_decade" (Member $71 '"age_decade")) '('"name" (Member $71 '"name")) '('"region" (Member $71 '"region"))))
      (return '($76 (AsStruct $75)))
    )))))
    (let $62 (ListType $17))
    (let $63 (VariantType (StructType '('group $62) '('singleRow $17))))
    (let $64 (Condense1 $61 (lambda '($77) (block '(
      (let $78 (Nth $77 '0))
      (let $79 (Variant $78 'singleRow $63))
      (return '((Member $78 '"name") $79))
    ))) (lambda '($80 $81) (AggrNotEquals (Member (Nth $80 '0) '"name") (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 $63)) 'singleRow (lambda '($87) (Variant (AsList $87 $84) 'group $63))))
      (return '((Nth $83 '0) $85))
    )))))
    (return (OrderedFlatMap $64 (lambda '($88) (Visit (Nth $88 '1) 'group (lambda '($89) (IfPresent (Last $89) (lambda '($90) (OrderedMap (Collect (Map $89 (lambda '($91) (AsStruct '('"age" (Member $91 '"age")) '('"age_decade" (Member $91 '"age_decade")) '('"name" (Member $91 '"name")) '('"region" (Member $91 '"region")))))) (lambda '($92) (AsStruct '('Sum0 (Member $90 'Sum0)) '('"age" (Member $92 '"age")) '('"age_decade" (Member $92 '"age_decade")) '('"name" (Member $92 '"name")) '('"region" (Member $92 '"region")))))) (List $62))) 'singleRow (lambda '($93) (AsList $93))))))
  )))))
  (let $44 (lambda '($94) (Member $94 'Sum0) (Member $94 '"age") (Member $94 '"age_decade") (Member $94 '"name") (Member $94 '"region")))
  (return (FromFlow (ExpandMap $43 $44)))
))) $18))
(let $20 (DqCnHashShuffle (TDqOutput $19 '0) '('"2") '0 '"HashV2"))
(let $21 (StructType $2 $4 $5 '('"sum1" $14) '('"sum2" $14)))
(let $22 '('('"_logical_id" '10006) '('"_id" '"9564f3cd-32ac61ba-5ae044ff-8e0fcaff") '('"_wide_channels" $21)))
(let $23 (DqPhyStage '($20) (lambda '($95) (block '(
  (let $96 (NarrowSqueezeToDict (ToFlow $95) (lambda '($100 $101 $102 $103 $104) $102) (lambda '($105 $106 $107 $108 $109) (AsStruct '('Sum0 $105) '('"age" $106) '('"age_decade" $107) '('"name" $108) '('"region" $109))) $10))
  (let $97 (Chopper (OrderedFlatMap $96 (lambda '($110) (OrderedFlatMap (DictPayloads $110) (lambda '($111) (Sort $111 $11 (lambda '($112) (Member $112 '"name"))))))) (lambda '($113) (Member $113 '"age_decade")) (lambda '($114 $115) (AggrNotEquals $114 (Member $115 '"age_decade"))) (lambda '($116 $117) (block '(
    (let $118 (Chain1Map $117 (lambda '($123) (block '(
      (let $124 (Member $123 '"age"))
      (let $125 (IfPresent $124 $13 $15))
      (let $126 '('Sum1 $125))
      (let $127 (AsStruct '('Sum0 (Member $123 'Sum0)) $126 '('"age" $124) '('"age_decade" (Member $123 '"age_decade")) '('"name" (Member $123 '"name")) '('"region" (Member $123 '"region"))))
      (return '($127 (AsStruct $126)))
    ))) (lambda '($128 $129) (block '(
      (let $130 (Member $128 '"age"))
      (let $131 (IfPresent $130 $13 $15))
      (let $132 '('Sum1 (AggrAdd $131 (Member (Nth $129 '1) 'Sum1))))
      (let $133 (AsStruct '('Sum0 (Member $128 'Sum0)) $132 '('"age" $130) '('"age_decade" (Member $128 '"age_decade")) '('"name" (Member $128 '"name")) '('"region" (Member $128 '"region"))))
      (return '($133 (AsStruct $132)))
    )))))
    (let $119 (StructType $16 '('Sum1 $14) $2 $3 $4 $5))
    (let $120 (ListType $119))
    (let $121 (VariantType (StructType '('group $120) '('singleRow $119))))
    (let $122 (Condense1 $118 (lambda '($134) (block '(
      (let $135 (Nth $134 '0))
      (let $136 (Variant $135 'singleRow $121))
      (return '((Member $135 '"name") $136))
    ))) (lambda '($137 $138) (AggrNotEquals (Member (Nth $137 '0) '"name") (Nth $138 '0))) (lambda '($139 $140) (block '(
      (let $141 (Nth $139 '0))
      (let $142 (Visit (Nth $140 '1) 'group (lambda '($143) (Variant (Insert $143 $141) 'group $121)) 'singleRow (lambda '($144) (Variant (AsList $144 $141) 'group $121))))
      (return '((Nth $140 '0) $142))
    )))))
    (return (OrderedFlatMap $122 (lambda '($145) (block '(
      (let $146 (Visit (Nth $145 '1) 'group (lambda '($147) (IfPresent (Last $147) (lambda '($148) (OrderedMap (Collect (Map $147 (lambda '($149) (AsStruct '('Sum0 (Member $149 'Sum0)) '('"age" (Member $149 '"age")) '('"age_decade" (Member $149 '"age_decade")) '('"name" (Member $149 '"name")) '('"region" (Member $149 '"region")))))) (lambda '($150) (AsStruct '('Sum0 (Member $150 'Sum0)) '('Sum1 (Member $148 'Sum1)) '('"age" (Member $150 '"age")) '('"age_decade" (Member $150 '"age_decade")) '('"name" (Member $150 '"name")) '('"region" (Member $150 '"region")))))) (List $120))) 'singleRow (lambda '($151) (AsList $151))))
      (return (Map $146 (lambda '($152) (AsStruct '('Sum0 (Member $152 'Sum0)) '('Sum1 (Member $152 'Sum1)) '('"age" (Member $152 '"age")) '('"name" (Member $152 '"name")) '('"region" (Member $152 '"region"))))))
    )))))
  )))))
  (let $98 (Sort (Map $97 (lambda '($153) (AsStruct '('"age" (Member $153 '"age")) '('"name" (Member $153 '"name")) '('"region" (Member $153 '"region")) '('"sum1" (Member $153 'Sum0)) '('"sum2" (Member $153 'Sum1))))) '($11 $11) (lambda '($154) '((Member $154 '"region") (Member $154 '"age")))))
  (let $99 (lambda '($155) (Member $155 '"age") (Member $155 '"name") (Member $155 '"region") (Member $155 '"sum1") (Member $155 '"sum2")))
  (return (FromFlow (ExpandMap $98 $99)))
))) $22))
(let $24 (DqCnMerge (TDqOutput $23 '0) '('('"2" '"Asc") '('0 '"Asc"))))
(let $25 (DqPhyStage '($24) (lambda '($156) (FromFlow (NarrowMap (ToFlow $156) (lambda '($157 $158 $159 $160 $161) (AsStruct '('"age" $157) '('"name" $158) '('"region" $159) '('"sum1" $160) '('"sum2" $161)))))) '('('"_logical_id" '10018) '('"_id" '"db744ea5-e4c017fc-a029b4dd-aa7f8f68"))))
(let $26 '($8 $19 $23 $25))
(let $27 '('"region" '"age" '"name" '"sum1" '"sum2"))
(let $28 (DqCnResult (TDqOutput $25 '0) $27))
(return (KqpPhysicalQuery '((KqpPhysicalTx $26 '($28) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $21) '0 '0)) '('('"type" '"query"))))
)
