我在理解如何利用Vertica的match子句来识别用户在我们的网站上搜索某些内容(event_category =“搜索”)然后看到产品轮播项目(product_list =“ banner”并且event_action ='impression')。
我想识别的模式之前,之后和期间都会捕获各种事件,因为页面上显示的产品数量以及用户对我们网站的参与程度可能会因会话而异。
原始数据示例
| hit_number | product_list | Event_Category | Event_Action | Event_Label |
|------------|----------------------|----------------|--------------|---------------|
| 105 | (null) | Search | Submit | chocolate |
| 106 | (null) | eec | impression | search-result |
| 107 | search-result | eec | impression | sendData |
| 107 | search-result | eec | impression | sendData |
| 107 | search-result | eec | impression | sendData |
| 107 | search-result | eec | impression | sendData |
| 108 | (null) | (null) | (null) | (null) |
| 109 | (null) | eec | impression | banner |
| 110 | banner-105-chocolate | eec | impression | sendData |
| 110 | banner-105-chocolate | eec | impression | sendData |
| 110 | banner-105-chocolate | eec | impression | sendData |
为使模式有效,必须至少有1个搜索事件和1次横幅展示,我已将模式设置为(Search + Banner +)来反映这一点,但是运行execute时我不返回任何结果SQL查询如下所示。
SELECT
page_title
,event_label
,event_name()
,match_id()
,pattern_id()
FROM
(SELECT
unique_visit_id
,hit_number
,event_category
,event_label
,event_action
,product_list
FROM
atomic.ga_sessions_hits_product_expanded
WHERE
1=1
AND ga_sessions_date >= CURRENT_DATE -3
AND unique_visit_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ORDER BY
hit_number ASC) base
Match
(Partition by unique_visit_id Order by hit_number
Define
Search as event_category ='Search' and event_action = 'Submit',
Banner as product_list ilike 'banner-%' and event_action ='impression'
Pattern
P as (Search+ BannerImpression+)
ROWS MATCH FIRST EVENT)
请让我知道是否有任何需要澄清的地方,我们将不胜感激!
答案 0 :(得分:0)
首先,您要进行分区的列不在示例输入中。我添加了它,并为输入数据中的所有行赋予了值42。
您的问题是,在该数据段中没有模式,您命名为banner
的事件紧随您命名为search
的事件之后
最后,我在DEFINE子句中添加了另一个事件。如果其他两个都不为真,则将选择最后一个(定义为other AS true
)(这是ROWS MATCH FIRST EVENT的行为)。
然后该模式变为(search+ other* banner+)
,然后找到该模式。
查看此处:
WITH
ga_sessions_hits_product_expanded(
unique_visit_id,hit_number,product_list,Event_Category,Event_Action,Event_Label
) AS (
SELECT 42,105,NULL,'Search','Submit','chocolate'
UNION ALL SELECT 42,106,NULL,'eec','impression','search-result'
UNION ALL SELECT 42,107,'search-result','eec','impression','sendData'
UNION ALL SELECT 42,107,'search-result','eec','impression','sendData'
UNION ALL SELECT 42,107,'search-result','eec','impression','sendData'
UNION ALL SELECT 42,107,'search-result','eec','impression','sendData'
UNION ALL SELECT 42,108,NULL,NULL,NULL,NULL
UNION ALL SELECT 42,109,NULL,'eec','impression','banner'
UNION ALL SELECT 42,110,'banner-105-chocolate','eec','impression','sendData'
UNION ALL SELECT 42,110,'banner-105-chocolate','eec','impression','sendData'
UNION ALL SELECT 42,110,'banner-105-chocolate','eec','impression','sendData'
)
SELECT
*
, event_name()
, pattern_id()
, match_id()
FROM ga_sessions_hits_product_expanded
MATCH(
PARTITION BY unique_visit_id ORDER BY hit_number
DEFINE
search AS event_category='Search' AND event_action='Submit'
, banner AS product_list ILIKE 'banner-%' AND event_action='impression'
, other AS true
PATTERN p AS (search+ other* banner+)
ROWS MATCH FIRST EVENT
);
-- out Null display is "NULL".
-- out unique_visit_id | hit_number | product_list | Event_Category | Event_Action | Event_Label | event_name | pattern_id | match_id
-- out -----------------+------------+----------------------+----------------+--------------+---------------+------------+------------+----------
-- out 42 | 105 | NULL | Search | Submit | chocolate | search | 1 | 1
-- out 42 | 106 | NULL | eec | impression | search-result | other | 1 | 2
-- out 42 | 107 | search-result | eec | impression | sendData | other | 1 | 3
-- out 42 | 107 | search-result | eec | impression | sendData | other | 1 | 4
-- out 42 | 107 | search-result | eec | impression | sendData | other | 1 | 5
-- out 42 | 107 | search-result | eec | impression | sendData | other | 1 | 6
-- out 42 | 108 | NULL | NULL | NULL | NULL | other | 1 | 7
-- out 42 | 109 | NULL | eec | impression | banner | other | 1 | 8
-- out 42 | 110 | banner-105-chocolate | eec | impression | sendData | banner | 1 | 9
-- out 42 | 110 | banner-105-chocolate | eec | impression | sendData | banner | 1 | 10
-- out 42 | 110 | banner-105-chocolate | eec | impression | sendData | banner | 1 | 11
-- out (11 rows)
-- out
-- out Time: First fetch (11 rows): 50.632 ms. All rows formatted: 50.721 ms