"""Task to snapshot flattened contract_term_condition.conditions into Snowflake.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from lib.constants import CONTRACT_TERM_CONDITIONS from tasks.accounting_run_calculate_nr import helpers from templates.accounting_run_calculate import \ snowflake_snapshot_flat_contract_term_conditions as templates def snapshot_flat_contract_term_conditions_task( dag_run: dict, condition_type: str, **kwargs ) -> None: """Flatten nested contract_term_conditions and insert into snapshot snowflake. Args: dag_run (dict): config of the DAG this task belongs to condition_type (str): one of 'countries', 'stores', or 'transaction_types' kwargs (dict): any other optional arguments """ event = helpers.get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) if condition_type == CONTRACT_TERM_CONDITIONS.COUNTRIES: insert_statement = \ templates.snapshot_flat_contract_term_condition_countries_template().render( accounting_run_id=accounting_run_id, schema=config.OWS_ENV ) elif condition_type == CONTRACT_TERM_CONDITIONS.STORES: insert_statement = \ templates.snapshot_flat_contract_term_condition_stores_template().render( accounting_run_id=accounting_run_id, schema=config.OWS_ENV ) elif condition_type == CONTRACT_TERM_CONDITIONS.TRANSACTION_TYPES: insert_statement = templates\ .snapshot_flat_contract_term_condition_transaction_types_template() \ .render( accounting_run_id=accounting_run_id, schema=config.OWS_ENV ) else: return hook.run(insert_statement, autocommit=True)