Skip to content

Instantly share code, notes, and snippets.

@prasanthj
Forked from t3rmin4t0r/ats-extract-plan.py
Last active August 4, 2017 20:58
Show Gist options
  • Save prasanthj/8c14413ba7de60447e2a76ed44892063 to your computer and use it in GitHub Desktop.
Save prasanthj/8c14413ba7de60447e2a76ed44892063 to your computer and use it in GitHub Desktop.
ATS to Hive query plan extraction
import json
import os,sys
class ATSFile(object):
def __init__(self, name):
self.data = json.load(open(name))
self.name = name
def dump(self):
if "hive_query_id" in self.data:
info = self.data["hive_query_id"]["otherinfo"]
else:
info = self.data["otherinfo"]
q = json.loads(info["QUERY"])
txt = q["queryText"]
plan = q["queryPlan"]
queryFile = self.name + "-query.txt"
planFile = self.name + "-plan.txt"
open(queryFile, "w").write(txt)
json.dump(plan, open(planFile,"w"), indent=2)
print ("Query written to " + os.path.abspath(queryFile))
print ("Query plan written to " + os.path.abspath(planFile))
def main(args):
data = [ATSFile(f) for f in args]
for d in data:
d.dump()
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment