(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('('"_logical_id" '9298) '('"_id" '"93cb2251-a901bf7-f0adeda1-252b20f8") '('"_wide_channels" (StructType $2))))
(let $4 (DqPhyStage '() (lambda '() (block '(
  (let $16 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $17 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $16)))
  (let $18 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('HasRLS '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $19 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $20 (YtTable '"Input" $17 $18 $19 '() (Void) (Void) '"/Root/plato"))
  (let $21 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $20 '('"key") (Void) (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $21 '())))
))) $3))
(let $5 (DqCnUnionAll (TDqOutput $4 '0)))
(let $6 '('"running_max" $1))
(let $7 (OptionalType $1))
(let $8 (StructType $2 '('"keys" (ListType $1)) '('"next_key" $7) $6))
(let $9 '('('"_logical_id" '10470) '('"_id" '"8a48e6eb-d9e84c23-f03b1600-e9e7783") '('"_wide_channels" $8)))
(let $10 (DqPhyStage '($5) (lambda '($22) (block '(
  (let $23 (Bool 'true))
  (let $24 (FromFlow (NarrowMap (WideSort (ToFlow $22) '('('0 $23))) (lambda '($37) (AsStruct '('"key" $37))))))
  (let $25 (Chain1Map $24 (lambda '($38) (block '(
    (let $39 (Member $38 '"key"))
    (let $40 '('"running_max" $39))
    (return '((AsStruct '('"key" $39) $40) (AsStruct $40)))
  ))) (lambda '($41 $42) (block '(
    (let $43 (Member $41 '"key"))
    (let $44 '('"running_max" (AggrMax $43 (Member (Nth $42 '1) '"running_max"))))
    (return '((AsStruct '('"key" $43) $44) (AsStruct $44)))
  )))))
  (let $26 (StructType $2 $6))
  (let $27 (ListType $26))
  (let $28 (VariantType (StructType '('group $27) '('singleRow $26))))
  (let $29 (Condense1 $25 (lambda '($45) (block '(
    (let $46 (Nth $45 '0))
    (let $47 (Variant $46 'singleRow $28))
    (return '((Member $46 '"key") $47))
  ))) (lambda '($48 $49) (AggrNotEquals (Member (Nth $48 '0) '"key") (Nth $49 '0))) (lambda '($50 $51) (block '(
    (let $52 (Nth $50 '0))
    (let $53 (Visit (Nth $51 '1) 'group (lambda '($54) (Variant (Insert $54 $52) 'group $28)) 'singleRow (lambda '($55) (Variant (AsList $55 $52) 'group $28))))
    (return '((Nth $51 '0) $53))
  )))))
  (let $30 (QueueCreate $26 (Uint64 '"3") (Uint64 '0) (DependsOn $24)))
  (let $31 (Uint64 '1))
  (let $32 (lambda '($68) (Just (Member $68 '"key"))))
  (let $33 (Nothing $7))
  (let $34 (Chain1Map (ToFlow (PreserveStream (OrderedFlatMap $29 (lambda '($56) (Visit (Nth $56 '1) 'group (lambda '($57) (IfPresent (Last $57) (lambda '($58) (OrderedMap (Collect (Map $57 (lambda '($59) (AsStruct '('"key" (Member $59 '"key")))))) (lambda '($60) (AsStruct '('"key" (Member $60 '"key")) '('"running_max" (Member $58 '"running_max")))))) (List $27))) 'singleRow (lambda '($61) (AsList $61))))) $30 $31)) (lambda '($62) (block '(
    (let $63 (Member $62 '"key"))
    (let $64 '('"keys" (AsList $63)))
    (let $65 (QueuePeek $30 $31 (DependsOn $62)))
    (let $66 (IfPresent $65 $32 $33))
    (let $67 (AsStruct '('"key" $63) $64 '('"next_key" $66) '('"running_max" (Member $62 '"running_max"))))
    (return '($67 (AsStruct $64 '('"next_key" (Void)))))
  ))) (lambda '($69 $70) (block '(
    (let $71 (Member $69 '"key"))
    (let $72 (Nth $70 '1))
    (let $73 '('"keys" (Insert (Member $72 '"keys") $71)))
    (let $74 (QueuePeek $30 $31 (DependsOn $69)))
    (let $75 (IfPresent $74 $32 $33))
    (let $76 (AsStruct '('"key" $71) $73 '('"next_key" $75) '('"running_max" (Member $69 '"running_max"))))
    (return '($76 (AsStruct $73 '('"next_key" (Member $72 '"next_key")))))
  )))))
  (let $35 (Sort (OrderedMap $34 (lambda '($77) (Nth $77 '0))) $23 (lambda '($78) (Member $78 '"key"))))
  (let $36 (lambda '($79) (Member $79 '"key") (Member $79 '"keys") (Member $79 '"next_key") (Member $79 '"running_max")))
  (return (FromFlow (ExpandMap $35 $36)))
))) $9))
(let $11 (DqCnMerge (TDqOutput $10 '0) '('('0 '"Asc"))))
(let $12 (DqPhyStage '($11) (lambda '($80) (FromFlow (NarrowMap (ToFlow $80) (lambda '($81 $82 $83 $84) (AsStruct '('"key" $81) '('"keys" $82) '('"next_key" $83) '('"running_max" $84)))))) '('('"_logical_id" '10482) '('"_id" '"37e62b34-1b1dda-594c8bf7-a3c1e54"))))
(let $13 '($4 $10 $12))
(let $14 '('"key" '"running_max" '"next_key" '"keys"))
(let $15 (DqCnResult (TDqOutput $12 '0) $14))
(return (KqpPhysicalQuery '((KqpPhysicalTx $13 '($15) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $8) '0 '0)) '('('"type" '"query"))))
)
