(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 '('"key" $2))
(let $4 '('"key_quad" $2))
(let $5 '('('"_logical_id" '4793) '('"_id" '"31a1e45f-9a08439c-bba3bdc2-9a7afaa6") '('"_wide_channels" (StructType $3 $4))))
(let $6 (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 '"14") '('DataSize '"621") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $23 (YtTable '"Input" $20 $21 $22 '() (Void) (Void) '"/Root/plato"))
  (let $24 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $23 '('"key") (Void) (Void))) '()))))
  (let $25 (lambda '($26) (block '(
    (let $27 (SafeCast $26 $2))
    (return $27 (% $27 (Int32 '"4")))
  ))))
  (return (FromFlow (WideMap (DqReadWideWrap $24 '()) $25)))
))) $5))
(let $7 (DqCnHashShuffle (TDqOutput $6 '0) '('1) '0 '"HashV2"))
(let $8 (DataType 'Uint64))
(let $9 (OptionalType $8))
(let $10 (StructType '('"dense_rank_key" $9) $3 $4 '('"rank_key" $9)))
(let $11 '('('"_logical_id" '5209) '('"_id" '"5e562758-3ee1f91-1fdf7da4-d078a564") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '($7) (lambda '($28) (block '(
  (let $29 (NarrowSqueezeToDict (ToFlow $28) (lambda '($35 $36) $36) (lambda '($37 $38) (AsStruct '('"key" $37) '('"key_quad" $38))) '('Auto 'Many)))
  (let $30 (Bool 'true))
  (let $31 (Chopper (OrderedFlatMap $29 (lambda '($39) (OrderedFlatMap (DictPayloads $39) (lambda '($40) (Sort $40 $30 (lambda '($41) (Member $41 '"key"))))))) (lambda '($42) (Member $42 '"key_quad")) (lambda '($43 $44) (AggrNotEquals $43 (Member $44 '"key_quad"))) (lambda '($45 $46) (block '(
    (let $47 (lambda '($58) (block '(
      (let $59 (Uint64 '1))
      (return (Just '($59 $58)))
    ))))
    (let $48 (Nothing (OptionalType (TupleType $8 $1))))
    (let $49 (lambda '($60) (Just '((Uint64 '1) (Uint64 '1) $60))))
    (let $50 (Nothing (OptionalType (TupleType $8 $8 $1))))
    (let $51 (Chain1Map $46 (lambda '($52) (block '(
      (let $53 (Member $52 '"key"))
      (let $54 (Uint64 '1))
      (let $55 (IfPresent $53 $47 $48))
      (let $56 (IfPresent $53 $49 $50))
      (let $57 (AsStruct '('_yql_DenseRank0 (Nth $55 '0)) '('_yql_Rank0 (Nth $56 '0)) '('"key" $53) '('"key_quad" (Member $52 '"key_quad"))))
      (return '($57 (AsStruct '('_yql_DenseRank0 $55) '('_yql_Rank0 $56))))
    ))) (lambda '($61 $62) (block '(
      (let $63 (Nth $62 '1))
      (let $64 (Member $61 '"key"))
      (let $65 (IfPresent $64 $47 $48))
      (let $66 (IfPresent (Member $63 '_yql_DenseRank0) (lambda '($70) (IfPresent $64 (lambda '($71) (block '(
        (let $72 (Nth $70 '0))
        (let $73 (If (== $71 (Nth $70 '1)) $72 (Inc $72)))
        (return (Just '($73 $71)))
      ))) (Just $70))) $65))
      (let $67 (IfPresent $64 $49 $50))
      (let $68 (IfPresent (Member $63 '_yql_Rank0) (lambda '($74) (IfPresent $64 (lambda '($75) (block '(
        (let $76 (Inc (Nth $74 '1)))
        (let $77 (If (== $75 (Nth $74 '"2")) (Nth $74 '0) $76))
        (return (Just '($77 $76 $75)))
      ))) (Just $74))) $67))
      (let $69 (AsStruct '('_yql_DenseRank0 (Nth $66 '0)) '('_yql_Rank0 (Nth $68 '0)) '('"key" $64) '('"key_quad" (Member $61 '"key_quad"))))
      (return '($69 (AsStruct '('_yql_DenseRank0 $66) '('_yql_Rank0 $68))))
    )))))
    (return (OrderedMap $51 (lambda '($78) (Nth $78 '0))))
  )))))
  (let $32 '($30 $30 $30))
  (let $33 (Sort (Map $31 (lambda '($79) (AsStruct '('"dense_rank_key" (Member $79 '_yql_DenseRank0)) '('"key" (Member $79 '"key")) '('"key_quad" (Member $79 '"key_quad")) '('"rank_key" (Member $79 '_yql_Rank0))))) $32 (lambda '($80) '((Member $80 '"rank_key") (Member $80 '"dense_rank_key") (Member $80 '"key_quad")))))
  (let $34 (lambda '($81) (Member $81 '"dense_rank_key") (Member $81 '"key") (Member $81 '"key_quad") (Member $81 '"rank_key")))
  (return (FromFlow (ExpandMap $33 $34)))
))) $11))
(let $13 '('('"3" '"Asc") '('0 '"Asc") '('"2" '"Asc")))
(let $14 (DqCnMerge (TDqOutput $12 '0) $13))
(let $15 (DqPhyStage '($14) (lambda '($82) (FromFlow (NarrowMap (ToFlow $82) (lambda '($83 $84 $85 $86) (AsStruct '('"dense_rank_key" $83) '('"key" $84) '('"key_quad" $85) '('"rank_key" $86)))))) '('('"_logical_id" '5221) '('"_id" '"9c33da0c-95aa3fa9-b4d6ca00-b7818db9"))))
(let $16 '($6 $12 $15))
(let $17 '('"rank_key" '"dense_rank_key" '"key_quad" '"key"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $10) '0 '0)) '('('"type" '"query"))))
)
