Google BigQuery в Visual Data Studio ошибка объявить переменную - PullRequest
0 голосов
/ 17 марта 2020

У меня запрос в Google BigQuery, такой же в коде, он хорошо работает в Google BigQuery, затем я скопировал в Visual Data Studio, есть ошибка «Ошибка конфигурации набора данных», я не понимаю эту ошибку введите описание изображения здесь , пожалуйста, помогите мне. Я думаю, что причиной проблемы является объявить переменную в BigQuery

DECLARE yesterday date;
DECLARE count_week01 INT64;--number user active in (last week -1)
DECLARE count_week0 INT64;--number user active in (last week)
DECLARE retention FLOAT64; -- % user has already actived
DECLARE churn_rate FLOAT64; -- % user has already leaved
DECLARE count_user_active_week0 INT64; -- % user has leave
DECLARE week0_begin string; --date begin of last week
DECLARE week0_end string; --date end of last week

DECLARE week01_begin string; --date begin of (last week - 1)
DECLARE week01_end string; --date end of (last week -1)

SET yesterday =  DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY);

--Set value for last week from yesterday
SET week0_begin =  FORMAT_DATE('%Y%m%d', DATE_ADD(yesterday, INTERVAL -6 DAY));
SET week0_end = FORMAT_DATE('%Y%m%d', yesterday);
--Set value for (last week -1) from yesterday
SET week01_begin =  FORMAT_DATE('%Y%m%d', DATE_ADD(yesterday, INTERVAL -13 DAY));
SET week01_end =   FORMAT_DATE('%Y%m%d', DATE_ADD(yesterday, INTERVAL -7 DAY));

--Count number user active time in last week -1
SET count_week01 = (SELECT COUNT(DISTINCT param.value.string_value) as phone
FROM  `analytics_223664948.events_*` ev,
UNNEST(event_params) AS param
WHERE ev.event_name = 'spl_active_time' and param.key = 'PhoneNumber' AND _TABLE_SUFFIX BETWEEN week01_begin AND week01_end);

--Count number user active time in last week
SET count_week0 = (SELECT COUNT(DISTINCT param.value.string_value) as phone
FROM  `analytics_223664948.events_*` ev,
UNNEST(event_params) AS param
WHERE ev.event_name = 'spl_active_time' and param.key = 'PhoneNumber' AND _TABLE_SUFFIX BETWEEN week0_begin AND week0_end);

--Join last week and last week -1
SET count_user_active_week0 = (SELECT COUNT(week0.phone) FROM
(
  (SELECT DISTINCT param.value.string_value as phone
  FROM  `analytics_223664948.events_*` ev,
  UNNEST(event_params) AS param
  WHERE ev.event_name = 'spl_active_time' and param.key = 'PhoneNumber' AND _TABLE_SUFFIX BETWEEN week0_begin AND week0_end) week0
  INNER JOIN 
  (SELECT DISTINCT param.value.string_value as phone
  FROM  `analytics_223664948.events_*` ev,
  UNNEST(event_params) AS param
  WHERE ev.event_name = 'spl_active_time' and param.key = 'PhoneNumber' AND _TABLE_SUFFIX BETWEEN week01_begin AND week01_end) week01
  ON week0.phone = week01.phone 
)
);
SET retention = 100*count_user_active_week0/count_week01;
SET churn_rate = 100 - retention;

SELECT week01_begin, week01_end, week0_begin, week0_end, count_week0, count_week01, retention, churn_rate

1 Ответ

0 голосов
/ 18 марта 2020

вы можете использовать с ... в качестве изменения для DECLARE

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...