-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfailed_metastore_export_decoder (2).py
More file actions
50 lines (45 loc) · 1.56 KB
/
failed_metastore_export_decoder (2).py
File metadata and controls
50 lines (45 loc) · 1.56 KB
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
import argparse
import json
import pandas as pd
def _read_log_file(logFile):
print(f"Reading log file {logFile}...")
fLog = open(logFile, "r")
logData = fLog.read()
fLog.close()
print("Log file read.")
return logData
def _get_failed_tables(logData):
print("Generating failed tables...")
allFailedTables = []
failedReasons = []
try:
for log in logData.split("\n"):
logJSON = json.loads(log)
failedTable = logJSON['table']
failedReason = logJSON['summary'][:200]
print(failedTable)
allFailedTables.append(failedTable)
failedReasons.append(failedReason)
except json.decoder.JSONDecodeError:
pass
return allFailedTables, failedReasons
def _report(allFailedTables, failedReasons):
print(f"Failed tables: {len(allFailedTables)}")
print(f"Failed reasons: {len(failedReasons)}")
print("Saving in log file failed_tables.csv ...")
pd.DataFrame.from_dict(
dict({
"failed_table": allFailedTables,
"failed_reason": failedReasons
})
).to_csv("failed_tables.csv")
print("Saved.")
def main(LOGFILE):
logData = _read_log_file(LOGFILE)
allFailedTables, failedReasons = _get_failed_tables(logData)
_report(allFailedTables, failedReasons)
if __name__=="__main__":
parser = argparse.ArgumentParser(description="Generate failed tables list.")
parser.add_argument("--LOGFILE", "--LOG", dest="LOGFILE", help="Path to failed log metastore file.")
parser = parser.parse_args()
main(parser.LOGFILE)