(
(let $1 (DataType 'Int32))
(let $2 '('"key" $1))
(let $3 '('('"_logical_id" '3667) '('"_id" '"6a2a5d23-b8391f7a-c4a1c403-ba7cef21") '('"_wide_channels" (StructType $2))))
(let $4 (DqPhyStage '() (lambda '() (block '(
  (let $11 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $12 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $11)))
  (let $13 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $14 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"621") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $15 (YtTable '"Input" $12 $13 $14 '() (Void) (Void) '"/Root/plato"))
  (let $16 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $15 '('"key") (Void) (Void))) '()))))
  (return (FromFlow (WideMap (DqReadWideWrap $16 '()) (lambda '($17) (Coalesce (SafeCast $17 (OptionalType $1)) (Int32 '0))))))
))) $3))
(let $5 (DqCnUnionAll (TDqOutput $4 '0)))
(let $6 '('('"_logical_id" '3727) '('"_id" '"8924431c-3c65167e-c2bd746b-ac58db57") '('"_partition_mode" '"aggregate")))
(let $7 (DqPhyStage '($5) (lambda '($18) (block '(
  (let $19 (Chain1Map (NarrowMap (WideSort (ToFlow $18) '('('0 (Bool 'true)))) (lambda '($20) (AsStruct '('"key" $20)))) (lambda '($21) (block '(
    (let $22 (Uint64 '1))
    (let $23 (Member $21 '"key"))
    (let $24 (AsStruct '('_yql_DenseRank0 $22) '('_yql_Rank0 $22) '('"key" $23)))
    (let $25 '($22 $22 $23))
    (return '($24 (AsStruct '('_yql_DenseRank0 '($22 $23)) '('_yql_Rank0 $25))))
  ))) (lambda '($26 $27) (block '(
    (let $28 (Member $26 '"key"))
    (let $29 (Nth $27 '1))
    (let $30 (Member $29 '_yql_DenseRank0))
    (let $31 (Nth $30 '0))
    (let $32 (If (== $28 (Nth $30 '1)) $31 (Inc $31)))
    (let $33 (Member $29 '_yql_Rank0))
    (let $34 (Inc (Nth $33 '1)))
    (let $35 (If (== $28 (Nth $33 '"2")) (Nth $33 '0) $34))
    (let $36 (AsStruct '('_yql_DenseRank0 $32) '('_yql_Rank0 $35) '('"key" $28)))
    (let $37 '($35 $34 $28))
    (return '($36 (AsStruct '('_yql_DenseRank0 '($32 $28)) '('_yql_Rank0 $37))))
  )))))
  (return (FromFlow (OrderedMap $19 (lambda '($38) (block '(
    (let $39 (Nth $38 '0))
    (return (AsStruct '('"dense_rank_key" (Member $39 '_yql_DenseRank0)) '('"key" (Member $39 '"key")) '('"rank_key" (Member $39 '_yql_Rank0))))
  ))))))
))) $6))
(let $8 '('"rank_key" '"dense_rank_key" '"key"))
(let $9 (DqCnResult (TDqOutput $7 '0) $8))
(let $10 (DataType 'Uint64))
(return (KqpPhysicalQuery '((KqpPhysicalTx '($4 $7) '($9) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"dense_rank_key" $10) $2 '('"rank_key" $10))) '0 '0)) '('('"type" '"query"))))
)
