(
(let $1 (DataType 'String))
(let $2 '('"key" $1))
(let $3 '('"value" $1))
(let $4 (StructType $2 $3))
(let $5 '('('"_logical_id" '10795) '('"_id" '"310c077f-db73cd32-8827e9d4-9c4482c1") '('"_wide_channels" $4)))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $25 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $26 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $25)))
  (let $27 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $28 (YtStat '('Id '"Input") '('RecordsCount '"30") '('DataSize '"1170") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $29 (YtTable '"Input" $26 $27 $28 '() (Void) (Void) '"/Root/plato"))
  (let $30 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $29 '('"key" '"value") (Void) (Void))) '()))))
  (return (FromFlow (WideFilter (DqReadWideWrap $30 '()) (lambda '($31 $32) (== $31 (String '1))))))
))) $5))
(let $7 (DqCnUnionAll (TDqOutput $6 '0)))
(let $8 (Bool 'true))
(let $9 (Uint64 '0))
(let $10 (Uint64 '"3"))
(let $11 (OptionalType $1))
(let $12 (StructType '('_yql_Lead0 $11) $2 $3))
(let $13 '('('"_logical_id" '10920) '('"_id" '"1d7ae12b-4c9eb619-7e9c662f-c8c29bf") '('"_partition_mode" '"aggregate") '('"_wide_channels" $12)))
(let $14 (DqPhyStage '($7) (lambda '($33) (block '(
  (let $34 (FromFlow (NarrowMap (WideSort (ToFlow $33) '('('1 $8))) (lambda '($40 $41) (AsStruct '('"key" $40) '('"value" $41))))))
  (let $35 (QueueCreate $4 (Uint64 '"5") $9 (DependsOn $34)))
  (let $36 (lambda '($46) (block '(
    (let $47 (Member $46 '"value"))
    (return (Just (Concat $47 $47)))
  ))))
  (let $37 (Nothing $11))
  (let $38 (Chain1Map (ToFlow (PreserveStream $34 $35 $10)) (lambda '($42) (block '(
    (let $43 (QueuePeek $35 $10 (DependsOn $42)))
    (let $44 (IfPresent $43 $36 $37))
    (let $45 (AsStruct '('_yql_Lead0 $44) '('"key" (Member $42 '"key")) '('"value" (Member $42 '"value"))))
    (return '($45 (AsStruct '('_yql_Lead0 (Void)))))
  ))) (lambda '($48 $49) (block '(
    (let $50 (QueuePeek $35 $10 (DependsOn $48)))
    (let $51 (IfPresent $50 $36 $37))
    (let $52 (AsStruct '('_yql_Lead0 $51) '('"key" (Member $48 '"key")) '('"value" (Member $48 '"value"))))
    (return '($52 (Nth $49 '1)))
  )))))
  (let $39 (lambda '($53) (block '(
    (let $54 (Nth $53 '0))
    (return (Member $54 '_yql_Lead0) (Member $54 '"key") (Member $54 '"value"))
  ))))
  (return (FromFlow (ExpandMap $38 $39)))
))) $13))
(let $15 (DqCnHashShuffle (TDqOutput $14 '0) '('1) '0 '"HashV2"))
(let $16 (OptionalType (DataType 'Uint32)))
(let $17 (StructType '('"dvalue_lead1" $11) $3 '('"value_lag2" $16)))
(let $18 '('('"_logical_id" '12651) '('"_id" '"457287ba-9b8a5f84-4b1076cc-b25232c6") '('"_wide_channels" $17)))
(let $19 (DqPhyStage '($15) (lambda '($55) (block '(
  (let $56 (NarrowSqueezeToDict (ToFlow $55) (lambda '($60 $61 $62) $61) (lambda '($63 $64 $65) (AsStruct '('_yql_Lead0 $63) '('"key" $64) '('"value" $65))) '('Auto 'Many)))
  (let $57 (Chopper (OrderedFlatMap $56 (lambda '($66) (OrderedFlatMap (DictPayloads $66) (lambda '($67) (Sort $67 (Bool 'false) (lambda '($68) (Member $68 '"value"))))))) (lambda '($69) (Member $69 '"key")) (lambda '($70 $71) (AggrNotEquals $70 (Member $71 '"key"))) (lambda '($72 $73) (block '(
    (let $74 (FromFlow $73))
    (let $75 (QueueCreate $12 $10 (Uint64 '1) (DependsOn $74)))
    (let $76 (lambda '($83) (SafeCast (Member $83 '"value") $16)))
    (let $77 (Nothing $16))
    (let $78 (Chain1Map (ToFlow (PreserveStream $74 $75 $9)) (lambda '($79) (block '(
      (let $80 (QueuePeek $75 $9 (DependsOn $79)))
      (let $81 (IfPresent $80 $76 $77))
      (let $82 (AsStruct '('_yql_Lag0 $81) '('_yql_Lead0 (Member $79 '_yql_Lead0)) '('"key" (Member $79 '"key")) '('"value" (Member $79 '"value"))))
      (return '($82 (AsStruct '('_yql_Lag0 (Void)))))
    ))) (lambda '($84 $85) (block '(
      (let $86 (QueuePeek $75 $9 (DependsOn $84)))
      (let $87 (IfPresent $86 $76 $77))
      (let $88 (AsStruct '('_yql_Lag0 $87) '('_yql_Lead0 (Member $84 '_yql_Lead0)) '('"key" (Member $84 '"key")) '('"value" (Member $84 '"value"))))
      (return '($88 (Nth $85 '1)))
    )))))
    (return (OrderedMap $78 (lambda '($89) (block '(
      (let $90 (Nth $89 '0))
      (return (AsStruct '('_yql_Lag0 (Member $90 '_yql_Lag0)) '('_yql_Lead0 (Member $90 '_yql_Lead0)) '('"value" (Member $90 '"value"))))
    )))))
  )))))
  (let $58 (Sort (Map $57 (lambda '($91) (AsStruct '('"dvalue_lead1" (Member $91 '_yql_Lead0)) '('"value" (Member $91 '"value")) '('"value_lag2" (Member $91 '_yql_Lag0))))) $8 (lambda '($92) (Member $92 '"value"))))
  (let $59 (lambda '($93) (Member $93 '"dvalue_lead1") (Member $93 '"value") (Member $93 '"value_lag2")))
  (return (FromFlow (ExpandMap $58 $59)))
))) $18))
(let $20 (DqCnMerge (TDqOutput $19 '0) '('('1 '"Asc"))))
(let $21 (DqPhyStage '($20) (lambda '($94) (FromFlow (NarrowMap (ToFlow $94) (lambda '($95 $96 $97) (AsStruct '('"dvalue_lead1" $95) '('"value" $96) '('"value_lag2" $97)))))) '('('"_logical_id" '12663) '('"_id" '"5e0809cf-ba54d442-eef62608-98a5704c"))))
(let $22 '($6 $14 $19 $21))
(let $23 '('"value" '"dvalue_lead1" '"value_lag2"))
(let $24 (DqCnResult (TDqOutput $21 '0) $23))
(return (KqpPhysicalQuery '((KqpPhysicalTx $22 '($24) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $17) '0 '0)) '('('"type" '"query"))))
)
