Simplify script
This commit is contained in:
Родитель
24cb0314e8
Коммит
b6abb264ab
|
@ -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 '''
|
|
||||||
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 '''
|
EXECUTE IMMEDIATE '''
|
||||||
INSERT total_pings
|
INSERT total_pings
|
||||||
SELECT "''' | |datasets[
|
SELECT "''' | |tables[
|
||||||
ORDINAL(i)
|
ORDINAL(i)
|
||||||
] | |'''" AS dataset_id,
|
|
||||||
"''' | |tables[
|
|
||||||
ORDINAL(t)
|
|
||||||
] | |'''" AS table_id,
|
] | |'''" AS table_id,
|
||||||
COUNT(*) AS total
|
COUNT(*) AS total
|
||||||
FROM `moz-fx-data-shared-prod`.''' | |datasets[
|
FROM `moz-fx-data-shared-prod`.''' | |tables[
|
||||||
ORDINAL(i)
|
ORDINAL(i)
|
||||||
] | |'''.''' | |tables[
|
|
||||||
ORDINAL(t)
|
|
||||||
] | |'''
|
] | |'''
|
||||||
WHERE
|
WHERE
|
||||||
DATE(submission_timestamp) = @submission_date
|
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
|
||||||
|
|
Загрузка…
Ссылка в новой задаче