{"title":"JOURNEYS","description":"Discover observed paths from a start event to an end event, including drop-offs, with the JOURNEYS operator in Altertable.","order":710,"askSuggestions":["How do I see the paths of users who never converted?","Should I measure paths as UNIQUES or EVENT TOTALS?","How do I keep a journey within a single session?"],"navigation":true,"body":{"code":"var Component=(()=>{var E=Object.create;var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var A=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),m=(i,n)=>{for(var r in n)c(i,r,{get:n[r],enumerable:!0})},d=(i,n,r,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of S(n))!v.call(i,t)&&t!==r&&c(i,t,{get:()=>n[t],enumerable:!(s=T(n,t))||s.enumerable});return i};var N=(i,n,r)=>(r=i!=null?E(I(i)):{},d(n||!i||!i.__esModule?c(r,\"default\",{value:i,enumerable:!0}):r,i)),f=i=>d(c({},\"__esModule\",{value:!0}),i);var l=A((w,h)=>{h.exports=_jsx_runtime});var P={};m(P,{default:()=>u,frontmatter:()=>g});var e=N(l()),g={title:\"JOURNEYS\",description:\"Discover observed paths from a start event to an end event, including drop-offs, with the JOURNEYS operator in Altertable.\",order:710,askSuggestions:[\"How do I see the paths of users who never converted?\",\"Should I measure paths as UNIQUES or EVENT TOTALS?\",\"How do I keep a journey within a single session?\"]};function p(i){let n={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...i.components},{DocsBeta:r,DocsPreviewDocument:s,DocsPreviewSection:t,DocsTable:a}=n;return r||o(\"DocsBeta\",!0),s||o(\"DocsPreviewDocument\",!0),t||o(\"DocsPreviewSection\",!0),a||o(\"DocsTable\",!0),(0,e.jsxs)(s,{anchors:\"journeys first-example operator-syntax choose-a-path-mode paths-between paths-starting-with paths-ending-with count-uniques-or-every-occurrence result-columns define-the-event-streams partition-by order-by step expand-by bound-a-path within within-session max-steps collapse-repeats filter-events-on-a-path exclude-when require practical-patterns split-checkout-by-plan paths-after-every-start learn-more\",children:[(0,e.jsxs)(t,{sectionId:\"journeys\",sectionTitle:\"JOURNEYS\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,e.jsx)(n.h1,{id:\"journeys\",children:\"JOURNEYS\"}),`\n`,(0,e.jsx)(r,{children:(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),` is available in beta. Its syntax and behavior may change as the\nimplementation evolves.`]})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),\" discovers observed paths over an identity partition. Use it when you need the routes from a start event to an end event, the sequences after a start, or the sequences before an end \\u2014 including users who never convert.\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"Run these statements through Altertable's \",(0,e.jsx)(n.a,{href:\"/docs/lakehouse/sql-engine\",children:\"SQL engine\"}),\".\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"first-example\",sectionTitle:\"First example\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,e.jsx)(n.h2,{id:\"first-example\",children:\"First example\"}),`\n`,(0,e.jsx)(n.p,{children:\"Suppose an event table contains one row for each user action:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`WITH events(user_id, ts, event_id, event) AS (\n    VALUES\n        (1, TIMESTAMP '2024-01-01 10:00:00', 1, 'Homepage'),\n        (1, TIMESTAMP '2024-01-01 10:01:00', 2, 'Signup'),\n        (1, TIMESTAMP '2024-01-01 10:02:00', 3, 'Docs'),\n        (1, TIMESTAMP '2024-01-01 10:03:00', 4, 'Checkout'),\n        (1, TIMESTAMP '2024-01-01 10:04:00', 5, 'Purchase'),\n        (2, TIMESTAMP '2024-01-01 10:00:00', 1, 'Signup'),\n        (2, TIMESTAMP '2024-01-01 10:01:00', 2, 'Docs'),\n        (2, TIMESTAMP '2024-01-01 10:02:00', 3, 'Checkout'),\n        (2, TIMESTAMP '2024-01-01 10:03:00', 4, 'Purchase'),\n        (3, TIMESTAMP '2024-01-01 10:00:00', 1, 'Pricing'),\n        (3, TIMESTAMP '2024-01-01 10:01:00', 2, 'Signup'),\n        (3, TIMESTAMP '2024-01-01 10:02:00', 3, 'Create project'),\n        (3, TIMESTAMP '2024-01-01 10:03:00', 4, 'Purchase'),\n        (4, TIMESTAMP '2024-01-01 10:00:00', 1, 'Docs'),\n        (4, TIMESTAMP '2024-01-01 10:01:00', 2, 'Signup'),\n        (4, TIMESTAMP '2024-01-01 10:02:00', 3, 'Docs'),\n        (4, TIMESTAMP '2024-01-01 10:03:00', 4, 'Docs')\n)\nSELECT\n    path,\n    converted,\n    truncated,\n    count AS journey_count,\n    avg_duration\nFROM events\nJOURNEYS (\n    PARTITION BY user_id\n    ORDER BY ts, event_id\n    STEP event\n    PATHS BETWEEN (event = 'Signup') AND (event = 'Purchase')\n    MEASURED AS UNIQUES\n    WITHIN INTERVAL 1 DAY\n    MAX STEPS 9\n    COLLAPSE REPEATS\n)\nORDER BY journey_count DESC, path;\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"The query starts at each user's first signup and follows events to the earliest purchase within one day. Events before signup are excluded. User 4 signed up and never purchased, so that path stays in the result as an incomplete journey. Consecutive documentation visits collapse into one step.\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-text\",children:`path                                  converted  truncated  journey_count\n[Signup, Docs, Checkout, Purchase]    true       false      2\n[Signup, Create project, Purchase]    true       false      1\n[Signup, Docs]                        false      false      1\n`})}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"PARTITION BY user_id\"}),\" creates an independent sequence for each user.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"ORDER BY ts, event_id\"}),\" defines event order, with \",(0,e.jsx)(n.code,{children:\"event_id\"}),\" breaking timestamp ties.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"STEP event\"}),\" is the value stored in each path position.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"PATHS BETWEEN\"}),\" keeps events from signup through purchase, or through the end of the window when purchase is missing.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"MEASURED AS UNIQUES\"}),\" counts one path per user.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"COLLAPSE REPEATS\"}),\" merges consecutive identical steps.\"]}),`\n`]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"operator-syntax\",sectionTitle:\"Operator syntax\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,e.jsx)(n.h2,{id:\"operator-syntax\",children:\"Operator syntax\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"The supported \",(0,e.jsx)(n.code,{children:\"FROM\"}),\"-clause shape is:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`FROM input_relation [input_alias]\nJOURNEYS (\n    PARTITION BY identity_column [, ...]\n    ORDER BY time_column [, tie_breaker_column ...]\n    STEP expression\n    [EXPAND BY property WHEN (predicate)]\n    PATHS STARTING WITH (predicate)\n      | PATHS ENDING WITH (predicate)\n      | PATHS BETWEEN (start_predicate) AND (end_predicate)\n    [MEASURED AS UNIQUES | EVENT TOTALS]\n    [WITHIN interval_expression | WITHIN SESSION session_column]\n    [MAX STEPS n]\n    [COLLAPSE REPEATS]\n    [EXCLUDE WHEN (predicate)]...\n    [REQUIRE (predicate)]...\n)\n[journeys_alias]\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"PARTITION BY\"}),\", \",(0,e.jsx)(n.code,{children:\"ORDER BY\"}),\", \",(0,e.jsx)(n.code,{children:\"STEP\"}),\", and one \",(0,e.jsx)(n.code,{children:\"PATHS\"}),\" mode are required. \",(0,e.jsx)(n.code,{children:\"MEASURED AS\"}),\" defaults to \",(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\". \",(0,e.jsx)(n.code,{children:\"MAX STEPS\"}),\" defaults to \",(0,e.jsx)(n.code,{children:\"9\"}),\".\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"The source relation must appear immediately before \",(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),\". The result can be aliased after the clause:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`SELECT j.path, j.count\nFROM events AS e\nJOURNEYS (\n    PARTITION BY user_id\n    ORDER BY ts, event_id\n    STEP event\n    PATHS STARTING WITH (event = 'Signup')\n) AS j;\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"Common SQL constructs such as CTEs, subqueries, joins, outer filters, grouping, and aliases can surround the operator.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"choose-a-path-mode\",sectionTitle:\"Choose a path mode\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,e.jsx)(n.h2,{id:\"choose-a-path-mode\",children:\"Choose a path mode\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"paths-between\",sectionTitle:\"PATHS BETWEEN\",anchors:\"\",ancestors:\"choose-a-path-mode\",index:\"4\",children:[(0,e.jsx)(n.h3,{id:\"paths-between\",children:(0,e.jsx)(n.code,{children:\"PATHS BETWEEN\"})}),`\n`,(0,e.jsx)(n.p,{children:\"Start at a start event and scan forward for an end event. This is the signup-to-purchase shape:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`PATHS BETWEEN (event = 'Signup') AND (event = 'Purchase')\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"converted\"}),\" is \",(0,e.jsx)(n.code,{children:\"true\"}),\" when an end event occurs inside the window, and \",(0,e.jsx)(n.code,{children:\"false\"}),\" when the path drops off. \",(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),\" uses the first start event. It does not skip that start to pick a later start that would convert.\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"With \",(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\", the first start is the only start. With \",(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\", each unused start begins a new instance. After a conversion, the next instance resumes after the end event. After a drop-off, it resumes after the start event.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"paths-starting-with\",sectionTitle:\"PATHS STARTING WITH\",anchors:\"\",ancestors:\"choose-a-path-mode\",index:\"5\",children:[(0,e.jsx)(n.h3,{id:\"paths-starting-with\",children:(0,e.jsx)(n.code,{children:\"PATHS STARTING WITH\"})}),`\n`,(0,e.jsxs)(n.p,{children:[\"Start at a start event and keep the following visible steps. \",(0,e.jsx)(n.code,{children:\"converted\"}),\" is \",(0,e.jsx)(n.code,{children:\"NULL\"}),\" because there is no end condition:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`PATHS STARTING WITH (event = 'Signup')\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\" uses the first start. \",(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\" starts a path at every start event. Those paths may overlap in the source rows.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"paths-ending-with\",sectionTitle:\"PATHS ENDING WITH\",anchors:\"\",ancestors:\"choose-a-path-mode\",index:\"6\",children:[(0,e.jsx)(n.h3,{id:\"paths-ending-with\",children:(0,e.jsx)(n.code,{children:\"PATHS ENDING WITH\"})}),`\n`,(0,e.jsxs)(n.p,{children:[\"End at an end event and look backward for the visible steps that precede it. \",(0,e.jsx)(n.code,{children:\"converted\"}),\" is \",(0,e.jsx)(n.code,{children:\"NULL\"}),\":\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`PATHS ENDING WITH (event = 'Purchase')\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\" uses the last end event. \",(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\" ends a path at every end event, looking backward within the window.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"count-uniques-or-every-occurrence\",sectionTitle:\"Count uniques or every occurrence\",anchors:\"\",ancestors:\"\",index:\"7\",children:[(0,e.jsx)(n.h2,{id:\"count-uniques-or-every-occurrence\",children:\"Count uniques or every occurrence\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"MEASURED AS UNIQUES\"}),\" emits one instance per identity. \",(0,e.jsx)(n.code,{children:\"MEASURED AS EVENT TOTALS\"}),\" emits every selected start or end:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`MEASURED AS UNIQUES\nMEASURED AS EVENT TOTALS\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use \",(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\" when you want one path per user. Use \",(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\" when the same user can start or complete the journey more than once and each attempt should count.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"result-columns\",sectionTitle:\"Result columns\",anchors:\"\",ancestors:\"\",index:\"8\",children:[(0,e.jsx)(n.h2,{id:\"result-columns\",children:\"Result columns\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),\" aggregates identical paths. The output does not keep one row per user.\"]}),`\n`,(0,e.jsx)(a,{columns:[\"Column\",\"Description\"],data:[{Column:\"`path`\",Description:\"`LIST` of steps, or `LIST<STRUCT(event, property)>` after `EXPAND BY`. Retained visible steps after exclusion, collapse, and truncation\"},{Column:\"`converted`\",Description:\"`BOOLEAN`. `true` or `false` for `PATHS BETWEEN`; `NULL` for starting-only and ending-only modes\"},{Column:\"`truncated`\",Description:\"`BOOLEAN`. `true` when the visible path exceeded `MAX STEPS`\"},{Column:\"`count`\",Description:\"`BIGINT`. Identities for `UNIQUES`, or selected occurrences for `EVENT TOTALS`\"},{Column:\"`min_duration` / `avg_duration` / `max_duration`\",Description:\"`INTERVAL`. Duration of the raw span from the first row to the last row, including excluded events\"}]}),`\n`,(0,e.jsxs)(n.p,{children:[\"Duration is \",(0,e.jsx)(n.code,{children:\"timestamp(end_row) - timestamp(start_row)\"}),\" of that raw span. A drop-off uses the last row still inside the window.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"define-the-event-streams\",sectionTitle:\"Define the event streams\",anchors:\"\",ancestors:\"\",index:\"9\",children:[(0,e.jsx)(n.h2,{id:\"define-the-event-streams\",children:\"Define the event streams\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"partition-by\",sectionTitle:\"PARTITION BY\",anchors:\"\",ancestors:\"define-the-event-streams\",index:\"10\",children:[(0,e.jsx)(n.h3,{id:\"partition-by\",children:(0,e.jsx)(n.code,{children:\"PARTITION BY\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"PARTITION BY\"}),\" is required. It splits the input into independent identities:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`PARTITION BY user_id\nPARTITION BY user_id, app_id\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"A path never crosses a partition boundary. Partition expressions must be input columns.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"order-by\",sectionTitle:\"ORDER BY\",anchors:\"\",ancestors:\"define-the-event-streams\",index:\"11\",children:[(0,e.jsx)(n.h3,{id:\"order-by\",children:(0,e.jsx)(n.code,{children:\"ORDER BY\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"ORDER BY\"}),\" is required. The first column is the time key:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`ORDER BY ts, event_id\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"It must be an ascending input column with a \",(0,e.jsx)(n.code,{children:\"DATE\"}),\", \",(0,e.jsx)(n.code,{children:\"TIMESTAMP\"}),\", or \",(0,e.jsx)(n.code,{children:\"TIMESTAMPTZ\"}),\" type. Additional columns are tie-breakers. Add a stable tie-breaker when multiple events can share a timestamp.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"step\",sectionTitle:\"STEP\",anchors:\"\",ancestors:\"define-the-event-streams\",index:\"12\",children:[(0,e.jsx)(n.h3,{id:\"step\",children:(0,e.jsx)(n.code,{children:\"STEP\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"STEP\"}),\" is the value stored in each path position. It can be any scalar expression over the input row:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`STEP event\nSTEP concat(event, ':', page)\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"A null step is omitted from the visible path. The row can still sit in the raw time span when other predicates match the original row.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"expand-by\",sectionTitle:\"EXPAND BY\",anchors:\"\",ancestors:\"define-the-event-streams\",index:\"13\",children:[(0,e.jsx)(n.h3,{id:\"expand-by\",children:(0,e.jsx)(n.code,{children:\"EXPAND BY\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"EXPAND BY\"}),\" splits a step by a property when a predicate is true:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`STEP event\nEXPAND BY plan WHEN (event = 'Checkout')\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"Matching events become \",(0,e.jsx)(n.code,{children:\"STRUCT(event, property)\"}),\". Non-matching events keep a null \",(0,e.jsx)(n.code,{children:\"property\"}),\". Different property values are different steps, so Checkout on \",(0,e.jsx)(n.code,{children:\"pro\"}),\" and Checkout on \",(0,e.jsx)(n.code,{children:\"free\"}),\" are distinct paths. A null \",(0,e.jsx)(n.code,{children:\"WHEN\"}),\" predicate is false. A true predicate with a null property still emits a visible expanded step.\"]}),`\n`,(0,e.jsx)(n.p,{children:\"Anchor, exclusion, and requirement predicates evaluate against the original input row, not the expanded struct.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"bound-a-path\",sectionTitle:\"Bound a path\",anchors:\"\",ancestors:\"\",index:\"14\",children:[(0,e.jsx)(n.h2,{id:\"bound-a-path\",children:\"Bound a path\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"within\",sectionTitle:\"WITHIN\",anchors:\"\",ancestors:\"bound-a-path\",index:\"15\",children:[(0,e.jsx)(n.h3,{id:\"within\",children:(0,e.jsx)(n.code,{children:\"WITHIN\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"WITHIN\"}),\" requires the path to finish inside a clock window:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`WITHIN INTERVAL 1 DAY\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"The interval is inclusive: an end event at exactly \",(0,e.jsx)(n.code,{children:\"start_time + interval\"}),\" still converts. One unit later does not. The expression must be a non-null, strictly positive, foldable DuckDB \",(0,e.jsx)(n.code,{children:\"INTERVAL\"}),\".\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"Without \",(0,e.jsx)(n.code,{children:\"WITHIN\"}),\" or \",(0,e.jsx)(n.code,{children:\"WITHIN SESSION\"}),\", a BETWEEN drop-off runs to the end of the partition.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"within-session\",sectionTitle:\"WITHIN SESSION\",anchors:\"\",ancestors:\"bound-a-path\",index:\"16\",children:[(0,e.jsx)(n.h3,{id:\"within-session\",children:(0,e.jsx)(n.code,{children:\"WITHIN SESSION\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"WITHIN SESSION\"}),\" keeps the path inside one session value instead of a clock window:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`WITHIN SESSION session_id\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"The start and end must share the same session column value. A null session value is a session break. You cannot combine \",(0,e.jsx)(n.code,{children:\"WITHIN\"}),\" and \",(0,e.jsx)(n.code,{children:\"WITHIN SESSION\"}),\".\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"Assign session IDs first with \",(0,e.jsx)(n.a,{href:\"/docs/lakehouse/features/sessionize\",children:(0,e.jsx)(n.code,{children:\"SESSIONIZE\"})}),\" when the source table does not already have them.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"max-steps\",sectionTitle:\"MAX STEPS\",anchors:\"\",ancestors:\"bound-a-path\",index:\"17\",children:[(0,e.jsx)(n.h3,{id:\"max-steps\",children:(0,e.jsx)(n.code,{children:\"MAX STEPS\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"MAX STEPS\"}),\" limits the retained visible path. The default is \",(0,e.jsx)(n.code,{children:\"9\"}),\":\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`MAX STEPS 9\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"Paths of 9 visible steps or fewer are untruncated. Longer paths keep the first 9 steps and set \",(0,e.jsx)(n.code,{children:\"truncated = true\"}),\". Conversion and duration still use the full raw span.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"collapse-repeats\",sectionTitle:\"COLLAPSE REPEATS\",anchors:\"\",ancestors:\"bound-a-path\",index:\"18\",children:[(0,e.jsx)(n.h3,{id:\"collapse-repeats\",children:(0,e.jsx)(n.code,{children:\"COLLAPSE REPEATS\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"COLLAPSE REPEATS\"}),\" merges consecutive identical visible steps after expansion and exclusion:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`COLLAPSE REPEATS\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"Repeated documentation visits become one \",(0,e.jsx)(n.code,{children:\"Docs\"}),\" step. After \",(0,e.jsx)(n.code,{children:\"EXPAND BY\"}),\", the same event with different property values does not collapse.\"]}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"filter-events-on-a-path\",sectionTitle:\"Filter events on a path\",anchors:\"\",ancestors:\"\",index:\"19\",children:[(0,e.jsx)(n.h2,{id:\"filter-events-on-a-path\",children:\"Filter events on a path\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"exclude-when\",sectionTitle:\"EXCLUDE WHEN\",anchors:\"\",ancestors:\"filter-events-on-a-path\",index:\"20\",children:[(0,e.jsx)(n.h3,{id:\"exclude-when\",children:(0,e.jsx)(n.code,{children:\"EXCLUDE WHEN\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"EXCLUDE WHEN\"}),\" hides matching rows from the visible path. They remain in the raw time span and still consume window time:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`EXCLUDE WHEN (event = 'Heartbeat')\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"An excluded start or end still bounds the span. You can repeat the clause.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"require\",sectionTitle:\"REQUIRE\",anchors:\"\",ancestors:\"filter-events-on-a-path\",index:\"21\",children:[(0,e.jsx)(n.h3,{id:\"require\",children:(0,e.jsx)(n.code,{children:\"REQUIRE\"})}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"REQUIRE\"}),\" keeps a candidate only when every required predicate appears in the raw span:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`REQUIRE (event = 'Checkout')\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"If a requirement is missing:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"PATHS BETWEEN\"}),\" with \",(0,e.jsx)(n.code,{children:\"UNIQUES\"}),\" emits a drop-off.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"PATHS BETWEEN\"}),\" with \",(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\" skips that start and resumes after it.\"]}),`\n`,(0,e.jsx)(n.li,{children:\"Starting-only and ending-only modes skip the candidate.\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"You can repeat the clause.\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"practical-patterns\",sectionTitle:\"Practical patterns\",anchors:\"\",ancestors:\"\",index:\"22\",children:[(0,e.jsx)(n.h2,{id:\"practical-patterns\",children:\"Practical patterns\"}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"split-checkout-by-plan\",sectionTitle:\"Split Checkout by plan\",anchors:\"\",ancestors:\"practical-patterns\",index:\"23\",children:[(0,e.jsx)(n.h3,{id:\"split-checkout-by-plan\",children:\"Split Checkout by plan\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use \",(0,e.jsx)(n.code,{children:\"EXPAND BY\"}),\" when the same event should become different steps for different property values:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`SELECT path, converted, count\nFROM events\nJOURNEYS (\n    PARTITION BY user_id\n    ORDER BY ts, event_id\n    STEP event\n    EXPAND BY plan WHEN (event = 'Checkout')\n    PATHS BETWEEN (event = 'Signup') AND (event = 'Purchase')\n    MEASURED AS EVENT TOTALS\n    WITHIN INTERVAL 1 DAY\n    COLLAPSE REPEATS\n)\nORDER BY count DESC, path;\n`})}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"paths-after-every-start\",sectionTitle:\"Paths after every start\",anchors:\"\",ancestors:\"practical-patterns\",index:\"24\",children:[(0,e.jsx)(n.h3,{id:\"paths-after-every-start\",children:\"Paths after every start\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"EVENT TOTALS\"}),\" counts every start event, including overlapping attempts by the same user:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`SELECT path, count\nFROM events\nJOURNEYS (\n    PARTITION BY user_id\n    ORDER BY ts, event_id\n    STEP event\n    PATHS STARTING WITH (event = 'Signup')\n    MEASURED AS EVENT TOTALS\n    WITHIN INTERVAL 1 DAY\n    MAX STEPS 9\n)\nORDER BY count DESC, path;\n`})}),`\n`]}),(0,e.jsxs)(t,{sectionId:\"learn-more\",sectionTitle:\"Learn more\",anchors:\"\",ancestors:\"\",index:\"25\",children:[(0,e.jsx)(n.h2,{id:\"learn-more\",children:\"Learn more\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:(0,e.jsx)(n.a,{href:\"/blog/2026-09-17-journeys-in-duckdb\",children:\"Event Paths in DuckDB\"})}),\": why \",(0,e.jsx)(n.code,{children:\"JOURNEYS\"}),\" exists and how it compares with SQL joins.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:(0,e.jsx)(n.a,{href:\"/docs/lakehouse/features/match-recognize\",children:\"MATCH_RECOGNIZE\"})}),\": find ordered row patterns with an explicit regular-expression-like pattern.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:(0,e.jsx)(n.a,{href:\"/docs/lakehouse/features/sessionize\",children:\"SESSIONIZE\"})}),\": assign events to gap-based sessions.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:(0,e.jsx)(n.a,{href:\"/docs/lakehouse/query/sql-explorer\",children:\"SQL Explorer\"})}),\": run and refine path queries interactively.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:(0,e.jsx)(n.a,{href:\"/docs/lakehouse/sql-engine\",children:\"SQL engine\"})}),\": learn about Altertable's DuckDB SQL dialect.\"]}),`\n`]})]})]})}function u(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,{...i,children:(0,e.jsx)(p,{...i})}):p(i)}function o(i,n){throw new Error(\"Expected \"+(n?\"component\":\"object\")+\" `\"+i+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return f(P);})();\n;return Component;"},"_id":"docs/lakehouse/features/journeys.mdx","_raw":{"sourceFilePath":"docs/lakehouse/features/journeys.mdx","sourceFileName":"journeys.mdx","sourceFileDir":"docs/lakehouse/features","contentType":"mdx","flattenedPath":"docs/lakehouse/features/journeys"},"type":"Docs","path":"/lakehouse/features/journeys","level":3,"parent":"lakehouse/features"}