Can we use `OR` or `IN` conditions to define a spe...
# questions-and-troubleshooting
m
Can we use
OR
or
IN
conditions to define a specific step in the
window_funnel
event chain in StarRocks? For example:
Copy code
SELECT uid,
       window_funnel(1800, time, 0, [
         event_type = 'Browse' OR event_type = 'Visit',
         event_type IN ('Click', 'Tap'),
         event_type = 'Order',
         event_type = 'Pay'
       ]) AS level
FROM events;
a
Copy code
CREATE TABLE events (
      uid INT,
      event_type VARCHAR(50),
      time DATETIME,
      page_url VARCHAR(200),
      amount DECIMAL(10,2)
  );

  -- Insert sample data
  INSERT INTO events VALUES
  -- User 1: Complete funnel (Browse -> Click -> Order -> Pay)
  (1, 'Browse', '2024-01-01 10:00:00', '/products', NULL),
  (1, 'Click', '2024-01-01 10:05:00', '/product/123', NULL),
  (1, 'Order', '2024-01-01 10:15:00', '/checkout', 99.99),
  (1, 'Pay', '2024-01-01 10:20:00', '/payment', 99.99),

  -- User 2: Uses Visit instead of Browse, Tap instead of Click
  (2, 'Visit', '2024-01-01 11:00:00', '/products', NULL),
  (2, 'Tap', '2024-01-01 11:03:00', '/product/456', NULL),
  (2, 'Order', '2024-01-01 11:10:00', '/checkout', 149.99),
  (2, 'Pay', '2024-01-01 11:12:00', '/payment', 149.99),

  -- User 3: Incomplete funnel (stops at Order)
  (3, 'Browse', '2024-01-01 12:00:00', '/products', NULL),
  (3, 'Click', '2024-01-01 12:02:00', '/product/789', NULL),
  (3, 'Order', '2024-01-01 12:08:00', '/checkout', 79.99),

  -- User 4: Different sequence, window exceeded
  (4, 'Visit', '2024-01-01 13:00:00', '/products', NULL),
  (4, 'Click', '2024-01-01 14:00:00', '/product/321', NULL),  -- 1 hour later, may exceed window
  (4, 'Order', '2024-01-01 14:05:00', '/checkout', 199.99),
  (4, 'Pay', '2024-01-01 14:10:00', '/payment', 199.99),

  -- User 5: Extra events that should be ignored
  (5, 'Browse', '2024-01-01 15:00:00', '/products', NULL),
  (5, 'Search', '2024-01-01 15:01:00', '/search', NULL),      -- Extra event
  (5, 'Tap', '2024-01-01 15:03:00', '/product/654', NULL),
  (5, 'AddCart', '2024-01-01 15:04:00', '/cart', NULL),       -- Extra event
  (5, 'Order', '2024-01-01 15:10:00', '/checkout', 299.99),
  (5, 'Pay', '2024-01-01 15:15:00', '/payment', 299.99);

  -- Test queries

  -- 1. Basic window_funnel with OR/IN conditions (30-minute window)
  SELECT
      uid,
      window_funnel(1800, time, 0, [
          event_type = 'Browse' OR event_type = 'Visit',
          event_type IN ('Click', 'Tap'),
          event_type = 'Order',
          event_type = 'Pay'
      ]) AS funnel_level
  FROM events
  GROUP BY uid
  ORDER BY uid;

  -- 2. Comparison: using exact matches only
  SELECT
      uid,
      window_funnel(1800, time, 0, [
          event_type = 'Browse',  -- Only Browse, not Visit
          event_type = 'Click',   -- Only Click, not Tap
          event_type = 'Order',
          event_type = 'Pay'
      ]) AS funnel_level_strict
  FROM events
  GROUP BY uid
  ORDER BY uid;

  -- 3. With different window sizes
  SELECT
      uid,
      window_funnel(3600, time, 0, [  -- 1-hour window
          event_type = 'Browse' OR event_type = 'Visit',
          event_type IN ('Click', 'Tap'),
          event_type = 'Order',
          event_type = 'Pay'
      ]) AS funnel_level_1h,
      window_funnel(1800, time, 0, [  -- 30-minute window
          event_type = 'Browse' OR event_type = 'Visit',
          event_type IN ('Click', 'Tap'),
          event_type = 'Order',
          event_type = 'Pay'
      ]) AS funnel_level_30m
  FROM events
  GROUP BY uid
  ORDER BY uid;

  -- 4. More complex conditions with AND/OR combinations
  SELECT
      uid,
      window_funnel(1800, time, 0, [
          event_type IN ('Browse', 'Visit'),
          event_type IN ('Click', 'Tap') AND page_url LIKE '/product/%',
          event_type = 'Order' AND amount > 100,
          event_type = 'Pay'
      ]) AS funnel_level_complex
  FROM events
  GROUP BY uid
  ORDER BY uid;

  -- Expected results for query 1:
  -- uid=1: level 4 (complete funnel: Browse->Click->Order->Pay)
  -- uid=2: level 4 (complete funnel: Visit->Tap->Order->Pay)
  -- uid=3: level 3 (stops at Order: Browse->Click->Order)
  -- uid=4: level 4 or lower depending on window (Visit->Click->Order->Pay, but timing matters)
  -- uid=5: level 4 (complete funnel: Browse->Tap->Order->Pay, extra events ignored)
It’s supported. You can have a look of above cases.
👍 1