(
(let $1 (DataType 'String))
(let $2 '('"value" $1))
(let $3 (StructType '('"key" $1) '('"subkey" $1) $2))
(let $4 '('('"_logical_id" '10978) '('"_id" '"42fa022c-c221ef9f-730eb4e9-9ab6bb8b") '('"_wide_channels" $3)))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $19 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $20 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $19)))
  (let $21 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $22 (YtStat '('Id '"Input") '('RecordsCount '"30") '('DataSize '"1170") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $23 (YtTable '"Input" $20 $21 $22 '() (Void) (Void) '"/Root/plato"))
  (let $24 '('"key" '"subkey" '"value"))
  (let $25 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $23 $24 (Void) (Void))) '()))))
  (return (FromFlow (WideFilter (DqReadWideWrap $25 '()) (lambda '($26 $27 $28) (== $26 (String '1))))))
))) $4))
(let $6 (DqCnHashShuffle (TDqOutput $5 '0) '('0) '0 '"HashV2"))
(let $7 (OptionalType (DataType 'Uint32)))
(let $8 (DataType 'Uint64))
(let $9 (OptionalType $8))
(let $10 (OptionalType $1))
(let $11 (StructType '('"dvalue_lead1" $10) '('"sum1" $9) '('"sum2" $9) $2 '('"value_lag2" $7)))
(let $12 '('('"_logical_id" '12452) '('"_id" '"be877f92-7debed18-7c0bfd25-a5cbe709") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($6) (lambda '($29) (block '(
  (let $30 (NarrowSqueezeToDict (ToFlow $29) (lambda '($35 $36 $37) $35) (lambda '($38 $39 $40) (AsStruct '('"key" $38) '('"subkey" $39) '('"value" $40))) '('Auto 'Many)))
  (let $31 (Bool 'true))
  (let $32 (Chopper (OrderedFlatMap $30 (lambda '($41) (OrderedFlatMap (DictPayloads $41) (lambda '($42) (Sort $42 $31 (lambda '($43) (Member $43 '"value"))))))) (lambda '($44) (Member $44 '"key")) (lambda '($45 $46) (AggrNotEquals $45 (Member $46 '"key"))) (lambda '($47 $48) (block '(
    (let $49 (FromFlow $48))
    (let $50 (Uint64 '"3"))
    (let $51 (QueueCreate $3 (Uint64 '"8") $50 (DependsOn $49)))
    (let $52 (Uint64 '0))
    (let $53 (lambda '($81) $81))
    (let $54 (lambda '($82) (SafeCast (Unwrap (SafeCast (Member $82 '"subkey") $7)) $8)))
    (let $55 (lambda '($83 $84) (AggrAdd (SafeCast (Unwrap (SafeCast (Member $83 '"subkey") $7)) $8) $84)))
    (let $56 (Uint64 '"6"))
    (let $57 (lambda '($86) (Just (SafeCast $86 $8))))
    (let $58 (Nothing $9))
    (let $59 (lambda '($85) (IfPresent (SafeCast (Member $85 '"subkey") $7) $57 $58)))
    (let $60 (lambda '($87 $88) (block '(
      (let $89 (IfPresent (SafeCast (Member $87 '"subkey") $7) $57 $58))
      (return (AggrAdd $89 $88))
    ))))
    (let $61 (Uint64 '"2"))
    (let $62 (lambda '($90) (SafeCast (Member $90 '"value") $7)))
    (let $63 (Nothing $7))
    (let $64 (lambda '($91) (block '(
      (let $92 (Member $91 '"value"))
      (return (Just (Concat $92 $92)))
    ))))
    (let $65 (Nothing $10))
    (let $66 (Chain1Map (ToFlow (PreserveStream $49 $51 $50)) (lambda '($67) (block '(
      (let $68 (DependsOn $67))
      (let $69 (QueueRange $51 $52 $50 $68))
      (let $70 (Fold1 (FlatMap $69 $53) $54 $55))
      (let $71 (QueueRange $51 $50 $56 $68))
      (let $72 (Fold1 (FlatMap $71 $53) $59 $60))
      (let $73 (Member $67 '"subkey"))
      (let $74 (IfPresent (SafeCast $73 $7) $57 $58))
      (let $75 (QueuePeek $51 $61 $68))
      (let $76 (IfPresent $75 $62 $63))
      (let $77 (QueuePeek $51 $56 $68))
      (let $78 (IfPresent $77 $64 $65))
      (let $79 (AsStruct '('Sum0 $70) '('Sum1 (Coalesce $72 $74)) '('_yql_Lag0 $76) '('_yql_Lead0 $78) '('"key" (Member $67 '"key")) '('"subkey" $73) '('"value" (Member $67 '"value"))))
      (let $80 (AsStruct '('Sum0 (Void)) '('Sum1 (Void)) '('_yql_Lag0 (Void)) '('_yql_Lead0 (Void))))
      (return '($79 $80))
    ))) (lambda '($93 $94) (block '(
      (let $95 (DependsOn $93))
      (let $96 (QueueRange $51 $52 $50 $95))
      (let $97 (Fold1 (FlatMap $96 $53) $54 $55))
      (let $98 (QueueRange $51 $50 $56 $95))
      (let $99 (Fold1 (FlatMap $98 $53) $59 $60))
      (let $100 (Member $93 '"subkey"))
      (let $101 (IfPresent (SafeCast $100 $7) $57 $58))
      (let $102 (QueuePeek $51 $61 $95))
      (let $103 (IfPresent $102 $62 $63))
      (let $104 (QueuePeek $51 $56 $95))
      (let $105 (IfPresent $104 $64 $65))
      (let $106 (AsStruct '('Sum0 $97) '('Sum1 (Coalesce $99 $101)) '('_yql_Lag0 $103) '('_yql_Lead0 $105) '('"key" (Member $93 '"key")) '('"subkey" $100) '('"value" (Member $93 '"value"))))
      (return '($106 (Nth $94 '1)))
    )))))
    (return (OrderedMap $66 (lambda '($107) (block '(
      (let $108 (Nth $107 '0))
      (return (AsStruct '('Sum0 (Member $108 'Sum0)) '('Sum1 (Member $108 'Sum1)) '('_yql_Lag0 (Member $108 '_yql_Lag0)) '('_yql_Lead0 (Member $108 '_yql_Lead0)) '('"value" (Member $108 '"value"))))
    )))))
  )))))
  (let $33 (Sort (Map $32 (lambda '($109) (AsStruct '('"dvalue_lead1" (Member $109 '_yql_Lead0)) '('"sum1" (Member $109 'Sum0)) '('"sum2" (Member $109 'Sum1)) '('"value" (Member $109 '"value")) '('"value_lag2" (Member $109 '_yql_Lag0))))) $31 (lambda '($110) (Member $110 '"value"))))
  (let $34 (lambda '($111) (Member $111 '"dvalue_lead1") (Member $111 '"sum1") (Member $111 '"sum2") (Member $111 '"value") (Member $111 '"value_lag2")))
  (return (FromFlow (ExpandMap $33 $34)))
))) $12))
(let $14 (DqCnMerge (TDqOutput $13 '0) '('('"3" '"Asc"))))
(let $15 (DqPhyStage '($14) (lambda '($112) (FromFlow (NarrowMap (ToFlow $112) (lambda '($113 $114 $115 $116 $117) (AsStruct '('"dvalue_lead1" $113) '('"sum1" $114) '('"sum2" $115) '('"value" $116) '('"value_lag2" $117)))))) '('('"_logical_id" '12464) '('"_id" '"19f7d7de-c00e5fe8-f3f9026e-306b9b5f"))))
(let $16 '($5 $13 $15))
(let $17 '('"value" '"sum1" '"dvalue_lead1" '"sum2" '"value_lag2"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
