forked from bellwether/minerva
added examples
This commit is contained in:
parent
ffdd27e506
commit
f4dd130266
5 changed files with 102 additions and 0 deletions
16
examples/athena_basic_execute.py
Normal file
16
examples/athena_basic_execute.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import minerva
|
||||
import pprint
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
m = minerva.Minerva("hay")
|
||||
athena = m.athena("s3://haystac-pmo-athena/")
|
||||
|
||||
query = athena.execute(
|
||||
"""
|
||||
create database if not exists test
|
||||
"""
|
||||
)
|
||||
print(query.finish())
|
||||
print(query.runtime)
|
||||
|
||||
39
examples/athena_basic_query.py
Normal file
39
examples/athena_basic_query.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import minerva
|
||||
import pprint
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
m = minerva.Minerva("hay")
|
||||
athena = m.athena("s3://haystac-pmo-athena/")
|
||||
|
||||
#query = athena.query(
|
||||
#"""SELECT *
|
||||
#FROM trajectories.kitware
|
||||
#WHERE ST_Disjoint(
|
||||
# ST_GeometryFromText('POLYGON((103.6 1.2151693, 103.6 1.5151693, 104.14797 1.5151693, 104.14797 1.2151693, 103.6 1.2151693))'),
|
||||
# ST_Point(longitude, latitude)
|
||||
#)
|
||||
#""")
|
||||
|
||||
# Everything *needs* to have a column in order for parquet to work, so scalar
|
||||
# values have to be assigned something, so here we use `as count` to create
|
||||
# a temporary column called `count`
|
||||
#print(athena.query("select count(*) as count from trajectories.kitware").results().head(1))
|
||||
|
||||
query = athena.query(
|
||||
"""
|
||||
select round(longitude, 3) as lon, count(*) as count
|
||||
from trajectories.kitware
|
||||
where agent = 4
|
||||
group by round(longitude, 3)
|
||||
order by count(*) desc
|
||||
"""
|
||||
)
|
||||
data = query.results()
|
||||
pp.pprint(data.head(10))
|
||||
print(query.runtime)
|
||||
|
||||
#import IPython
|
||||
#IPython.embed()
|
||||
|
||||
|
||||
29
examples/launch_instances.py
Normal file
29
examples/launch_instances.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from minerva.pier import Pier
|
||||
from minerva.docker import Docker
|
||||
import sys
|
||||
|
||||
profile = "hay"
|
||||
pier = Pier(profile,
|
||||
subnet_id = "subnet-05eb26d8649a093e1", # project-subnet-public1-us-east-1a
|
||||
sg_groups = ["sg-0f9e555954e863954", # ssh
|
||||
"sg-0b34a3f7398076545"], # default
|
||||
iam = "S3+SSM+CloudWatch+ECR")
|
||||
|
||||
num = 0
|
||||
mach = pier.machine(ami = "ami-0b0cd81283738558a", # ubuntu 22.04 x86
|
||||
instance_type = "t3.medium",
|
||||
username = "ubuntu",
|
||||
name = f"minerva-{num}",
|
||||
variables = {"num": num})
|
||||
|
||||
# Running the machine in the HAYSTAC PMO account
|
||||
# Pulling a container from the HAYSTAC T&E account
|
||||
d = Docker(machine = mach,
|
||||
#container = "436820952613.dkr.ecr.us-east-1.amazonaws.com/test:latest",
|
||||
container = "amazon/aws-cli:latest",
|
||||
variables = {"num": num},
|
||||
stdout = sys.stdout)
|
||||
|
||||
d.create()
|
||||
d.run()
|
||||
#d.terminate()
|
||||
14
examples/redshift_basic_query.py
Normal file
14
examples/redshift_basic_query.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import minerva
|
||||
import pprint
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
m = minerva.Minerva("hay")
|
||||
red = m.redshift("s3://haystac-pmo-athena/",
|
||||
db="dev",
|
||||
cluster="redshift-cluster-1")
|
||||
query = red.query("select count(*) from myspectrum_schema.kitware where agent = 4")
|
||||
data = query.results()
|
||||
pp.pprint(data.head(10))
|
||||
print(query.runtime)
|
||||
|
||||
4
examples/s3_ls.py
Normal file
4
examples/s3_ls.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import minerva
|
||||
|
||||
m = minerva.Minerva("hay")
|
||||
print(list(m.s3.ls("s3://haystac-pmo-athena/")))
|
||||
Loading…
Add table
Add a link
Reference in a new issue