output consolidation; added executable via poetry

This commit is contained in:
Ari Brown 2023-09-19 16:12:58 -04:00
parent ab344374d9
commit ffe0eddd9b
4 changed files with 46 additions and 34 deletions

View file

@ -50,7 +50,11 @@ class Execute:
# Send the SQL to Athena for running
def run(self):
config = {"OutputLocation": self.athena.output}
if self.__class__ == Query:
config = {"OutputLocation": os.path.join(self.athena.output, "results")}
else:
config = {"OutputLocation": self.athena.output}
if self.params:
resp = self.client.start_query_execution(QueryString=self.query(),
ResultConfiguration=config,
@ -94,6 +98,7 @@ class Query(Execute):
# Automatically includes unloading the results to Parquet format
def query(self):
out = os.path.join(self.athena.output,
"results",
str(random.random()))
query = f"unload ({self.sql}) to {repr(out)} " + \
f"with (format = '{self.DATA_STYLE}')"

37
minerva/console.py Executable file
View file

@ -0,0 +1,37 @@
import minerva
import pprint
import readline
import argparse
def main():
pp = pprint.PrettyPrinter(indent=4)
parser = argparse.ArgumentParser(description="""
REPL for the Athena SQL engine
""")
parser.add_argument("-p", "--profile", default="hay", help="The AWS profile to use")
parser.add_argument("-o", "--output", default="s3://haystac-pmo-athena/")
args = parser.parse_args()
m = minerva.Minerva(args.profile)
athena = m.athena(args.output)
text = input("> ")
while text != "\\q":
try:
first_word = text.split()[0]
if first_word.lower() in ["drop", "alter", "create", "update"]:
query = athena.execute(text)
query.finish()
else:
query = athena.query(text)
data = query.results()
pp.pprint(data.head(10))
print()
print(f"\t({'$%.2f' % query.cost}, {query.runtime})")
except Exception as e:
print(e)
text = input("> ")