This commit is contained in:
Anna Scholtz 2020-12-08 15:00:17 -08:00
Родитель 24cb0314e8
Коммит b6abb264ab
1 изменённых файлов: 19 добавлений и 64 удалений

Просмотреть файл

@ -1,82 +1,38 @@
DECLARE datasets ARRAY<STRING>;
DECLARE tables ARRAY<STRING>; DECLARE tables ARRAY<STRING>;
DECLARE i INT64 DEFAULT 0; DECLARE i INT64 DEFAULT 0;
DECLARE t INT64 DEFAULT 0; SET tables = (
DECLARE ignored_tables ARRAY<STRING>;
-- tables that should be ignored, e.g. because we don't have permission to access them
SET ignored_tables = ["telemetry_stable.regrets_reporter_update_v4"];
SET datasets = (
SELECT SELECT
ARRAY_AGG(schema_name) ARRAY_AGG(CONCAT(dataset_id, ".", table_id))
FROM FROM
`moz-fx-data-shared-prod.INFORMATION_SCHEMA.SCHEMATA` `moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1
WHERE
schema_name LIKE '%_stable%'
); );
CREATE TEMP TABLE CREATE TEMP TABLE
total_pings(dataset_id STRING, table_id STRING, total INT64); total_pings(table_id STRING, total INT64);
LOOP LOOP
SET i = i + 1; SET i = i + 1;
IF IF
i > ARRAY_LENGTH(datasets) i > ARRAY_LENGTH(tables)
THEN THEN
LEAVE; LEAVE;
END IF; END IF;
CREATE OR REPLACE TEMP TABLE tables(table_name STRING);
EXECUTE IMMEDIATE ''' EXECUTE IMMEDIATE '''
INSERT tables INSERT total_pings
SELECT table_name SELECT "''' | |tables[
FROM `moz-fx-data-shared-prod`. ''' | |datasets[
ORDINAL(i) ORDINAL(i)
] | |'''.INFORMATION_SCHEMA.TABLES ] | |'''" AS table_id,
'''; COUNT(*) AS total
FROM `moz-fx-data-shared-prod`.''' | |tables[
SET tables = (SELECT ARRAY_AGG(table_name) FROM tables); ORDINAL(i)
] | |'''
SET t = 0; WHERE
DATE(submission_timestamp) = @submission_date
LOOP ''';
SET t = t + 1;
IF
t > ARRAY_LENGTH(tables)
THEN
LEAVE;
END IF;
IF
tables[ORDINAL(t)] NOT IN UNNEST(ignored_tables)
THEN
EXECUTE IMMEDIATE '''
INSERT total_pings
SELECT "''' | |datasets[
ORDINAL(i)
] | |'''" AS dataset_id,
"''' | |tables[
ORDINAL(t)
] | |'''" AS table_id,
COUNT(*) AS total
FROM `moz-fx-data-shared-prod`.''' | |datasets[
ORDINAL(i)
] | |'''.''' | |tables[
ORDINAL(t)
] | |'''
WHERE
DATE(submission_timestamp) = @submission_date
''';
END IF;
END LOOP;
END LOOP; END LOOP;
SELECT SELECT
@ -85,10 +41,9 @@ SELECT
table_id, table_id,
COALESCE(SAFE_DIVIDE(byte_size, total), 0) AS average_byte_size COALESCE(SAFE_DIVIDE(byte_size, total), 0) AS average_byte_size
FROM FROM
total_pings total_pings t
LEFT JOIN LEFT JOIN
`moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1 `moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1 s
USING
(table_id, dataset_id)
WHERE WHERE
submission_date = @submission_date CONCAT(s.dataset_id, ".", s.table_id) = t.table_id
AND submission_date = @submission_date