(
(let $1 (DataType 'String))
(let $2 '('"subkey" $1))
(let $3 '('"value" $1))
(let $4 (StructType '('"key" $1) $2 $3))
(let $5 '('('"_logical_id" '11752) '('"_id" '"a06c3506-9f3c586f-7b67940c-7709360f") '('"_wide_channels" $4)))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $27 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $28 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $27)))
  (let $29 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $30 (YtStat '('Id '"Input") '('RecordsCount '"30") '('DataSize '"1170") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $31 (YtTable '"Input" $28 $29 $30 '() (Void) (Void) '"/Root/plato"))
  (let $32 '('"key" '"subkey" '"value"))
  (let $33 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $31 $32 (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $33 '())))
))) $5))
(let $7 (DqCnHashShuffle (TDqOutput $6 '0) '('0) '0 '"HashV2"))
(let $8 (Bool 'true))
(let $9 (Uint64 '0))
(let $10 (Uint64 '3))
(let $11 (OptionalType (DataType 'Uint64)))
(let $12 (Nothing $11))
(let $13 (OptionalType $1))
(let $14 (StructType '('Sum0 $11) '('_yql_Lead0 $13) $2 $3))
(let $15 '('('"_logical_id" '12560) '('"_id" '"665bd4c8-b67cdd8a-b7ab12a2-6e602f88") '('"_wide_channels" $14)))
(let $16 (DqPhyStage '($7) (lambda '($34) (block '(
  (let $35 (NarrowSqueezeToDict (ToFlow $34) (lambda '($38 $39 $40) $38) (lambda '($41 $42 $43) (AsStruct '('"key" $41) '('"subkey" $42) '('"value" $43))) '('Auto 'Many)))
  (let $36 (Chopper (OrderedFlatMap $35 (lambda '($44) (OrderedFlatMap (DictPayloads $44) (lambda '($45) (Sort $45 $8 (lambda '($46) (Member $46 '"value"))))))) (lambda '($47) (Member $47 '"key")) (lambda '($48 $49) (AggrNotEquals $48 (Member $49 '"key"))) (lambda '($50 $51) (block '(
    (let $52 (FromFlow $51))
    (let $53 (QueueCreate $4 (Uint64 '"5") $9 (DependsOn $52)))
    (let $54 '('Sum0 $12))
    (let $55 (lambda '($62) (block '(
      (let $63 (Member $62 '"value"))
      (return (Just (Concat $63 $63)))
    ))))
    (let $56 (Nothing $13))
    (let $57 (Chain1Map (ToFlow (PreserveStream $52 $53 $10)) (lambda '($58) (block '(
      (let $59 (QueuePeek $53 $10 (DependsOn $58)))
      (let $60 (IfPresent $59 $55 $56))
      (let $61 (AsStruct $54 '('_yql_Lead0 $60) '('"key" (Member $58 '"key")) '('"subkey" (Member $58 '"subkey")) '('"value" (Member $58 '"value"))))
      (return '($61 (AsStruct '('Sum0 (Void)) '('_yql_Lead0 (Void)))))
    ))) (lambda '($64 $65) (block '(
      (let $66 (QueuePeek $53 $10 (DependsOn $64)))
      (let $67 (IfPresent $66 $55 $56))
      (let $68 (AsStruct $54 '('_yql_Lead0 $67) '('"key" (Member $64 '"key")) '('"subkey" (Member $64 '"subkey")) '('"value" (Member $64 '"value"))))
      (return '($68 (Nth $65 '1)))
    )))))
    (return (OrderedMap $57 (lambda '($69) (block '(
      (let $70 (Nth $69 '0))
      (return (AsStruct '('Sum0 (Member $70 'Sum0)) '('_yql_Lead0 (Member $70 '_yql_Lead0)) '('"subkey" (Member $70 '"subkey")) '('"value" (Member $70 '"value"))))
    )))))
  )))))
  (let $37 (lambda '($71) (Member $71 'Sum0) (Member $71 '_yql_Lead0) (Member $71 '"subkey") (Member $71 '"value")))
  (return (FromFlow (ExpandMap $36 $37)))
))) $15))
(let $17 (DqCnUnionAll (TDqOutput $16 '0)))
(let $18 (OptionalType (DataType 'Uint32)))
(let $19 (StructType '('"dvalue_lead1" $13) '('"sum1" $11) '('"sum2" $11) $3 '('"value_lag2" $18)))
(let $20 '('('"_logical_id" '13940) '('"_id" '"7e99d85d-da6f764b-1314830e-eed102dc") '('"_wide_channels" $19)))
(let $21 (DqPhyStage '($17) (lambda '($72) (block '(
  (let $73 (FromFlow (NarrowMap (WideSort (ToFlow $72) '('('3 (Bool 'false)))) (lambda '($81 $82 $83 $84) (AsStruct '('Sum0 $81) '('_yql_Lead0 $82) '('"subkey" $83) '('"value" $84))))))
  (let $74 (QueueCreate $14 $10 (Uint64 '1) (DependsOn $73)))
  (let $75 '('Sum1 $12))
  (let $76 (lambda '($89) (SafeCast (Member $89 '"value") $18)))
  (let $77 (Nothing $18))
  (let $78 (Chain1Map (ToFlow (PreserveStream $73 $74 $9)) (lambda '($85) (block '(
    (let $86 (QueuePeek $74 $9 (DependsOn $85)))
    (let $87 (IfPresent $86 $76 $77))
    (let $88 (AsStruct '('Sum0 (Member $85 'Sum0)) $75 '('_yql_Lag0 $87) '('_yql_Lead0 (Member $85 '_yql_Lead0)) '('"subkey" (Member $85 '"subkey")) '('"value" (Member $85 '"value"))))
    (return '($88 (AsStruct '('Sum1 (Void)) '('_yql_Lag0 (Void)))))
  ))) (lambda '($90 $91) (block '(
    (let $92 (QueuePeek $74 $9 (DependsOn $90)))
    (let $93 (IfPresent $92 $76 $77))
    (let $94 (AsStruct '('Sum0 (Member $90 'Sum0)) $75 '('_yql_Lag0 $93) '('_yql_Lead0 (Member $90 '_yql_Lead0)) '('"subkey" (Member $90 '"subkey")) '('"value" (Member $90 '"value"))))
    (return '($94 (Nth $91 '1)))
  )))))
  (let $79 (Sort (Map $78 (lambda '($95) (block '(
    (let $96 (Nth $95 '0))
    (return (AsStruct '('"dvalue_lead1" (Member $96 '_yql_Lead0)) '('"sum1" (Member $96 'Sum0)) '('"sum2" (Member $96 'Sum1)) '('"value" (Member $96 '"value")) '('"value_lag2" (Member $96 '_yql_Lag0))))
  )))) $8 (lambda '($97) (Member $97 '"value"))))
  (let $80 (lambda '($98) (Member $98 '"dvalue_lead1") (Member $98 '"sum1") (Member $98 '"sum2") (Member $98 '"value") (Member $98 '"value_lag2")))
  (return (FromFlow (ExpandMap $79 $80)))
))) $20))
(let $22 (DqCnMerge (TDqOutput $21 '0) '('('3 '"Asc"))))
(let $23 (DqPhyStage '($22) (lambda '($99) (FromFlow (NarrowMap (ToFlow $99) (lambda '($100 $101 $102 $103 $104) (AsStruct '('"dvalue_lead1" $100) '('"sum1" $101) '('"sum2" $102) '('"value" $103) '('"value_lag2" $104)))))) '('('"_logical_id" '13952) '('"_id" '"4aebd6ae-f70c3141-24313d2f-3da7e80c"))))
(let $24 '($6 $16 $21 $23))
(let $25 '('"value" '"sum1" '"dvalue_lead1" '"sum2" '"value_lag2"))
(let $26 (DqCnResult (TDqOutput $23 '0) $25))
(return (KqpPhysicalQuery '((KqpPhysicalTx $24 '($26) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $19) '0 '0)) '('('"type" '"query"))))
)
