(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 '('"ts" $2))
(let $4 '('"user" (OptionalType (DataType 'String))))
(let $5 '('('"_logical_id" '7991) '('"_id" '"c8dfe438-5fbbeae9-62a77f69-f3c6b57c") '('"_wide_channels" (StructType $3 $4))))
(let $6 (DqPhyStage '() (lambda '() (block '(
  (let $18 '@@["StructType";[["user";["OptionalType";["DataType";"String"]]];["ts";["OptionalType";["DataType";"Int32"]]];["payload";["DataType";"Int32"]]]]@@)
  (let $19 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $18)))
  (let $20 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $21 (YtStat '('Id '"Input") '('RecordsCount '"18") '('DataSize '"655") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $22 (YtTable '"Input" $19 $20 $21 '() (Void) (Void) '"/Root/plato"))
  (let $23 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $22 '('"ts" '"user") (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $23 '())))
))) $5))
(let $7 (DqCnHashShuffle (TDqOutput $6 '0) '('1) '0 '"HashV2"))
(let $8 (ListType $1))
(let $9 (DataType 'Uint64))
(let $10 (StructType '('"session_len" $9) '('"ss" $2) '('"ss1" $2) $3 '('"ts_session" $8) $4))
(let $11 '('('"_logical_id" '8487) '('"_id" '"6800a08-4c88f5b8-ee9e4b7b-c57dd1c") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '($7) (lambda '($24) (block '(
  (let $25 (NarrowSqueezeToDict (ToFlow $24) (lambda '($33 $34) $34) (lambda '($35 $36) (AsStruct '('"ts" $35) '('"user" $36))) '('Auto 'Many)))
  (let $26 (Bool 'true))
  (let $27 (Chain1Map (OrderedFlatMap $25 (lambda '($37) (OrderedFlatMap (DictPayloads $37) (lambda '($38) (Sort $38 $26 (lambda '($39) (Member $39 '"ts"))))))) (lambda '($40) (block '(
    (let $41 (Member $40 '"ts"))
    (return '($40 $41 $41 (Member $40 '"user")))
  ))) (lambda '($42 $43) (block '(
    (let $44 (Member $42 '"user"))
    (let $45 (Member $42 '"ts"))
    (let $46 '($42 $45 $45 $44))
    (let $47 (Nth $43 '2))
    (let $48 (If (Coalesce (< $47 $45) $26) (- $45 $47) (- $47 $45)))
    (let $49 (If (And (AggrNotEquals $45 $47) (Coalesce (< (Int32 '"10") $48) $26)) $45 (Nth $43 '1)))
    (let $50 '($42 $49 $45 $44))
    (return (If (AggrNotEquals $44 (Member (Nth $43 '0) '"user")) $46 $50))
  )))))
  (let $28 '"_yql_window_session_params")
  (let $29 '"_yql_window_session_start")
  (let $30 (Chopper (OrderedMap $27 (lambda '($51) (block '(
    (let $52 (Nth $51 '1))
    (let $53 (Nth $51 '0))
    (return (AsStruct '($28 (AsStruct '('start $52) '('state (Nth $51 '2)))) '($29 $52) '('"ts" (Member $53 '"ts")) '('"user" (Member $53 '"user"))))
  )))) (lambda '($54) '((Member $54 '"user") (Member $54 $29))) (lambda '($55 $56) (Or (AggrNotEquals (Nth $55 '0) (Member $56 '"user")) (AggrNotEquals (Nth $55 '1) (Member $56 $29)))) (lambda '($57 $58) (block '(
    (let $59 (Chain1Map $58 (lambda '($64) (block '(
      (let $65 (Member $64 '"ts"))
      (let $66 '('AggregateList0 (ToList $65)))
      (let $67 '('Count0 (Uint64 '1)))
      (let $68 (AsStruct $66 $67 '($28 (Member $64 $28)) '($29 (Member $64 $29)) '('"ts" $65) '('"user" (Member $64 '"user"))))
      (return '($68 (AsStruct $66 $67)))
    ))) (lambda '($69 $70) (block '(
      (let $71 (Member $69 '"ts"))
      (let $72 (Nth $70 '1))
      (let $73 (Member $72 'AggregateList0))
      (let $74 (IfPresent $71 (lambda '($78) (Insert $73 $78)) $73))
      (let $75 '('AggregateList0 $74))
      (let $76 '('Count0 (Inc (Member $72 'Count0))))
      (let $77 (AsStruct $75 $76 '($28 (Member $69 $28)) '($29 (Member $69 $29)) '('"ts" $71) '('"user" (Member $69 '"user"))))
      (return '($77 (AsStruct $75 $76)))
    )))))
    (let $60 (StructType '('AggregateList0 $8) '('Count0 $9) '($28 (StructType '('start $2) '('state $2))) '($29 $2) $3 $4))
    (let $61 (ListType $60))
    (let $62 (VariantType (StructType '('group $61) '('singleRow $60))))
    (let $63 (Condense1 $59 (lambda '($79) (block '(
      (let $80 (Variant (Nth $79 '0) 'singleRow $62))
      (return '((Void) $80))
    ))) (lambda '($81 $82) (Bool 'false)) (lambda '($83 $84) (block '(
      (let $85 (Nth $83 '0))
      (let $86 (Visit (Nth $84 '1) 'group (lambda '($87) (Variant (Insert $87 $85) 'group $62)) 'singleRow (lambda '($88) (Variant (AsList $88 $85) 'group $62))))
      (return '((Nth $84 '0) $86))
    )))))
    (return (FlatMap $63 (lambda '($89) (Visit (Nth $89 '1) 'group (lambda '($90) (block '(
      (let $91 (IfPresent (Last $90) (lambda '($92) (OrderedMap (Collect (Map $90 (lambda '($93) (AsStruct '($28 (Member $93 $28)) '($29 (Member $93 $29)) '('"ts" (Member $93 '"ts")) '('"user" (Member $93 '"user")))))) (lambda '($94) (AsStruct '('AggregateList0 (Member $92 'AggregateList0)) '('Count0 (Member $92 'Count0)) '($28 (Member $94 $28)) '($29 (Member $94 $29)) '('"ts" (Member $94 '"ts")) '('"user" (Member $94 '"user")))))) (List $61)))
      (return (Map $91 (lambda '($95) (block '(
        (let $96 (Member $95 $28))
        (return (AsStruct '('AggregateList0 (Member $95 'AggregateList0)) '('Count0 (Member $95 'Count0)) '('"group_w1_0" $96) '('"ss0" $96) '('"ts" (Member $95 '"ts")) '('"user" (Member $95 '"user"))))
      )))))
    ))) 'singleRow (lambda '($97) (block '(
      (let $98 (Member $97 $28))
      (return (AsList (AsStruct '('AggregateList0 (Member $97 'AggregateList0)) '('Count0 (Member $97 'Count0)) '('"group_w1_0" $98) '('"ss0" $98) '('"ts" (Member $97 '"ts")) '('"user" (Member $97 '"user")))))
    )))))))
  )))))
  (let $31 (Sort (Map $30 (lambda '($99) (block '(
    (let $100 (Sort (Member $99 'AggregateList0) $26 (lambda '($101) $101)))
    (return (AsStruct '('"session_len" (Member $99 'Count0)) '('"ss" (Member (Member $99 '"ss0") 'start)) '('"ss1" (Member (Member $99 '"group_w1_0") 'start)) '('"ts" (Member $99 '"ts")) '('"ts_session" $100) '('"user" (Member $99 '"user"))))
  )))) '($26 $26) (lambda '($102) '((Member $102 '"user") (Member $102 '"ts")))))
  (let $32 (lambda '($103) (Member $103 '"session_len") (Member $103 '"ss") (Member $103 '"ss1") (Member $103 '"ts") (Member $103 '"ts_session") (Member $103 '"user")))
  (return (FromFlow (ExpandMap $31 $32)))
))) $11))
(let $13 (DqCnMerge (TDqOutput $12 '0) '('('"5" '"Asc") '('"3" '"Asc"))))
(let $14 (DqPhyStage '($13) (lambda '($104) (FromFlow (NarrowMap (ToFlow $104) (lambda '($105 $106 $107 $108 $109 $110) (AsStruct '('"session_len" $105) '('"ss" $106) '('"ss1" $107) '('"ts" $108) '('"ts_session" $109) '('"user" $110)))))) '('('"_logical_id" '8499) '('"_id" '"d6d39b9-e67ae9ad-491f558d-a0457e51"))))
(let $15 '($6 $12 $14))
(let $16 '('"user" '"ts" '"ss1" '"ss" '"ts_session" '"session_len"))
(let $17 (DqCnResult (TDqOutput $14 '0) $16))
(return (KqpPhysicalQuery '((KqpPhysicalTx $15 '($17) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $10) '0 '0)) '('('"type" '"query"))))
)
