(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 '('"ts" $2))
(let $4 '('('"_logical_id" '2933) '('"_id" '"3a0b4d6c-e2959ce-36eb5640-3c5cd32c") '('"_wide_channels" (StructType $3))))
(let $5 (DqPhyStage '() (lambda '() (block '(
  (let $25 '@@["StructType";[["user";["OptionalType";["DataType";"String"]]];["ts";["OptionalType";["DataType";"Int32"]]];["payload";["DataType";"Int32"]]]]@@)
  (let $26 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $25)))
  (let $27 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('HasRLS '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $28 (YtStat '('Id '"Input") '('RecordsCount '"18") '('DataSize '"656") '('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 '('"ts") (Void) (Void) (Void))) '()))))
  (return (FromFlow (DqReadWideWrap $30 '())))
))) $4))
(let $6 (DqCnUnionAll (TDqOutput $5 '0)))
(let $7 (Bool 'true))
(let $8 '"_yql_group_session_start")
(let $9 '($8 $2))
(let $10 (StructType '('_yql_agg_0 $2) $9 $3))
(let $11 '('('"_logical_id" '3178) '('"_id" '"e92d573f-a0a1bf0a-d7fa5a8f-4c0e3601") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '($6) (lambda '($31) (block '(
  (let $32 (Uint32 '0))
  (let $33 (Chain1Map (NarrowMap (WideSort (ToFlow $31) '('('0 $7))) (lambda '($38) (AsStruct '('"ts" $38)))) (lambda '($39) (block '(
    (let $40 (Member $39 '"ts"))
    (return '($39 $40 $40 $32))
  ))) (lambda '($41 $42) (block '(
    (let $43 (Member $41 '"ts"))
    (let $44 (Nth $42 '2))
    (let $45 (If (Coalesce (< $44 $43) $7) (- $43 $44) (- $44 $43)))
    (let $46 (If (And (AggrNotEquals $43 $44) (Coalesce (< (Int32 '"10") $45) $7)) $43 (Nth $42 '1)))
    (return '($41 $46 $43 $32))
  )))))
  (let $34 (lambda '($47) (Nth $47 '1) (Member (Nth $47 '0) '"ts")))
  (let $35 (lambda '($48 $49) $48 $49))
  (let $36 (lambda '($50 $51 $52 $53)))
  (let $37 (lambda '($54 $55) $55 $54 $55))
  (return (FromFlow (DqPhyHashCombine (ExpandMap $33 $34) '-1073741824 $35 $36 $36 $37)))
))) $11))
(let $13 (DqCnHashShuffle (TDqOutput $12 '0) '('1 '2) '0 '"HashV2"))
(let $14 '('Auto 'Many))
(let $15 '('('"_logical_id" '3270) '('"_id" '"7f2aa9ef-ece931cb-83ec3126-a2008652") '('"_partition_mode" '"aggregate") '('"_wide_channels" (StructType '('_yql_agg_0 (OptionalType $2)) $9))))
(let $16 (DqPhyStage '($13) (lambda '($56) (block '(
  (let $57 (NarrowSqueezeToDict (ToFlow $56) (lambda '($60 $61 $62) '($61 $62)) (lambda '($63 $64 $65) (AsStruct '('_yql_agg_0 $63) '($8 $64) '('"ts" $65))) $14))
  (let $58 (Condense1 (OrderedFlatMap $57 (lambda '($66) (OrderedFlatMap (DictPayloads $66) (lambda '($67) $67)))) (lambda '($68) $68) (lambda '($69 $70) (Or (AggrNotEquals (Member $69 $8) (Member $70 $8)) (AggrNotEquals (Member $69 '"ts") (Member $70 '"ts")))) (lambda '($71 $72) $71)))
  (let $59 (lambda '($73) (Just (Member $73 '_yql_agg_0)) (Member $73 $8)))
  (return (FromFlow (ExpandMap $58 $59)))
))) $15))
(let $17 (DqCnHashShuffle (TDqOutput $16 '0) '('1) '0 '"HashV2"))
(let $18 (StructType '('"session_start" $1)))
(let $19 '('('"_logical_id" '3736) '('"_id" '"660202b2-47136e95-8ba49583-8f68cf28") '('"_wide_channels" $18)))
(let $20 (DqPhyStage '($17) (lambda '($74) (block '(
  (let $75 (NarrowSqueezeToDict (ToFlow $74) (lambda '($78 $79) $79) (lambda '($80 $81) (AsStruct '('_yql_agg_0 $80) '($8 $81))) $14))
  (let $76 (Condense1 (OrderedFlatMap $75 (lambda '($82) (OrderedFlatMap (DictPayloads $82) (lambda '($83) $83)))) (lambda '($84) $84) (lambda '($85 $86) (AggrNotEquals (Member $85 $8) (Member $86 $8))) (lambda '($87 $88) (block '(
    (let $89 (Member $87 '_yql_agg_0))
    (let $90 (Member $88 '_yql_agg_0))
    (let $91 (IfPresent $89 (lambda '($92) (IfPresent $90 (lambda '($93) (Just (AggrMin $92 $93))) $89)) $90))
    (return (AsStruct '('_yql_agg_0 $91) '($8 (Member $88 $8))))
  )))))
  (let $77 (Sort (Map $76 (lambda '($94) (AsStruct '('"session_start" (Coalesce (Unwrap (Member $94 '_yql_agg_0)) (Int32 '"100500")))))) $7 (lambda '($95) (Member $95 '"session_start"))))
  (return (FromFlow (ExpandMap $77 (lambda '($96) (Member $96 '"session_start")))))
))) $19))
(let $21 (DqCnMerge (TDqOutput $20 '0) '('('0 '"Asc"))))
(let $22 (DqPhyStage '($21) (lambda '($97) (FromFlow (NarrowMap (ToFlow $97) (lambda '($98) (AsStruct '('"session_start" $98)))))) '('('"_logical_id" '3748) '('"_id" '"e1b3a27e-dbfbda9b-41a79435-d542e3ec"))))
(let $23 '($5 $12 $16 $20 $22))
(let $24 (DqCnResult (TDqOutput $22 '0) '('"session_start")))
(return (KqpPhysicalQuery '((KqpPhysicalTx $23 '($24) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $18) '0 '0)) '('('"type" '"query"))))
)
