Reads the query runtime information at 'path' and returns a dict >. Returns an empty dict if the hosts in the 'impala' instance do not match the data in 'path'.
(path, impala=None)
| 65 | |
| 66 | |
| 67 | def load_runtime_info(path, impala=None): |
| 68 | """Reads the query runtime information at 'path' and returns a |
| 69 | dict<db_name, dict<sql, Query>>. Returns an empty dict if the hosts in the 'impala' |
| 70 | instance do not match the data in 'path'. |
| 71 | """ |
| 72 | queries_by_db_and_sql = defaultdict(lambda: defaultdict(dict)) |
| 73 | if not os.path.exists(path): |
| 74 | return queries_by_db_and_sql |
| 75 | with open(path) as file: |
| 76 | store = json.load(file) |
| 77 | _check_store_version(store) |
| 78 | if ( |
| 79 | impala and |
| 80 | store.get("host_names") != sorted([i.host_name for i in impala.impalads]) |
| 81 | ): |
| 82 | return queries_by_db_and_sql |
| 83 | for db_name, queries_by_sql in store["db_names"].items(): |
| 84 | for sql, queries_by_options in queries_by_sql.items(): |
| 85 | for options, json_query in queries_by_options.items(): |
| 86 | query = Query() |
| 87 | query.__dict__.update(json_query) |
| 88 | query.sql = sql |
| 89 | queries_by_db_and_sql[db_name][sql][options] = query |
| 90 | return queries_by_db_and_sql |
| 91 | |
| 92 | |
| 93 | def _check_store_version(store): |