forked from bellwether/minerva
output consolidation; added executable via poetry
This commit is contained in:
parent
ab344374d9
commit
ffe0eddd9b
4 changed files with 46 additions and 34 deletions
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import minerva
|
||||
import pprint
|
||||
import readline
|
||||
import argparse
|
||||
|
||||
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/output")
|
||||
args = parser.parse_args()
|
||||
|
||||
m = minerva.Minerva(args.profile)
|
||||
athena = m.athena(args.output)
|
||||
|
||||
text = input("> ")
|
||||
while text != "\\q":
|
||||
query = athena.query(text)
|
||||
|
||||
try:
|
||||
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("> ")
|
||||
|
||||
|
|
@ -50,7 +50,11 @@ class Execute:
|
|||
|
||||
# Send the SQL to Athena for running
|
||||
def run(self):
|
||||
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
37
minerva/console.py
Executable 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("> ")
|
||||
|
||||
|
|
@ -9,10 +9,12 @@ authors = [
|
|||
]
|
||||
packages = [
|
||||
{ include = "minerva/**/*.py" },
|
||||
{ include = "bin/*" }
|
||||
]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
minerva-console = "minerva.console:main"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">3.9, <3.11"
|
||||
boto3 = "^1.26.161"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue