(
(let $1 (Int32 '0))
(let $2 (DataType 'Int32))
(let $3 (StructType '('"sort_col" (TupleType $2 $2)) '('"ts" (OptionalType $2)) '('"user" (OptionalType (DataType 'String)))))
(let $4 '('('"_logical_id" '3483) '('"_id" '"7e98d670-519ec6b0-ca5f7212-30d6de94") '('"_wide_channels" $3)))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $14 '@@["StructType";[["user";["OptionalType";["DataType";"String"]]];["ts";["OptionalType";["DataType";"Int32"]]];["payload";["DataType";"Int32"]]]]@@)
  (let $15 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $14)))
  (let $16 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $17 (YtStat '('Id '"Input") '('RecordsCount '"18") '('DataSize '"656") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $18 (YtTable '"Input" $15 $16 $17 '() (Void) (Void) '"/Root/plato"))
  (let $19 '('"payload" '"ts" '"user"))
  (let $20 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $18 $19 (Void) (Void))) '()))))
  (let $21 (lambda '($22 $23 $24) '((Coalesce $23 $1) $22) $23 $24))
  (return (FromFlow (WideMap (DqReadWideWrap $20 '()) $21)))
))) $4))
(let $6 (DqCnHashShuffle (TDqOutput $5 '0) '('2) '0 '"HashV2"))
(let $7 (StructType '('"session_len" (DataType 'Uint64))))
(let $8 '('('"_logical_id" '3892) '('"_id" '"3f77e7d3-6e509434-bc53b3d5-8ae9b19e") '('"_wide_channels" $7)))
(let $9 (DqPhyStage '($6) (lambda '($25) (block '(
  (let $26 (NarrowSqueezeToDict (ToFlow $25) (lambda '($34 $35 $36) $36) (lambda '($37 $38 $39) (AsStruct '('"sort_col" $37) '('"ts" $38) '('"user" $39))) '('Auto 'Many)))
  (let $27 (Bool 'true))
  (let $28 (Int32 '1))
  (let $29 '('"count" $28))
  (let $30 (Chain1Map (OrderedFlatMap $26 (lambda '($40) (OrderedFlatMap (DictPayloads $40) (lambda '($41) (Sort $41 $27 (lambda '($42) (Member $42 '"sort_col"))))))) (lambda '($43) (block '(
    (let $44 (Coalesce (Member $43 '"ts") $1))
    (return '($43 $44 (AsStruct $29 '('"value" $44)) (Member $43 '"user")))
  ))) (lambda '($45 $46) (block '(
    (let $47 (Member $45 '"user"))
    (let $48 (Coalesce (Member $45 '"ts") $1))
    (let $49 '($45 $48 (AsStruct $29 '('"value" $48)) $47))
    (let $50 (Nth $46 '2))
    (let $51 (+ (Member $50 '"count") $28))
    (let $52 (+ (Member $50 '"value") $48))
    (let $53 (If (== (Unwrap (% $51 (Int32 '2))) $28) $52 (Nth $46 '1)))
    (let $54 '($45 $53 (AsStruct '('"count" $51) '('"value" $52)) $47))
    (return (If (AggrNotEquals $47 (Member (Nth $46 '0) '"user")) $49 $54))
  )))))
  (let $31 '"_yql_group_session_start")
  (let $32 (Condense1 $30 (lambda '($55) (AsStruct '('_yql_agg_0 (Uint64 '1)) '($31 (Nth $55 '1)) '('"user" (Member (Nth $55 '0) '"user")))) (lambda '($56 $57) (Or (AggrNotEquals (Member (Nth $56 '0) '"user") (Member $57 '"user")) (AggrNotEquals (Nth $56 '1) (Member $57 $31)))) (lambda '($58 $59) (AsStruct '('_yql_agg_0 (Inc (Member $59 '_yql_agg_0))) '($31 (Member $59 $31)) '('"user" (Member $59 '"user"))))))
  (let $33 (Sort (Map $32 (lambda '($60) (AsStruct '('"session_len" (Member $60 '_yql_agg_0))))) $27 (lambda '($61) (Member $61 '"session_len"))))
  (return (FromFlow (ExpandMap $33 (lambda '($62) (Member $62 '"session_len")))))
))) $8))
(let $10 (DqCnMerge (TDqOutput $9 '0) '('('0 '"Asc"))))
(let $11 (DqPhyStage '($10) (lambda '($63) (FromFlow (NarrowMap (ToFlow $63) (lambda '($64) (AsStruct '('"session_len" $64)))))) '('('"_logical_id" '3904) '('"_id" '"84740292-b880439e-13f9693a-2adf587c"))))
(let $12 '($5 $9 $11))
(let $13 (DqCnResult (TDqOutput $11 '0) '('"session_len")))
(return (KqpPhysicalQuery '((KqpPhysicalTx $12 '($13) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $7) '0 '0)) '('('"type" '"query"))))
)
