(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 '('"key" $2))
(let $4 '('('"_logical_id" '4787) '('"_id" '"4d378397-ff674577-6957a9a6-d2b7acef") '('"_wide_channels" (StructType $3))))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $13 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $14 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $13)))
  (let $15 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $16 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"621") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $17 (YtTable '"Input" $14 $15 $16 '() (Void) (Void) '"/Root/plato"))
  (let $18 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $17 '('"key") (Void) (Void))) '()))))
  (return (FromFlow (WideMap (DqReadWideWrap $18 '()) (lambda '($19) (SafeCast $19 $2)))))
))) $4))
(let $6 (DqCnUnionAll (TDqOutput $5 '0)))
(let $7 (DataType 'Uint64))
(let $8 '('('"_logical_id" '4844) '('"_id" '"a2e9f8e9-10c6dc5f-f61afc3-3fe76827") '('"_partition_mode" '"aggregate")))
(let $9 (DqPhyStage '($6) (lambda '($20) (block '(
  (let $21 (lambda '($33) (block '(
    (let $34 (Uint64 '1))
    (return (Just '($34 $33)))
  ))))
  (let $22 (Nothing (OptionalType (TupleType $7 $1))))
  (let $23 (lambda '($35) (Just '((Uint64 '1) (Uint64 '1) $35))))
  (let $24 (Nothing (OptionalType (TupleType $7 $7 $1))))
  (let $25 (Chain1Map (NarrowMap (WideSort (ToFlow $20) '('('0 (Bool 'true)))) (lambda '($26) (AsStruct '('"key" $26)))) (lambda '($27) (block '(
    (let $28 (Member $27 '"key"))
    (let $29 (Uint64 '1))
    (let $30 (IfPresent $28 $21 $22))
    (let $31 (IfPresent $28 $23 $24))
    (let $32 (AsStruct '('_yql_DenseRank0 (Nth $30 '0)) '('_yql_Rank0 (Nth $31 '0)) '('"key" $28)))
    (return '($32 (AsStruct '('_yql_DenseRank0 $30) '('_yql_Rank0 $31))))
  ))) (lambda '($36 $37) (block '(
    (let $38 (Nth $37 '1))
    (let $39 (Member $36 '"key"))
    (let $40 (IfPresent $39 $21 $22))
    (let $41 (IfPresent (Member $38 '_yql_DenseRank0) (lambda '($45) (IfPresent $39 (lambda '($46) (block '(
      (let $47 (Nth $45 '0))
      (let $48 (If (== $46 (Nth $45 '1)) $47 (Inc $47)))
      (return (Just '($48 $46)))
    ))) (Just $45))) $40))
    (let $42 (IfPresent $39 $23 $24))
    (let $43 (IfPresent (Member $38 '_yql_Rank0) (lambda '($49) (IfPresent $39 (lambda '($50) (block '(
      (let $51 (Inc (Nth $49 '1)))
      (let $52 (If (== $50 (Nth $49 '"2")) (Nth $49 '0) $51))
      (return (Just '($52 $51 $50)))
    ))) (Just $49))) $42))
    (let $44 (AsStruct '('_yql_DenseRank0 (Nth $41 '0)) '('_yql_Rank0 (Nth $43 '0)) '('"key" $39)))
    (return '($44 (AsStruct '('_yql_DenseRank0 $41) '('_yql_Rank0 $43))))
  )))))
  (return (FromFlow (OrderedMap $25 (lambda '($53) (block '(
    (let $54 (Nth $53 '0))
    (return (AsStruct '('"dense_rank_key" (Member $54 '_yql_DenseRank0)) '('"key" (Member $54 '"key")) '('"rank_key" (Member $54 '_yql_Rank0))))
  ))))))
))) $8))
(let $10 '('"rank_key" '"dense_rank_key" '"key"))
(let $11 (DqCnResult (TDqOutput $9 '0) $10))
(let $12 (OptionalType $7))
(return (KqpPhysicalQuery '((KqpPhysicalTx '($5 $9) '($11) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"dense_rank_key" $12) $3 '('"rank_key" $12))) '0 '0)) '('('"type" '"query"))))
)
