-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.py
51 lines (44 loc) · 1.39 KB
/
cleanup.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import collections.abc
def parse_args():
"""
Parse arguments from sys.argv into dictionary.
Repeated arguments will be grouped into an array.
For example, "--foo=bar --foo=party --bar=foo" will generate the following:
dict(
"foo": ["bar", "party"],
"bar": "foo"
)
"""
args = {}
for arg in sys.argv[1:]:
split = arg.split("=", 1)
key = split[0]
if key.startswith("--"):
key = key[2:]
val = split[1]
if key in args:
if not isinstance(args[key], collections.abc.Sequence):
args[key] = [args[key]]
args[key].append(val)
else:
args[key] = val
return args
def sanitize(securable):
"""
Sanitizes the three level namespace securable name so that it supports schema names such as "2024"
ex: catalog.2024.table -> `catalog`.`2024`.`table`
"""
return ".".join(map(lambda x: "`" + x + "`", securable.split(".")))
def main():
"""
This program will take in the following arguments:
--materialization_full_table_name
The location the materialization
It will then delete the specified materialization table.
"""
args = parse_args()
materialization_full_table_name = sanitize(args["materialization_full_table_name"])
spark.sql(f"DROP TABLE IF EXISTS {materialization_full_table_name}")
if __name__ == '__main__':
main()