google-bigquery - BigQuery 问题 - 使用路径表进行归因建模
问题描述
这可能是一个基本问题,但我就是想不通。样本数据和查询可以在这里找到。
查询的目的是找出将信用归因于哪个位置。在第一次接触模型中,最早的接触导致转化 (FLOODLIGHT) 被记入贷方。所以这里 22 有 1 个学分,11 有 2 个学分。我不太了解第一个棘手的查询,尤其是未嵌套的部分。比较有什么意义prev_conversion_event.event_time < conversion_event.event_time
?它们本质上不一样吗?我的意思是他们俩都来自UNNEST(t.*_path.events)
. 而且attributed_event.event_time
也来自同一个地方。我只是在这里感到困惑。非常感谢帮助!
为方便起见,我在下面粘贴示例数据和查询:
/* Substitute *_paths for the specific paths table that you want to query. */
SELECT
(
SELECT
attributed_event_metadata.placement_id
FROM (
SELECT
AS STRUCT attributed_event.placement_id,
ROW_NUMBER() OVER(ORDER BY attributed_event.event_time ASC) AS rank
FROM
UNNEST(t.*_paths.events) AS attributed_event
WHERE
attributed_event.event_type != "FLOODLIGHT"
AND attributed_event.event_time < conversion_event.event_time
AND attributed_event.event_time > (
SELECT
IFNULL( (
SELECT
MAX(prev_conversion_event.event_time) AS event_time
FROM
UNNEST(t.*_paths.events) AS prev_conversion_event
WHERE
prev_conversion_event.event_type = "FLOODLIGHT"
AND prev_conversion_event.event_time < conversion_event.event_time),
0)) ) AS attributed_event_metadata
WHERE
attributed_event_metadata.rank = 1) AS placement_id,
COUNT(*) AS credit
FROM
adh.*_paths AS t,
UNNEST(*_paths.events) AS conversion_event
WHERE
conversion_event.event_type = "FLOODLIGHT"
GROUP BY
placement_id
HAVING
placement_id IS NOT NULL
ORDER BY
credit DESC
解决方案
比较两者prev_conversion_event.event_time
和的点conversion_event.event_time
暗示了分配给每个值的名称。
我们想要的是找到两个 Floodlight 之间的所有事件。然后,您需要检查您的事件attributed_event
是否不是 Floodlight,并且它位于两个 Floodlight 之间,即
attributed_event.event_type != "FLOODLIGHT"
attributed_event.event_time < conversion_event.event_time
attributed_event.event_time > MAX(prev_conversion_event.event_time)
whereMAX(prev_conversion_event.event_time)
必须将以前的 Floodlight 反射到当前的 Floodlight conversion_event.event_time
,因此您需要
prev_conversion_event.event_type = "FLOODLIGHT"
conversion_event.event_type = "FLOODLIGHT"
prev_conversion_event.event_time < conversion_event.event_time
当然,所有三个元素 prev_conversion、conversion 和属性都是从相同的事件中获得的(带有额外的过滤),因此您需要从同一列中获取它们
UNNEST(t.*_paths.events) AS prev_conversion_event WHERE ...
UNNEST(t.*_paths.events) AS conversion_event WHERE ...
UNNEST(t.*_paths.events) AS attributed_event WHERE ...
然后,您只需按正确顺序组合前面的条件,并为每个用例(首次接触、最后接触、线性)添加适当的排名和信用。
我希望这个解释足够清楚。如果有不清楚的地方,请告诉我,以便我帮助您进一步理解。
推荐阅读
- bash - grep 命令的说明
- java - java - 如何在Java中的Quartz集群中将具有triggerstate的作业解锁为ERROR
- svelte - 如何遍历列表并在 svelte 中每行显示 4 个项目
- apache-flink - 使用 POJO 的状态模式演变
- rust - 如何使用自定义波特率读取串口?
- python - 尝试合并不同的文件 csv 并标记列
- python - 如何使用日志记录来创建每个方法调用的日志?
- vb.net - VB .Net水晶报表每页末尾打印一段
- apache-spark - Databricks:结构化流因 TimeoutException 而失败
- python - 从多个脚本插入 Mariadb