"""Helper functions related to Snowflake DB actions.""" from connectors import snowflake as snowdb from utils.db_utils import run_query, zip_resultproxy_dict from sql.select_all_distinct_single_field \ import SELECT_ALL_DISTINCT_SINGLE_FIELD from sql.select_all_single_field import \ SELECT_ALL_SINGLE_FIELD @snowdb.db_session_wrap def get_single_snowflake_field(session, field, table, distinct=False): """Get the value of a single field from snowflake. Args: session (SQLAlchemy): Session from db wrapper field (str): field name to retrieve table (str): table name to query distinct (bool): require distinct rows in result? Returns: dict """ params = { 'field_name': field, 'table_name': table } sql = SELECT_ALL_DISTINCT_SINGLE_FIELD if distinct \ else SELECT_ALL_SINGLE_FIELD query_results = run_query(session, sql=sql, params=params) results = zip_resultproxy_dict(query_results) return results