(
(let $1 (OptionalType (DataType 'Int32)))
(let $2 '('"key" $1))
(let $3 '('"value" (DataType 'String)))
(let $4 (StructType $2 '('"subkey" $1) $3))
(let $5 '('('"_logical_id" '6664) '('"_id" '"2eccf-d036af29-40137340-79a56371") '('"_wide_channels" $4)))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $12 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $13 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $12)))
  (let $14 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $15 (YtStat '('Id '"Input") '('RecordsCount '"14") '('DataSize '"614") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $16 (YtTable '"Input" $13 $14 $15 '() (Void) (Void) '"/Root/plato"))
  (let $17 '('"key" '"subkey" '"value"))
  (let $18 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $16 $17 (Void) (Void))) '()))))
  (let $19 (lambda '($20 $21 $22) (SafeCast $20 $1) (SafeCast $21 $1) $22))
  (return (FromFlow (WideMap (DqReadWideWrap $18 '()) $19)))
))) $5))
(let $7 (DqCnUnionAll (TDqOutput $6 '0)))
(let $8 '('('"_logical_id" '6831) '('"_id" '"af3cfb0b-d77b6da-527c83e1-ee8affce") '('"_partition_mode" '"aggregate")))
(let $9 (DqPhyStage '($7) (lambda '($23) (block '(
  (let $24 (Bool 'true))
  (let $25 '('('0 $24) '('1 $24) '('2 $24)))
  (let $26 (FromFlow (NarrowMap (WideSort (ToFlow $23) $25) (lambda '($34 $35 $36) (AsStruct '('"key" $34) '('"subkey" $35) '('"value" $36))))))
  (let $27 (Uint64 '1))
  (let $28 (QueueCreate $4 (Uint64 '"3") $27 (DependsOn $26)))
  (let $29 (Uint64 '0))
  (let $30 (lambda '($44) (Member $44 '"key")))
  (let $31 (Nothing $1))
  (let $32 (lambda '($45) (Member $45 '"subkey")))
  (let $33 (Chain1Map (ToFlow (PreserveStream $26 $28 $29)) (lambda '($37) (block '(
    (let $38 (QueuePeek $28 $29 (DependsOn $37)))
    (let $39 (IfPresent $38 $30 $31))
    (let $40 (IfPresent $38 $32 $31))
    (let $41 '('_yql_RowNumber0 $27))
    (let $42 (AsStruct '('_yql_Lag0 $39) '('_yql_Lag1 $40) $41 '('"key" (Member $37 '"key")) '('"subkey" (Member $37 '"subkey")) '('"value" (Member $37 '"value"))))
    (let $43 (AsStruct '('_yql_Lag0 (Void)) '('_yql_Lag1 (Void)) $41))
    (return '($42 $43))
  ))) (lambda '($46 $47) (block '(
    (let $48 (QueuePeek $28 $29 (DependsOn $46)))
    (let $49 (IfPresent $48 $30 $31))
    (let $50 (IfPresent $48 $32 $31))
    (let $51 (Nth $47 '1))
    (let $52 '('_yql_RowNumber0 (Inc (Member $51 '_yql_RowNumber0))))
    (let $53 (AsStruct '('_yql_Lag0 $49) '('_yql_Lag1 $50) $52 '('"key" (Member $46 '"key")) '('"subkey" (Member $46 '"subkey")) '('"value" (Member $46 '"value"))))
    (let $54 (AsStruct '('_yql_Lag0 (Member $51 '_yql_Lag0)) '('_yql_Lag1 (Member $51 '_yql_Lag1)) $52))
    (return '($53 $54))
  )))))
  (return (FromFlow (OrderedMap $33 (lambda '($55) (block '(
    (let $56 (Nth $55 '0))
    (let $57 (Member $56 '"key"))
    (return (AsStruct '('"key" $57) '('"key_diff" (- $57 (Member $56 '_yql_Lag0))) '('"row" (Member $56 '_yql_RowNumber0)) '('"subkey_diff" (- (Member $56 '"subkey") (Member $56 '_yql_Lag1))) '('"value" (Member $56 '"value"))))
  ))))))
))) $8))
(let $10 '('"key" '"key_diff" '"subkey_diff" '"row" '"value"))
(let $11 (DqCnResult (TDqOutput $9 '0) $10))
(return (KqpPhysicalQuery '((KqpPhysicalTx '($6 $9) '($11) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType $2 '('"key_diff" $1) '('"row" (DataType 'Uint64)) '('"subkey_diff" $1) $3)) '0 '0)) '('('"type" '"query"))))
)
