(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"subkey" $1))
(let $4 '('"value" $1))
(let $5 (StructType $2 $3 $4))
(let $6 '('('"_logical_id" '9305) '('"_id" '"9198b17b-797a96b2-899da70f-d984430b") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $18 '@@["StructType";[["value";["DataType";"String"]];["subkey";["DataType";"String"]];["key";["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 '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $22 (YtTable '"Input" $19 $20 $21 '() (Void) (Void) '"/Root/plato"))
  (let $23 '('"key" '"subkey" '"value"))
  (let $24 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $22 $23 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $24 '())))
))) $6))
(let $8 (DqCnUnionAll (TDqOutput $7 '0)))
(let $9 (OptionalType $1))
(let $10 (StructType $2 '('"min_k" $1) '('"prev_k" $9) $3 $4))
(let $11 '('('"_logical_id" '10609) '('"_id" '"fd5956ea-78d863c9-3cddf8bd-9dc1b1c2") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '($8) (lambda '($25) (block '(
  (let $26 (Bool 'true))
  (let $27 (FromFlow (NarrowMap (WideSort (ToFlow $25) '('('1 $26))) (lambda '($40 $41 $42) (AsStruct '('"key" $40) '('"subkey" $41) '('"value" $42))))))
  (let $28 (Chain1Map $27 (lambda '($43) (block '(
    (let $44 (Member $43 '"key"))
    (let $45 '('Min0 $44))
    (let $46 (AsStruct $45 '('"key" $44) '('"subkey" (Member $43 '"subkey")) '('"value" (Member $43 '"value"))))
    (return '($46 (AsStruct $45)))
  ))) (lambda '($47 $48) (block '(
    (let $49 (Member $47 '"key"))
    (let $50 '('Min0 (AggrMin $49 (Member (Nth $48 '1) 'Min0))))
    (let $51 (AsStruct $50 '('"key" $49) '('"subkey" (Member $47 '"subkey")) '('"value" (Member $47 '"value"))))
    (return '($51 (AsStruct $50)))
  )))))
  (let $29 (StructType '('Min0 $1) $2 $3 $4))
  (let $30 (ListType $29))
  (let $31 (VariantType (StructType '('group $30) '('singleRow $29))))
  (let $32 (Condense1 $28 (lambda '($52) (block '(
    (let $53 (Nth $52 '0))
    (let $54 (Variant $53 'singleRow $31))
    (return '((Member $53 '"subkey") $54))
  ))) (lambda '($55 $56) (AggrNotEquals (Member (Nth $55 '0) '"subkey") (Nth $56 '0))) (lambda '($57 $58) (block '(
    (let $59 (Nth $57 '0))
    (let $60 (Visit (Nth $58 '1) 'group (lambda '($61) (Variant (Insert $61 $59) 'group $31)) 'singleRow (lambda '($62) (Variant (AsList $62 $59) 'group $31))))
    (return '((Nth $58 '0) $60))
  )))))
  (let $33 (QueueCreate $29 (Uint64 '"3") (Uint64 '1) (DependsOn $27)))
  (let $34 (Uint64 '0))
  (let $35 (lambda '($73) (Just (Member $73 '"key"))))
  (let $36 (Nothing $9))
  (let $37 (Chain1Map (ToFlow (PreserveStream (OrderedFlatMap $32 (lambda '($63) (Visit (Nth $63 '1) 'group (lambda '($64) (IfPresent (Last $64) (lambda '($65) (OrderedMap (Collect (Map $64 (lambda '($66) (AsStruct '('"key" (Member $66 '"key")) '('"subkey" (Member $66 '"subkey")) '('"value" (Member $66 '"value")))))) (lambda '($67) (AsStruct '('Min0 (Member $65 'Min0)) '('"key" (Member $67 '"key")) '('"subkey" (Member $67 '"subkey")) '('"value" (Member $67 '"value")))))) (List $30))) 'singleRow (lambda '($68) (AsList $68))))) $33 $34)) (lambda '($69) (block '(
    (let $70 (QueuePeek $33 $34 (DependsOn $69)))
    (let $71 (IfPresent $70 $35 $36))
    (let $72 (AsStruct '('Min0 (Member $69 'Min0)) '('_yql_Lag0 $71) '('"key" (Member $69 '"key")) '('"subkey" (Member $69 '"subkey")) '('"value" (Member $69 '"value"))))
    (return '($72 (AsStruct '('_yql_Lag0 (Void)))))
  ))) (lambda '($74 $75) (block '(
    (let $76 (QueuePeek $33 $34 (DependsOn $74)))
    (let $77 (IfPresent $76 $35 $36))
    (let $78 (AsStruct '('Min0 (Member $74 'Min0)) '('_yql_Lag0 $77) '('"key" (Member $74 '"key")) '('"subkey" (Member $74 '"subkey")) '('"value" (Member $74 '"value"))))
    (return '($78 (Nth $75 '1)))
  )))))
  (let $38 (Sort (Map $37 (lambda '($79) (block '(
    (let $80 (Nth $79 '0))
    (return (AsStruct '('"key" (Member $80 '"key")) '('"min_k" (Member $80 'Min0)) '('"prev_k" (Member $80 '_yql_Lag0)) '('"subkey" (Member $80 '"subkey")) '('"value" (Member $80 '"value"))))
  )))) $26 (lambda '($81) (Member $81 '"subkey"))))
  (let $39 (lambda '($82) (Member $82 '"key") (Member $82 '"min_k") (Member $82 '"prev_k") (Member $82 '"subkey") (Member $82 '"value")))
  (return (FromFlow (ExpandMap $38 $39)))
))) $11))
(let $13 (DqCnMerge (TDqOutput $12 '0) '('('"3" '"Asc"))))
(let $14 (DqPhyStage '($13) (lambda '($83) (FromFlow (NarrowMap (ToFlow $83) (lambda '($84 $85 $86 $87 $88) (AsStruct '('"key" $84) '('"min_k" $85) '('"prev_k" $86) '('"subkey" $87) '('"value" $88)))))) '('('"_logical_id" '10621) '('"_id" '"9197be54-c43e0ebf-16d09669-e14504f9"))))
(let $15 '($7 $12 $14))
(let $16 '('"value" '"subkey" '"key" '"prev_k" '"min_k"))
(let $17 (DqCnResult (TDqOutput $14 '0) $16))
(return (KqpPhysicalQuery '((KqpPhysicalTx $15 '($17) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $10) '0 '0)) '('('"type" '"query"))))
)
