-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoverlapping_table_locations.hql
35 lines (34 loc) · 1.51 KB
/
overlapping_table_locations.hql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
USE ${DB};
WITH D_TBL_LOCATIONS AS (
SELECT DISTINCT
db_name
, tbl_name
, tbl_type
, part_name
, CASE
WHEN PART_NAME IS NULL
THEN regexp_extract(tbl_location, 'hdfs://([^/]+)(.*)', 2)
WHEN PART_NAME IS NOT NULL
THEN regexp_extract(part_location, 'hdfs://([^/]+)(.*)', 2)
END AS tbl_location
FROM
hms_dump_${ENV}
WHERE
db_name != 'sys'
AND db_name != 'information_schema'
)
SELECT
tbl_location
, SIZE(COLLECT_SET(
CONCAT(db_name, ".", tbl_name, "[Partition:", NVL(part_name, "DEFAULT"), "]"))) AS TBL_PARTS_SHARING_LOCATION
, COLLECT_SET(CONCAT(db_name, ".", tbl_name, "[Partition:", NVL(part_name, "DEFAULT"), "]", ":(", tbl_type,
")")) AS DB_TBLS
FROM
D_TBL_LOCATIONS
WHERE
db_name != 'sys'
AND db_name != 'information_schema'
GROUP BY tbl_location
HAVING
SIZE(COLLECT_SET(
CONCAT(db_name, ".", tbl_name, "[Partition:", NVL(part_name, "DEFAULT"), "]", ":(", tbl_type, ")"))) > 1;