我已经在标准SQL中为BigQuery编写了一些查询,这些查询计划于每天凌晨5点UTC + 2运行,但是它们返回空或空结果。
具体来说,查询正在查看前一天的数据,因此它们采用@run_date
参数并减去1天以获得用作_table_suffix
的正确日期(数据已按列划分) )。
我已经测试了手动运行查询的方法,既可以从控制台(将@run_date
切换为CURRENT_DATE()
),也可以通过使用当前日期作为运行日期手动安排回填。
WITH installs AS (
SELECT
COUNTIF(event_name="first_open" AND app_info.install_source="manual_install") AS manualInstalls,
COUNTIF(event_name="first_open" AND app_info.install_source <> "manual_install") AS appStoreOtherInstalls,
COUNTIF(event_name="first_open") AS installsTotal,
COUNTIF(event_name="app_remove" AND user_id IS NOT NULL) AS uninstallRegistered,
COUNTIF(event_name="app_remove" AND user_id IS NULL) AS uninstallUnregistered,
COUNTIF(event_name="app_remove") AS uninstallsTotal
FROM `project.dataset.events_*`
WHERE _table_suffix=CAST(FORMAT_DATE("%Y%m%d",DATE_SUB(@run_date, INTERVAL 1 DAY)) AS STRING)
),
maus AS (
SELECT
COUNT( DISTINCT
(SELECT
IF(
REGEXP_CONTAINS(user_id,
CASE
WHEN user_id LIKE "+237%" THEN r"\+237((67)|(8[0-3])|(5[0-4]))"
WHEN user_id LIKE "+27%" THEN r"\+27((83)|(810)|(6((0[3-5])|(3([0-5]|[8-9]))|(40)|(5[5-7])))|7(1(0|[7-9])|(3|8)))"
WHEN user_id LIKE "+225%" THEN r"\+225(0|[4-8])[4-6]"
WHEN user_id LIKE "+242%" THEN r"\+24206[4-9]"
END
),
user_id, "")
)
) AS mauNetwork,
count(DISTINCT user_id) AS mau
FROM `project.dataset.events_*`
WHERE _table_suffix BETWEEN CAST(FORMAT_DATE("%Y%m%d",DATE_SUB(@run_date, INTERVAL 30 DAY)) AS STRING)
AND CAST(FORMAT_DATE("%Y%m%d",DATE_SUB(@run_date, INTERVAL 1 DAY)) AS STRING)
)
SELECT
CAST(FORMAT_DATE("%Y%m%d", DATE_SUB(@run_date, INTERVAL 1 DAY)) AS STRING) AS event_date,
IF(installs.manualInstalls IS NOT NULL, installs.manualInstalls, 0) AS manualInstalls,
IF(installs.appStoreOtherInstalls IS NOT NULL, installs.appStoreOtherInstalls, 0) AS appStoreOtherInstalls,
IF(installs.installsTotal IS NOT NULL, installs.installsTotal, 0) AS installsTotal,
IF(installs.uninstallRegistered IS NOT NULL, installs.uninstallRegistered, 0) AS uninstallRegistered,
IF(installs.uninstallUnregistered IS NOT NULL, installs.uninstallUnregistered, 0) AS uninstallNotRegistered,
IF(installs.uninstallsTotal IS NOT NULL, installs.uninstallsTotal, 0) AS uninstallsTotal,
IF(maus.mau IS NOT NULL, maus.mau, 0) AS mau,
IF(maus.mauNetwork IS NOT NULL, maus.mauNetwork, 0) AS mauNetwork
FROM installs, signUps, daus, maus
我希望所有列都被填充,但是由于它们为空,所以将它们填充为零。名为maus
的子查询块确实返回了结果,但是它的窗口更长了-我怀疑按照我的方式检索前一天数据的逻辑可能存在问题。
我非常感谢您的任何见解/建议!
答案 0 :(得分:0)
潜在的问题是这些表根本无法在凌晨5点使用。在处理Firebase导出到BigQuery时需要考虑两个因素。
Firebase将当天的数据存储在<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@drawable/custom_alert_dialog"
android:layout_height="match_parent">
<TextView
android:background="@color/Blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Warning"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
android:id="@+id/btn_confirm"
android:layout_width="100dp"
android:layout_height="30dp"
/>
<Button
android:id="@+id/btn_quit"
android:layout_width="100dp"
android:layout_height="30dp"
/>
</LinearLayout>
表中,当它决定关闭该表时,会将其写入永久events_intraday_*
表中。此过程可能需要一些时间,甚至可能需要一整天,尽管这种情况很少见。
然后,根据您在Firebase本身中的时区设置,表格将在一天的晚些时候关闭。
基本上,以后再运行查询,一切都会按预期进行。不幸的是,有时由于处理的运行时间比预期的要晚而仍然无法使用,因此有两种选择-编写具有内部逻辑以检查表的可用性的自定义调度程序,或者编写查询以检查其自身的方式首先要提供数据。