Simplify script
This commit is contained in:
Родитель
24cb0314e8
Коммит
b6abb264ab
|
@ -1,82 +1,38 @@
|
|||
DECLARE datasets ARRAY<STRING>;
|
||||
|
||||
DECLARE tables ARRAY<STRING>;
|
||||
|
||||
DECLARE i INT64 DEFAULT 0;
|
||||
|
||||
DECLARE t INT64 DEFAULT 0;
|
||||
|
||||
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 = (
|
||||
SET tables = (
|
||||
SELECT
|
||||
ARRAY_AGG(schema_name)
|
||||
ARRAY_AGG(CONCAT(dataset_id, ".", table_id))
|
||||
FROM
|
||||
`moz-fx-data-shared-prod.INFORMATION_SCHEMA.SCHEMATA`
|
||||
WHERE
|
||||
schema_name LIKE '%_stable%'
|
||||
`moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1
|
||||
);
|
||||
|
||||
CREATE TEMP TABLE
|
||||
total_pings(dataset_id STRING, table_id STRING, total INT64);
|
||||
total_pings(table_id STRING, total INT64);
|
||||
|
||||
LOOP
|
||||
SET i = i + 1;
|
||||
|
||||
IF
|
||||
i > ARRAY_LENGTH(datasets)
|
||||
i > ARRAY_LENGTH(tables)
|
||||
THEN
|
||||
LEAVE;
|
||||
END IF;
|
||||
|
||||
CREATE OR REPLACE TEMP TABLE tables(table_name STRING);
|
||||
|
||||
EXECUTE IMMEDIATE '''
|
||||
INSERT tables
|
||||
SELECT table_name
|
||||
FROM `moz-fx-data-shared-prod`. ''' | |datasets[
|
||||
ORDINAL(i)
|
||||
] | |'''.INFORMATION_SCHEMA.TABLES
|
||||
''';
|
||||
|
||||
SET tables = (SELECT ARRAY_AGG(table_name) FROM tables);
|
||||
|
||||
SET t = 0;
|
||||
|
||||
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[
|
||||
SELECT "''' | |tables[
|
||||
ORDINAL(i)
|
||||
] | |'''" AS dataset_id,
|
||||
"''' | |tables[
|
||||
ORDINAL(t)
|
||||
] | |'''" AS table_id,
|
||||
COUNT(*) AS total
|
||||
FROM `moz-fx-data-shared-prod`.''' | |datasets[
|
||||
FROM `moz-fx-data-shared-prod`.''' | |tables[
|
||||
ORDINAL(i)
|
||||
] | |'''.''' | |tables[
|
||||
ORDINAL(t)
|
||||
] | |'''
|
||||
WHERE
|
||||
DATE(submission_timestamp) = @submission_date
|
||||
''';
|
||||
END IF;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
|
||||
SELECT
|
||||
|
@ -85,10 +41,9 @@ SELECT
|
|||
table_id,
|
||||
COALESCE(SAFE_DIVIDE(byte_size, total), 0) AS average_byte_size
|
||||
FROM
|
||||
total_pings
|
||||
total_pings t
|
||||
LEFT JOIN
|
||||
`moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1
|
||||
USING
|
||||
(table_id, dataset_id)
|
||||
`moz-fx-data-shared-prod`.monitoring.stable_table_sizes_v1 s
|
||||
WHERE
|
||||
submission_date = @submission_date
|
||||
CONCAT(s.dataset_id, ".", s.table_id) = t.table_id
|
||||
AND submission_date = @submission_date
|
||||
|
|
Загрузка…
Ссылка в новой задаче