(
(let $1 (DataType 'Int32))
(let $2 '('"payload" $1))
(let $3 (OptionalType $1))
(let $4 '('"ts" $3))
(let $5 (DataType 'String))
(let $6 '('"user" (OptionalType $5)))
(let $7 '('"user_nonopt" $5))
(let $8 (StructType $2 $4 $6 $7))
(let $9 '('('"_logical_id" '7077) '('"_id" '"133ecbe6-5fbfa343-fe09d72d-6a237ee8") '('"_wide_channels" $8)))
(let $10 (DqPhyStage '() (lambda '() (block '(
  (let $20 '@@["StructType";[["user";["OptionalType";["DataType";"String"]]];["ts";["OptionalType";["DataType";"Int32"]]];["payload";["DataType";"Int32"]]]]@@)
  (let $21 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $20)))
  (let $22 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $23 (YtStat '('Id '"Input") '('RecordsCount '"18") '('DataSize '"655") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $24 (YtTable '"Input" $21 $22 $23 '() (Void) (Void) '"/Root/plato"))
  (let $25 '('"payload" '"ts" '"user"))
  (let $26 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $24 $25 (Void) (Void))) '()))))
  (let $27 (lambda '($28 $29 $30) $28 $29 $30 (Coalesce $30 (String '"u0"))))
  (return (FromFlow (WideMap (DqReadWideWrap $26 '()) $27)))
))) $9))
(let $11 (DqCnHashShuffle (TDqOutput $10 '0) '('2 '"3") '0 '"HashV2"))
(let $12 (StructType '('"full_session" (ListType $8)) $2 '('"session_len" (DataType 'Uint64)) $4 $6 $7))
(let $13 '('('"_logical_id" '8040) '('"_id" '"3a39d82a-7298e4e-754c29c7-a8636e1b") '('"_wide_channels" $12)))
(let $14 (DqPhyStage '($11) (lambda '($31) (block '(
  (let $32 (NarrowSqueezeToDict (ToFlow $31) (lambda '($40 $41 $42 $43) '($42 $43)) (lambda '($44 $45 $46 $47) (AsStruct '('"payload" $44) '('"ts" $45) '('"user" $46) '('"user_nonopt" $47))) '('Auto 'Many)))
  (let $33 (Bool 'true))
  (let $34 (Chain1Map (OrderedFlatMap $32 (lambda '($48) (OrderedFlatMap (DictPayloads $48) (lambda '($49) (Sort $49 $33 (lambda '($50) (Member $50 '"ts"))))))) (lambda '($51) (block '(
    (let $52 (Member $51 '"ts"))
    (return '($51 $52 $52 '((Member $51 '"user") (Member $51 '"user_nonopt"))))
  ))) (lambda '($53 $54) (block '(
    (let $55 (Member $53 '"user"))
    (let $56 (Nth $54 '0))
    (let $57 (Member $53 '"user_nonopt"))
    (let $58 (Member $53 '"ts"))
    (let $59 '($55 $57))
    (let $60 '($53 $58 $58 $59))
    (let $61 (Nth $54 '2))
    (let $62 (If (Coalesce (< $61 $58) $33) (- $58 $61) (- $61 $58)))
    (let $63 (If (And (AggrNotEquals $58 $61) (Coalesce (< (Int32 '"10") $62) $33)) $58 (Nth $54 '1)))
    (let $64 '($53 $63 $58 $59))
    (return (If (Or (AggrNotEquals $55 (Member $56 '"user")) (AggrNotEquals $57 (Member $56 '"user_nonopt"))) $60 $64))
  )))))
  (let $35 '"_yql_window_session_params")
  (let $36 '"_yql_window_session_start")
  (let $37 (Chopper (OrderedMap $34 (lambda '($65) (block '(
    (let $66 (Nth $65 '1))
    (let $67 (Nth $65 '0))
    (return (AsStruct '($35 (AsStruct '('start $66) '('state (Nth $65 '2)))) '($36 $66) '('"payload" (Member $67 '"payload")) '('"ts" (Member $67 '"ts")) '('"user" (Member $67 '"user")) '('"user_nonopt" (Member $67 '"user_nonopt"))))
  )))) (lambda '($68) '('((Member $68 '"user") (Member $68 '"user_nonopt")) (Member $68 $36))) (lambda '($69 $70) (block '(
    (let $71 (Nth $69 '0))
    (return (Or (AggrNotEquals (Nth $71 '0) (Member $70 '"user")) (AggrNotEquals (Nth $71 '1) (Member $70 '"user_nonopt")) (AggrNotEquals (Nth $69 '1) (Member $70 $36))))
  ))) (lambda '($72 $73) (block '(
    (let $74 (FromFlow $73))
    (let $75 (StructType '($35 (StructType '('start $3) '('state $3))) '($36 $3) $2 $4 $6 $7))
    (let $76 (QueueCreate $75 (Void) (Uint64 '0) (DependsOn $74)))
    (let $77 (Uint64 '"18446744073709551615"))
    (let $78 (Chain1Map (ToFlow (PreserveStream $74 $76 $77)) (lambda '($79) (block '(
      (let $80 (Uint64 '1))
      (let $81 (QueueRange $76 $80 $77 (DependsOn $79)))
      (let $82 (FlatMap $81 (lambda '($92) $92)))
      (let $83 '('"payload" (Member $79 '"payload")))
      (let $84 '('"ts" (Member $79 '"ts")))
      (let $85 '('"user" (Member $79 '"user")))
      (let $86 '('"user_nonopt" (Member $79 '"user_nonopt")))
      (let $87 (Fold $82 (AsList (AsStruct $83 $84 $85 $86)) (lambda '($93 $94) (block '(
        (let $95 (AsStruct '('"payload" (Member $93 '"payload")) '('"ts" (Member $93 '"ts")) '('"user" (Member $93 '"user")) '('"user_nonopt" (Member $93 '"user_nonopt"))))
        (return (Insert $94 $95))
      )))))
      (let $88 '('AggregateList0 $87))
      (let $89 (Fold $82 $80 (lambda '($96 $97) (Inc $97))))
      (let $90 '('Count0 $89))
      (let $91 (AsStruct $88 $90 '($35 (Member $79 $35)) '($36 (Member $79 $36)) $83 $84 $85 $86))
      (return '($91 (AsStruct $88 $90)))
    ))) (lambda '($98 $99) (block '(
      (let $100 (Nth $99 '1))
      (let $101 (AsStruct '('AggregateList0 (Member $100 'AggregateList0)) '('Count0 (Member $100 'Count0)) '($35 (Member $98 $35)) '($36 (Member $98 $36)) '('"payload" (Member $98 '"payload")) '('"ts" (Member $98 '"ts")) '('"user" (Member $98 '"user")) '('"user_nonopt" (Member $98 '"user_nonopt"))))
      (return '($101 $100))
    )))))
    (return (OrderedMap $78 (lambda '($102) (block '(
      (let $103 (Nth $102 '0))
      (return (AsStruct '('AggregateList0 (Member $103 'AggregateList0)) '('Count0 (Member $103 'Count0)) '('"payload" (Member $103 '"payload")) '('"ts" (Member $103 '"ts")) '('"user" (Member $103 '"user")) '('"user_nonopt" (Member $103 '"user_nonopt"))))
    )))))
  )))))
  (let $38 (Sort (Map $37 (lambda '($104) (AsStruct '('"full_session" (Member $104 'AggregateList0)) '('"payload" (Member $104 '"payload")) '('"session_len" (Member $104 'Count0)) '('"ts" (Member $104 '"ts")) '('"user" (Member $104 '"user")) '('"user_nonopt" (Member $104 '"user_nonopt"))))) '($33 $33) (lambda '($105) '((Member $105 '"user") (Member $105 '"payload")))))
  (let $39 (lambda '($106) (Member $106 '"full_session") (Member $106 '"payload") (Member $106 '"session_len") (Member $106 '"ts") (Member $106 '"user") (Member $106 '"user_nonopt")))
  (return (FromFlow (ExpandMap $38 $39)))
))) $13))
(let $15 (DqCnMerge (TDqOutput $14 '0) '('('"4" '"Asc") '('1 '"Asc"))))
(let $16 (DqPhyStage '($15) (lambda '($107) (FromFlow (NarrowMap (ToFlow $107) (lambda '($108 $109 $110 $111 $112 $113) (AsStruct '('"full_session" $108) '('"payload" $109) '('"session_len" $110) '('"ts" $111) '('"user" $112) '('"user_nonopt" $113)))))) '('('"_logical_id" '8052) '('"_id" '"f27a7a66-a62b79b9-14fe61f3-bc124208"))))
(let $17 '($10 $14 $16))
(let $18 '('"user" '"user_nonopt" '"ts" '"payload" '"full_session" '"session_len"))
(let $19 (DqCnResult (TDqOutput $16 '0) $18))
(return (KqpPhysicalQuery '((KqpPhysicalTx $17 '($19) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $12) '0 '0)) '('('"type" '"query"))))
)
