(
(declare %kqp%tx_result_binding_0_0 (OptionalType (StructType '('MaxBy0 (DataType 'String)))))
(let $1 (DataSource '"yt" '"/Root/plato"))
(let $2 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
(let $3 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $2)))
(let $4 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
(let $5 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
(let $6 (YtTable '"Input" $3 $4 $5 '() (Void) (Void) '"/Root/plato"))
(let $7 (Bool 'false))
(let $8 (DataType 'String))
(let $9 '('('"_logical_id" '4313) '('"_id" '"b713d089-f4179f75-b041f474-e8087489") '('"_wide_channels" (StructType '('_yql_agg_0 (TupleType $8 $8))))))
(let $10 (DqPhyStage '() (lambda '() (block '(
  (let $31 '('"key" '"subkey" '"value"))
  (let $32 (YtReadTable! world $1 '((YtSection '((YtPath $6 $31 (Void) (Void))) '()))))
  (let $33 (Condense1 (NarrowMap (WideFilter (DqReadWideWrap $32 '()) (lambda '($34 $35 $36) (> $36 (String '"a")))) (lambda '($37 $38 $39) (AsStruct '('"key" $37) '('"subkey" $38)))) (lambda '($40) '((Member $40 '"key") (Member $40 '"subkey"))) (lambda '($41 $42) $7) (lambda '($43 $44) (block '(
    (let $45 (Member $43 '"subkey"))
    (return (If (AggrLess (Nth $44 '1) $45) '((Member $43 '"key") $45) $44))
  )))))
  (return (FromFlow (ExpandMap $33 (lambda '($46) $46))))
))) $9))
(let $11 (DqCnUnionAll (TDqOutput $10 '0)))
(let $12 (OptionalType (StructType '('MaxBy0 $8))))
(let $13 (DqPhyStage '($11) (lambda '($47) (block '(
  (let $48 (lambda '($51) (Nth $51 '0) (Nth $51 '1)))
  (let $49 (lambda '($55 $56 $57) (block '(
    (let $58 (If (AggrLess $57 (Nth $55 '1)) $55 '($56 $57)))
    (return (Nth $58 '0) (Nth $58 '1))
  ))))
  (let $50 (WideCondense1 (ToFlow $47) $48 (lambda '($52 $53 $54) $7) $49))
  (return (FromFlow (Condense (NarrowMap (Take $50 (Uint64 '1)) (lambda '($59 $60) (AsStruct '('MaxBy0 $59)))) (Nothing $12) (lambda '($61 $62) $7) (lambda '($63 $64) (Just $63)))))
))) '('('"_logical_id" '5222) '('"_id" '"5653aa6d-dae4cb1c-12616f51-d10089f"))))
(let $14 (DqCnValue (TDqOutput $13 '0)))
(let $15 (KqpPhysicalTx '($10 $13) '($14) '() '('('"type" '"compute"))))
(let $16 '('('"_logical_id" '4179) '('"_id" '"9b55202c-2b557bb1-5aa61f60-3ef99536") '('"_wide_channels" (StructType '('"key" $8) '('"value" $8)))))
(let $17 (DqPhyStage '() (lambda '() (block '(
  (let $65 (YtReadTable! world $1 '((YtSection '((YtPath $6 '('"key" '"value") (Void) (Void))) '()))))
  (return (FromFlow (WideFilter (DqReadWideWrap $65 '()) (lambda '($66 $67) (> $66 (String '"050"))))))
))) $16))
(let $18 (DqCnBroadcast (TDqOutput $17 '0)))
(let $19 '"%kqp%tx_result_binding_0_0")
(let $20 (OptionalType $8))
(let $21 (StructType '('"a.key" $8) '('"b.value" $20) '('"max_key" $20)))
(let $22 '('('"_logical_id" '5553) '('"_id" '"2d80ca48-b25fe659-d37d8637-256a69a4") '('"_wide_channels" $21)))
(let $23 (DqPhyStage '($18) (lambda '($68) (block '(
  (let $69 '('Many 'Hashed 'Compact))
  (let $70 (NarrowSqueezeToDict (ToFlow $68) (lambda '($72 $73) $72) (lambda '($74 $75) (AsStruct '('"key" $74) '('"value" $75))) $69))
  (let $71 (lambda '($79 $80) $79 $80 (Member %kqp%tx_result_binding_0_0 'MaxBy0)))
  (return (FromFlow (WideMap (WideSort (FlatMap $70 (lambda '($76) (block '(
    (let $77 '('"key"))
    (let $78 (YtReadTable! world $1 '((YtSection '((YtPath $6 $77 (Void) (Void))) '()))))
    (return (MapJoinCore (DqReadWideWrap $78 '()) $76 'Left '('0) $77 '('0 '0) '('"value" '1) '('"a.key") '('"b.key")))
  )))) '('('0 (Bool 'true)))) $71)))
))) $22))
(let $24 (DqCnMerge (TDqOutput $23 '0) '('('0 '"Asc"))))
(let $25 (DqPhyStage '($24) (lambda '($81) (FromFlow (NarrowMap (ToFlow $81) (lambda '($82 $83 $84) (AsStruct '('"a.key" $82) '('"b.value" $83) '('"max_key" $84)))))) '('('"_logical_id" '5565) '('"_id" '"eafe6771-b5325de8-f3515f5-cc4db37e"))))
(let $26 '($17 $23 $25))
(let $27 '('"a.key" '"max_key" '"b.value"))
(let $28 (DqCnResult (TDqOutput $25 '0) $27))
(let $29 (KqpTxResultBinding $12 '0 '0))
(let $30 (KqpPhysicalTx $26 '($28) '('($19 $29)) '('('"type" '"generic"))))
(return (KqpPhysicalQuery '($15 $30) '((KqpTxResultBinding (ListType $21) '1 '0)) '('('"type" '"query"))))
)
