(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 '('"key" $1))
(let $4 '('"key_quad" $2))
(let $5 '('('"_logical_id" '3701) '('"_id" '"6ad8b264-db6cd9fa-fb084790-da284923") '('"_wide_channels" (StructType $3 $4))))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $18 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $19 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $18)))
  (let $20 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $21 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"621") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $22 (YtTable '"Input" $19 $20 $21 '() (Void) (Void) '"/Root/plato"))
  (let $23 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $22 '('"key") (Void) (Void))) '()))))
  (let $24 (lambda '($25) (block '(
    (let $26 (SafeCast $25 $2))
    (return (Coalesce $26 (Int32 '0)) (% $26 (Int32 '"4")))
  ))))
  (return (FromFlow (WideMap (DqReadWideWrap $23 '()) $24)))
))) $5))
(let $7 (DqCnHashShuffle (TDqOutput $6 '0) '('1) '0 '"HashV2"))
(let $8 (DataType 'Uint64))
(let $9 (StructType '('"dense_rank_key" $8) $3 $4 '('"rank_key" $8)))
(let $10 '('('"_logical_id" '4120) '('"_id" '"bb46ed6c-fd660759-158c2f52-5cc50be4") '('"_wide_channels" $9)))
(let $11 (DqPhyStage '($7) (lambda '($27) (block '(
  (let $28 (NarrowSqueezeToDict (ToFlow $27) (lambda '($34 $35) $35) (lambda '($36 $37) (AsStruct '('"key" $36) '('"key_quad" $37))) '('Auto 'Many)))
  (let $29 (Bool 'true))
  (let $30 (Chopper (OrderedFlatMap $28 (lambda '($38) (OrderedFlatMap (DictPayloads $38) (lambda '($39) (Sort $39 $29 (lambda '($40) (Member $40 '"key"))))))) (lambda '($41) (Member $41 '"key_quad")) (lambda '($42 $43) (AggrNotEquals $42 (Member $43 '"key_quad"))) (lambda '($44 $45) (block '(
    (let $46 (Chain1Map $45 (lambda '($47) (block '(
      (let $48 (Uint64 '1))
      (let $49 (Member $47 '"key"))
      (let $50 (AsStruct '('_yql_DenseRank0 $48) '('_yql_Rank0 $48) '('"key" $49) '('"key_quad" (Member $47 '"key_quad"))))
      (let $51 '($48 $48 $49))
      (return '($50 (AsStruct '('_yql_DenseRank0 '($48 $49)) '('_yql_Rank0 $51))))
    ))) (lambda '($52 $53) (block '(
      (let $54 (Member $52 '"key"))
      (let $55 (Nth $53 '1))
      (let $56 (Member $55 '_yql_DenseRank0))
      (let $57 (Nth $56 '0))
      (let $58 (If (== $54 (Nth $56 '1)) $57 (Inc $57)))
      (let $59 (Member $55 '_yql_Rank0))
      (let $60 (Inc (Nth $59 '1)))
      (let $61 (If (== $54 (Nth $59 '"2")) (Nth $59 '0) $60))
      (let $62 (AsStruct '('_yql_DenseRank0 $58) '('_yql_Rank0 $61) '('"key" $54) '('"key_quad" (Member $52 '"key_quad"))))
      (let $63 '($61 $60 $54))
      (return '($62 (AsStruct '('_yql_DenseRank0 '($58 $54)) '('_yql_Rank0 $63))))
    )))))
    (return (OrderedMap $46 (lambda '($64) (Nth $64 '0))))
  )))))
  (let $31 '($29 $29 $29))
  (let $32 (Sort (Map $30 (lambda '($65) (AsStruct '('"dense_rank_key" (Member $65 '_yql_DenseRank0)) '('"key" (Member $65 '"key")) '('"key_quad" (Member $65 '"key_quad")) '('"rank_key" (Member $65 '_yql_Rank0))))) $31 (lambda '($66) '((Member $66 '"rank_key") (Member $66 '"dense_rank_key") (Member $66 '"key_quad")))))
  (let $33 (lambda '($67) (Member $67 '"dense_rank_key") (Member $67 '"key") (Member $67 '"key_quad") (Member $67 '"rank_key")))
  (return (FromFlow (ExpandMap $32 $33)))
))) $10))
(let $12 '('('"3" '"Asc") '('0 '"Asc") '('"2" '"Asc")))
(let $13 (DqCnMerge (TDqOutput $11 '0) $12))
(let $14 (DqPhyStage '($13) (lambda '($68) (FromFlow (NarrowMap (ToFlow $68) (lambda '($69 $70 $71 $72) (AsStruct '('"dense_rank_key" $69) '('"key" $70) '('"key_quad" $71) '('"rank_key" $72)))))) '('('"_logical_id" '4132) '('"_id" '"2b2aabea-796819fd-d1d1044c-221479c"))))
(let $15 '($6 $11 $14))
(let $16 '('"rank_key" '"dense_rank_key" '"key_quad" '"key"))
(let $17 (DqCnResult (TDqOutput $14 '0) $16))
(return (KqpPhysicalQuery '((KqpPhysicalTx $15 '($17) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $9) '0 '0)) '('('"type" '"query"))))
)
