Skip to content

Commit

Permalink
Commenting, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Aug 25, 2023
1 parent 40660e8 commit dfad146
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
5 changes: 2 additions & 3 deletions cumulus_library/studies/core/builder_soe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@


class SOEBuilder(BaseTableBuilder):
display_text = "Creating condition code table..."
display_text = "Creating SoE support tables..."

def prepare_queries(self, cursor: object, schema: str):
"""Constructs queries related to condition codeableConcept
"""Constructs tables for SOE QA verification
:param cursor: A database cursor object
:param schema: the schema/db name, matching the cursor
Expand Down Expand Up @@ -55,4 +55,3 @@ def prepare_queries(self, cursor: object, schema: str):
"core__soe_doc_period",
)
)
self.write_queries()
2 changes: 1 addition & 1 deletion cumulus_library/template_sql/object_denormalize.sql.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE "{{schema}}"."{{ target_table }}" AS (
CREATE TABLE "{{schema_name}}"."{{ target_table }}" AS (
SELECT
{{ source_id }},
{%- for key in field_config.keys() %}
Expand Down
49 changes: 29 additions & 20 deletions cumulus_library/template_sql/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def get_is_table_not_empty_query(
unnests: Optional[list[dict]] = [],
conditions: Optional[list[str]] = [],
):
"""Checks for presence of data, allowing for unnesting or filtering"""
path = Path(__file__).parent
with open(f"{path}/is_table_not_empty.sql.jinja") as is_table_not_empty:
return Template(is_table_not_empty.read()).render(
Expand All @@ -288,6 +289,34 @@ def get_is_table_not_empty_query(
)


def get_object_denormalize_query(
schema_name: str,
source_table: str,
source_id: str,
field: str,
field_config: dict,
target_table: str,
):
"""Generates a table by expanding a specified row element
:param schema_name: The athena query to create the table in
:param table_name: The name of the athena table to create
:param table_cols: Comma deleniated column names, i.e. ['first','second']
:param dataset: Array of data arrays to insert, i.e. [['1','3'],['2','4']]
"""
path = Path(__file__).parent
with open(f"{path}/object_denormalize.sql.jinja") as column_datatype:
return Template(column_datatype.read()).render(
schema_name=schema_name,
source_table=source_table,
source_id=source_id,
field=field,
field_config=field_config,
target_table=target_table,
)


def get_show_tables(schema_name: str, prefix: str) -> str:
"""Generates a show tables query, filtered by prefix
Expand Down Expand Up @@ -318,23 +347,3 @@ def get_show_views(schema_name: str, prefix: str) -> str:
return Template(show_tables.read()).render(
schema_name=schema_name, prefix=prefix
)


def get_object_denormalize_query(
schema: str,
source_table: str,
source_id: str,
field: str,
field_config: dict,
target_table: str,
):
path = Path(__file__).parent
with open(f"{path}/object_denormalize.sql.jinja") as column_datatype:
return Template(column_datatype.read()).render(
schema=schema,
source_table=source_table,
source_id=source_id,
field=field,
field_config=field_config,
target_table=target_table,
)

0 comments on commit dfad146

Please sign in to comment.