(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('('"_logical_id" '2819) '('"_id" '"ec76cdf7-9d9911fa-64e04fd5-3dc8d040") '('"_wide_channels" (StructType $2 $3))))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $15 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $16 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $15)))
  (let $17 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $18 (YtStat '('Id '"Input") '('RecordsCount '"10") '('DataSize '"420") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $19 (YtTable '"Input" $16 $17 $18 '() (Void) (Void) '"/Root/plato"))
  (let $20 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $19 '('"key" '"subkey") (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $20 '())))
))) $4))
(let $6 (DqCnHashShuffle (TDqOutput $5 '0) '('0) '0 '"HashV2"))
(let $7 (StructType '('"ix" (DataType 'Uint64)) $2 $3 '('"subkey_enc" $1)))
(let $8 '('('"_logical_id" '3233) '('"_id" '"cef1f12-f9be0959-166736b0-21c3587e") '('"_wide_channels" $7)))
(let $9 (DqPhyStage '($6) (lambda '($21) (block '(
  (let $22 (NarrowSqueezeToDict (ToFlow $21) (lambda '($30 $31) $30) (lambda '($32 $33) (AsStruct '('"key" $32) '('"subkey" $33))) '('Auto 'Many)))
  (let $23 '($1 '"" '1))
  (let $24 (CallableType '() '($1) $23))
  (let $25 (Udf '"String.Base64Encode" (Void) (VoidType) '"" $24 (VoidType) '"" '('('"blocks") '('"strict"))))
  (let $26 (Chopper (OrderedFlatMap $22 (lambda '($34) (OrderedFlatMap (DictPayloads $34) (lambda '($35) (block '(
    (let $36 (Sort (OrderedMap $35 (lambda '($37) (block '(
      (let $38 (Member $37 '"subkey"))
      (return (AsStruct '('_yql_sys_order_by (Apply $25 $38)) '('"key" (Member $37 '"key")) '('"subkey" $38)))
    )))) (Bool 'false) (lambda '($39) (Member $39 '_yql_sys_order_by))))
    (return (OrderedMap $36 (lambda '($40) (AsStruct '('"key" (Member $40 '"key")) '('"subkey" (Member $40 '"subkey"))))))
  )))))) (lambda '($41) (Member $41 '"key")) (lambda '($42 $43) (AggrNotEquals $42 (Member $43 '"key"))) (lambda '($44 $45) (block '(
    (let $46 (Chain1Map $45 (lambda '($47) (block '(
      (let $48 (Uint64 '1))
      (let $49 (Member $47 '"subkey"))
      (let $50 (AsStruct '('_yql_Rank0 $48) '('"key" (Member $47 '"key")) '('"subkey" $49)))
      (let $51 '($48 $48 (Apply $25 $49)))
      (return '($50 (AsStruct '('_yql_Rank0 $51))))
    ))) (lambda '($52 $53) (block '(
      (let $54 (Member $52 '"subkey"))
      (let $55 (Apply $25 $54))
      (let $56 (Member (Nth $53 '1) '_yql_Rank0))
      (let $57 (Inc (Nth $56 '1)))
      (let $58 (If (== $55 (Nth $56 '"2")) (Nth $56 '0) $57))
      (let $59 (AsStruct '('_yql_Rank0 $58) '('"key" (Member $52 '"key")) '('"subkey" $54)))
      (let $60 '($58 $57 $55))
      (return '($59 (AsStruct '('_yql_Rank0 $60))))
    )))))
    (return (OrderedMap $46 (lambda '($61) (Nth $61 '0))))
  )))))
  (let $27 (Bool 'true))
  (let $28 (Sort (Map $26 (lambda '($62) (block '(
    (let $63 (Member $62 '"subkey"))
    (return (AsStruct '('"ix" (Member $62 '_yql_Rank0)) '('"key" (Member $62 '"key")) '('"subkey" $63) '('"subkey_enc" (Apply $25 $63))))
  )))) '($27 $27) (lambda '($64) '((Member $64 '"key") (Member $64 '"ix")))))
  (let $29 (lambda '($65) (Member $65 '"ix") (Member $65 '"key") (Member $65 '"subkey") (Member $65 '"subkey_enc")))
  (return (FromFlow (ExpandMap $28 $29)))
))) $8))
(let $10 (DqCnMerge (TDqOutput $9 '0) '('('1 '"Asc") '('0 '"Asc"))))
(let $11 (DqPhyStage '($10) (lambda '($66) (FromFlow (NarrowMap (ToFlow $66) (lambda '($67 $68 $69 $70) (AsStruct '('"ix" $67) '('"key" $68) '('"subkey" $69) '('"subkey_enc" $70)))))) '('('"_logical_id" '3245) '('"_id" '"534f0ac8-5fbac5f2-ffb61213-1a41a4db"))))
(let $12 '($5 $9 $11))
(let $13 '('"key" '"ix" '"subkey" '"subkey_enc"))
(let $14 (DqCnResult (TDqOutput $11 '0) $13))
(return (KqpPhysicalQuery '((KqpPhysicalTx $12 '($14) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $7) '0 '0)) '('('"type" '"query"))))
)
