我很难为相当复杂的报告查询构建有效的BigQuery案例陈述。我正在使用的数据集已由Google Analytics填充。对于此查询,有很多情况,但这是我正在查看的案例之一:
CASE when previous page="^/XXX/[^/]+/apps/booking/flight/traveler\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Traveler info 2.0"
when previous page="^/web/[^/]+/apps/booking/flight/traveler\.aspx" and landing page="^/web/[^/]+/default\.aspx" then "Traveler info 1.0" when previous
请注意,XXX和网络是不同的情况。其中的缺点是需要确定页面路径是否是登录页面,以便处理案例。我目前在该领域有一个单独的问题。对于这个具体问题,我已经查看了许多资源,包括SO上的以下资源,which introduces the BigQuery case function.为了支持这个问题,这里将是构建的完整案例陈述。
Case when page = "^/XXX/[^/]+/default\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Homepage 2.0"
when page ="^/web/[^/]+/default\.aspx" and landing page = "^/web/[^/]+/default\.aspx" then "Homepage 1.0"
when page="^XXX/[^/]+/apps/booking?flight/(searchresult1|search(rt|ow|md))\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev inbound search 2.0"
when page="^web/[^/]+/apps/booking?flight/(searchresult1|search(rt|ow|md))\.aspx" and landing page="^/web/[^/]+/default\.aspx" then "Rev inbound search 1.0"
when page="^/XXX/[^/]+/apps/booking/flight/searchResult2\.aspx" and previous page ="^XXX/[^/]+/apps/booking?flight/(searchresult1|search(rt|ow|md))\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev outbound search 2.0"
when page="^/web/[^/]+/apps/booking/flight/searchResult2\.aspx" and previous page="^web/[^/]+/apps/booking?flight/(searchresult1|search(rt|ow|md))\.aspx" landing page="^/web/[^/]+/default\.aspx" then "Rev outbound search 1.0"
when page="^/XXX/[^/]+/apps/booking/flight/reviewRevenue\.aspx" and previous page="^/XXX/[^/]+/apps/booking/flight/searchResult2\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev review itinerary 2.0"
when page="^/web/[^/]+/apps/booking/flight/reviewRevenue\.aspx" and previous page="^/web/[^/]+/apps/booking/flight/searchResult2\.aspx" and landing page="^/web/[^/]+/default\.aspx" then "Rev review itinerary 1.0"
when page="^/XXX/[^/]+/apps/booking/flight/traveler\.aspx" and previous page="^/XXX/[^/]+/apps/booking/flight/reviewRevenue\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev traveler info 2.0"
when page="^/web/[^/]+/apps/booking/flight/traveler\.aspx" and previous page="^/web/[^/]+/apps/booking/flight/reviewRevenue\.aspx" and landing page="^/web/[^/]+/default\.aspx" then "Rev traveler info 1.0"
when page="^/XXX/[^/]+/apps/booking/flight/seatSelector\.aspx" and previous page="^/XXX/[^/]+/apps/booking/flight/traveler\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev seat selector 2.0"
when page="^/web/[^/]+/apps/booking/flight/seatSelector\.aspx" and previous page="^/web/[^/]+/apps/booking/flight/traveler\.aspx" and landing page="^/web/[^/]+/default\.aspx" then "Rev seat selector 1.0"
when page="^/XXX/[^/]+/apps/booking/flight/billingRevenue\.aspx" and previous page="^/XXX/[^/]+/apps/booking/flight/seatSelector\.aspx" and landing page="^/XXX/[^/]+/default\.aspx" then "Rev payment info 2.0"
我的第一个本能就是创建一个新列(可能),查看用户用来确定唯一访问应该属于哪种情况的路径。这可能不是最佳方向,也是我正在探索的方向。另一种是直接使用case函数。任何初步支持或洞察力都可以解决这一部分查询的最佳方式。
答案 0 :(得分:2)
这取决于您运行查询的频率。 如果是Ad Hoc分析,我不会为创建新字段而烦恼。 如果你打算经常运行它,我会在填充BQ表时创建一个额外的字段,并在那里保存一个带有相关信息的短字符串。
问题不在于查询的效率(让BQ的人担心这一点),而是关于查询成本。经常查询具有很长字符串的字段(例如URL)是很昂贵的。如果您可以保留一个明显更短的预先计算的字符串,您可以节省一些钱。
我建议您探索的另一个选项是使用Regx_Extract函数解析字符串。它可能更具可读性,而且更短。 希望这有帮助