(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('"value" $1))
(let $5 (StructType $2 $3 $4))
(let $6 '('('"_logical_id" '5489) '('"_id" '"53b462d3-4405babd-5978f0b2-d600f93c") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $21 '@@["StructType";[["value";["DataType";"String"]];["subkey";["DataType";"String"]];["key";["DataType";"String"]]]]@@)
  (let $22 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $21)))
  (let $23 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $24 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $25 (YtTable '"Input" $22 $23 $24 '() (Void) (Void) '"/Root/plato"))
  (let $26 '('"key" '"subkey" '"value"))
  (let $27 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $25 $26 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $27 '())))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('0) '0 '"HashV2"))
(let $9 (StructType '('Min0 $1) $2 $3 $4))
(let $10 '('('"_logical_id" '5552) '('"_id" '"5ced9790-2230331f-5241f48e-3b52cbb6") '('"_partition_mode" '"aggregate") '('"_wide_channels" $9)))
(let $11 (DqPhyStage '($8) (lambda '($28) (block '(
  (let $29 (NarrowSqueezeToDict (ToFlow $28) (lambda '($32 $33 $34) $32) (lambda '($35 $36 $37) (AsStruct '('"key" $35) '('"subkey" $36) '('"value" $37))) '('Auto 'Many)))
  (let $30 (Chopper (OrderedFlatMap $29 (lambda '($38) (OrderedFlatMap (DictPayloads $38) (lambda '($39) $39)))) (lambda '($40) (Member $40 '"key")) (lambda '($41 $42) (AggrNotEquals $41 (Member $42 '"key"))) (lambda '($43 $44) (block '(
    (let $45 (Chain1Map $44 (lambda '($49) (block '(
      (let $50 (Member $49 '"subkey"))
      (let $51 '('Min0 $50))
      (let $52 (AsStruct $51 '('"key" (Member $49 '"key")) '('"subkey" $50) '('"value" (Member $49 '"value"))))
      (return '($52 (AsStruct $51)))
    ))) (lambda '($53 $54) (block '(
      (let $55 (Member $53 '"subkey"))
      (let $56 '('Min0 (AggrMin $55 (Member (Nth $54 '1) 'Min0))))
      (let $57 (AsStruct $56 '('"key" (Member $53 '"key")) '('"subkey" $55) '('"value" (Member $53 '"value"))))
      (return '($57 (AsStruct $56)))
    )))))
    (let $46 (ListType $9))
    (let $47 (VariantType (StructType '('group $46) '('singleRow $9))))
    (let $48 (Condense1 $45 (lambda '($58) (block '(
      (let $59 (Variant (Nth $58 '0) 'singleRow $47))
      (return '((Void) $59))
    ))) (lambda '($60 $61) (Bool 'false)) (lambda '($62 $63) (block '(
      (let $64 (Nth $62 '0))
      (let $65 (Visit (Nth $63 '1) 'group (lambda '($66) (Variant (Insert $66 $64) 'group $47)) 'singleRow (lambda '($67) (Variant (AsList $67 $64) 'group $47))))
      (return '((Nth $63 '0) $65))
    )))))
    (return (OrderedFlatMap $48 (lambda '($68) (Visit (Nth $68 '1) 'group (lambda '($69) (IfPresent (Last $69) (lambda '($70) (OrderedMap (Collect (Map $69 (lambda '($71) (AsStruct '('"key" (Member $71 '"key")) '('"subkey" (Member $71 '"subkey")) '('"value" (Member $71 '"value")))))) (lambda '($72) (AsStruct '('Min0 (Member $70 'Min0)) '('"key" (Member $72 '"key")) '('"subkey" (Member $72 '"subkey")) '('"value" (Member $72 '"value")))))) (List $46))) 'singleRow (lambda '($73) (AsList $73))))))
  )))))
  (let $31 (lambda '($74) (Member $74 'Min0) (Member $74 '"key") (Member $74 '"subkey") (Member $74 '"value")))
  (return (FromFlow (ExpandMap $30 $31)))
))) $10))
(let $12 (DqCnUnionAll (TDqOutput $11 '0)))
(let $13 (StructType $2 $3 $4 '('"z" (DataType 'Uint64)) '('"zz" $1)))
(let $14 '('('"_logical_id" '6142) '('"_id" '"c73986c5-8611b6ab-99baef70-133131d6") '('"_wide_channels" $13)))
(let $15 (DqPhyStage '($12) (lambda '($75) (block '(
  (let $76 (Bool 'true))
  (let $77 (Chain1Map (NarrowMap (WideSort (ToFlow $75) '('('1 $76) '('2 $76))) (lambda '($80 $81 $82 $83) (AsStruct '('Min0 $80) '('"key" $81) '('"subkey" $82) '('"value" $83)))) (lambda '($84) (block '(
    (let $85 '('_yql_RowNumber0 (Uint64 '1)))
    (let $86 (AsStruct '('Min0 (Member $84 'Min0)) $85 '('"key" (Member $84 '"key")) '('"subkey" (Member $84 '"subkey")) '('"value" (Member $84 '"value"))))
    (return '($86 (AsStruct $85)))
  ))) (lambda '($87 $88) (block '(
    (let $89 '('_yql_RowNumber0 (Inc (Member (Nth $88 '1) '_yql_RowNumber0))))
    (let $90 (AsStruct '('Min0 (Member $87 'Min0)) $89 '('"key" (Member $87 '"key")) '('"subkey" (Member $87 '"subkey")) '('"value" (Member $87 '"value"))))
    (return '($90 (AsStruct $89)))
  )))))
  (let $78 (Sort (Map $77 (lambda '($91) (block '(
    (let $92 (Nth $91 '0))
    (return (AsStruct '('"key" (Member $92 '"key")) '('"subkey" (Member $92 '"subkey")) '('"value" (Member $92 '"value")) '('"z" (Member $92 '_yql_RowNumber0)) '('"zz" (Member $92 'Min0))))
  )))) '($76 $76) (lambda '($93) '((Member $93 '"key") (Member $93 '"subkey")))))
  (let $79 (lambda '($94) (Member $94 '"key") (Member $94 '"subkey") (Member $94 '"value") (Member $94 '"z") (Member $94 '"zz")))
  (return (FromFlow (ExpandMap $78 $79)))
))) $14))
(let $16 (DqCnMerge (TDqOutput $15 '0) '('('0 '"Asc") '('1 '"Asc"))))
(let $17 (DqPhyStage '($16) (lambda '($95) (FromFlow (NarrowMap (ToFlow $95) (lambda '($96 $97 $98 $99 $100) (AsStruct '('"key" $96) '('"subkey" $97) '('"value" $98) '('"z" $99) '('"zz" $100)))))) '('('"_logical_id" '6154) '('"_id" '"2314ddd7-d52481be-9671c0b2-bc40b044"))))
(let $18 '($7 $11 $15 $17))
(let $19 '('"zz" '"z" '"value" '"subkey" '"key"))
(let $20 (DqCnResult (TDqOutput $17 '0) $19))
(return (KqpPhysicalQuery '((KqpPhysicalTx $18 '($20) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $13) '0 '0)) '('('"type" '"query"))))
)
