(
(let $1 (DataType 'Int32))
(let $2 '('"payload" $1))
(let $3 (OptionalType $1))
(let $4 '('"ts" $3))
(let $5 '('"user" (OptionalType (DataType 'String))))
(let $6 (StructType $2 $4 $5))
(let $7 '('('"_logical_id" '6661) '('"_id" '"a5e4055e-696e29f8-e1b5c80-705ef973") '('"_wide_channels" $6)))
(let $8 (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))) '()))))
  (return (FromFlow (DqReadWideWrap $26 '())))
))) $7))
(let $9 (DqCnHashShuffle (TDqOutput $8 '0) '('2) '0 '"HashV2"))
(let $10 (ListType $1))
(let $11 (DataType 'Uint64))
(let $12 (StructType $2 '('"session_len" $11) $4 '('"ts_session" $10) $5))
(let $13 '('('"_logical_id" '7159) '('"_id" '"2b4a00b1-fbcc7645-89041e8a-6f232153") '('"_wide_channels" $12)))
(let $14 (DqPhyStage '($9) (lambda '($27) (block '(
  (let $28 (NarrowSqueezeToDict (ToFlow $27) (lambda '($36 $37 $38) $38) (lambda '($39 $40 $41) (AsStruct '('"payload" $39) '('"ts" $40) '('"user" $41))) '('Auto 'Many)))
  (let $29 (Bool 'true))
  (let $30 (Chain1Map (OrderedFlatMap $28 (lambda '($42) (OrderedFlatMap (DictPayloads $42) (lambda '($43) (Sort $43 $29 (lambda '($44) (Member $44 '"ts"))))))) (lambda '($45) (block '(
    (let $46 (Member $45 '"ts"))
    (return '($45 $46 $46 (Member $45 '"user")))
  ))) (lambda '($47 $48) (block '(
    (let $49 (Member $47 '"user"))
    (let $50 (Member $47 '"ts"))
    (let $51 '($47 $50 $50 $49))
    (let $52 (Nth $48 '2))
    (let $53 (If (Coalesce (< $52 $50) $29) (- $50 $52) (- $52 $50)))
    (let $54 (If (And (AggrNotEquals $50 $52) (Coalesce (< (Int32 '"10") $53) $29)) $50 (Nth $48 '1)))
    (let $55 '($47 $54 $50 $49))
    (return (If (AggrNotEquals $49 (Member (Nth $48 '0) '"user")) $51 $55))
  )))))
  (let $31 '"_yql_window_session_params")
  (let $32 '"_yql_window_session_start")
  (let $33 (Chopper (OrderedMap $30 (lambda '($56) (block '(
    (let $57 (Nth $56 '1))
    (let $58 (Nth $56 '0))
    (return (AsStruct '($31 (AsStruct '('start $57) '('state (Nth $56 '2)))) '($32 $57) '('"payload" (Member $58 '"payload")) '('"ts" (Member $58 '"ts")) '('"user" (Member $58 '"user"))))
  )))) (lambda '($59) '((Member $59 '"user") (Member $59 $32))) (lambda '($60 $61) (Or (AggrNotEquals (Nth $60 '0) (Member $61 '"user")) (AggrNotEquals (Nth $60 '1) (Member $61 $32)))) (lambda '($62 $63) (block '(
    (let $64 (Chain1Map $63 (lambda '($69) (block '(
      (let $70 (Member $69 '"ts"))
      (let $71 '('AggregateList0 (ToList $70)))
      (let $72 '('Count0 (Uint64 '1)))
      (let $73 (AsStruct $71 $72 '($31 (Member $69 $31)) '($32 (Member $69 $32)) '('"payload" (Member $69 '"payload")) '('"ts" $70) '('"user" (Member $69 '"user"))))
      (return '($73 (AsStruct $71 $72)))
    ))) (lambda '($74 $75) (block '(
      (let $76 (Member $74 '"ts"))
      (let $77 (Nth $75 '1))
      (let $78 (Member $77 'AggregateList0))
      (let $79 (IfPresent $76 (lambda '($83) (Insert $78 $83)) $78))
      (let $80 '('AggregateList0 $79))
      (let $81 '('Count0 (Inc (Member $77 'Count0))))
      (let $82 (AsStruct $80 $81 '($31 (Member $74 $31)) '($32 (Member $74 $32)) '('"payload" (Member $74 '"payload")) '('"ts" $76) '('"user" (Member $74 '"user"))))
      (return '($82 (AsStruct $80 $81)))
    )))))
    (let $65 (StructType '('AggregateList0 $10) '('Count0 $11) '($31 (StructType '('start $3) '('state $3))) '($32 $3) $2 $4 $5))
    (let $66 (ListType $65))
    (let $67 (VariantType (StructType '('group $66) '('singleRow $65))))
    (let $68 (Condense1 $64 (lambda '($84) (block '(
      (let $85 (Nth $84 '0))
      (let $86 (Variant $85 'singleRow $67))
      (return '((Member $85 '"ts") $86))
    ))) (lambda '($87 $88) (AggrNotEquals (Member (Nth $87 '0) '"ts") (Nth $88 '0))) (lambda '($89 $90) (block '(
      (let $91 (Nth $89 '0))
      (let $92 (Visit (Nth $90 '1) 'group (lambda '($93) (Variant (Insert $93 $91) 'group $67)) 'singleRow (lambda '($94) (Variant (AsList $94 $91) 'group $67))))
      (return '((Nth $90 '0) $92))
    )))))
    (return (OrderedFlatMap $68 (lambda '($95) (block '(
      (let $96 (Visit (Nth $95 '1) 'group (lambda '($97) (IfPresent (Last $97) (lambda '($98) (OrderedMap (Collect (Map $97 (lambda '($99) (AsStruct '($31 (Member $99 $31)) '($32 (Member $99 $32)) '('"payload" (Member $99 '"payload")) '('"ts" (Member $99 '"ts")) '('"user" (Member $99 '"user")))))) (lambda '($100) (AsStruct '('AggregateList0 (Member $98 'AggregateList0)) '('Count0 (Member $98 'Count0)) '($31 (Member $100 $31)) '($32 (Member $100 $32)) '('"payload" (Member $100 '"payload")) '('"ts" (Member $100 '"ts")) '('"user" (Member $100 '"user")))))) (List $66))) 'singleRow (lambda '($101) (AsList $101))))
      (return (Map $96 (lambda '($102) (AsStruct '('AggregateList0 (Member $102 'AggregateList0)) '('Count0 (Member $102 'Count0)) '('"payload" (Member $102 '"payload")) '('"ts" (Member $102 '"ts")) '('"user" (Member $102 '"user"))))))
    )))))
  )))))
  (let $34 (Sort (Map $33 (lambda '($103) (AsStruct '('"payload" (Member $103 '"payload")) '('"session_len" (Member $103 'Count0)) '('"ts" (Member $103 '"ts")) '('"ts_session" (Member $103 'AggregateList0)) '('"user" (Member $103 '"user"))))) '($29 $29) (lambda '($104) '((Member $104 '"user") (Member $104 '"payload")))))
  (let $35 (lambda '($105) (Member $105 '"payload") (Member $105 '"session_len") (Member $105 '"ts") (Member $105 '"ts_session") (Member $105 '"user")))
  (return (FromFlow (ExpandMap $34 $35)))
))) $13))
(let $15 (DqCnMerge (TDqOutput $14 '0) '('('"4" '"Asc") '('0 '"Asc"))))
(let $16 (DqPhyStage '($15) (lambda '($106) (FromFlow (NarrowMap (ToFlow $106) (lambda '($107 $108 $109 $110 $111) (AsStruct '('"payload" $107) '('"session_len" $108) '('"ts" $109) '('"ts_session" $110) '('"user" $111)))))) '('('"_logical_id" '7171) '('"_id" '"8dd0e9ea-c04cd935-6e1976e1-ef090cd5"))))
(let $17 '($8 $14 $16))
(let $18 '('"user" '"ts" '"payload" '"ts_session" '"session_len"))
(let $19 (DqCnResult (TDqOutput $16 '0) $18))
(return (KqpPhysicalQuery '((KqpPhysicalTx $17 '($19) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $12) '0 '0)) '('('"type" '"query"))))
)
