forked from bellwether/minerva
added sql loading code from metrics calculator to minerva
This commit is contained in:
parent
98524d3be6
commit
af4f8bb999
2 changed files with 20 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from .helpers import parallel_map, load_template
|
||||
from .helpers import parallel_map, load_template, load_sql
|
||||
|
||||
from .athena import Athena
|
||||
from .redshift import Redshift
|
||||
|
|
@ -19,6 +19,7 @@ __all__ = [
|
|||
"Pier",
|
||||
"Minerva",
|
||||
"parallel_map",
|
||||
"load_template"
|
||||
"load_template",
|
||||
"load_sql"
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -41,3 +41,20 @@ def load_template(path, **params):
|
|||
|
||||
return Template(query).render(**params)
|
||||
|
||||
|
||||
# `partition = {"field" => values}`
|
||||
def partition_string(partition):
|
||||
if not partition:
|
||||
return ""
|
||||
|
||||
parts = [f"{k} >= {min(v)} and {k} <= {max(v)}" for k, v in partition.items()]
|
||||
string = " and ".join(parts)
|
||||
|
||||
return string
|
||||
|
||||
|
||||
# Wrapper to enable the inclusion of partitioning strings
|
||||
def load_sql(path, **params):
|
||||
params['partition_string'] = partition_string(params.get('partition', None))
|
||||
return m.load_template(path, **params)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue