"""Task to create contract_mechanical_deduction snapshots in snowflake.""" from hooks.royalty_snowflake_hook import RoyaltySnowflakeHook from lib import config from tasks.accounting_run_calculate import helpers from templates.accounting_run_calculate.\ snapshot_contract_mechanical_deductions \ import insert_snapshot_contract_mechanical_deduction_template def snapshot_contract_mechanical_deductions_task(dag_run, *args, **kwargs): """Query royalty_accounting replica and insert into snowflake snapshot table. This task will copy data from the royalty_accounting Snowflake replica into the snapshot_contract_mechanical_deduction table for all contracts associated with the accounting run's run_controller. Args: dag_run (dict): config of the DAG this task belongs to kwargs (dict): any other optional arguments """ event = helpers.get_event_from_params(dag_run, **kwargs) _, accounting_run = helpers.get_event_records(event.target_id) hook = RoyaltySnowflakeHook(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) insert_statement = insert_snapshot_contract_mechanical_deduction_template().render( accounting_run_id=accounting_run['accounting_run_id'], run_controller_id=accounting_run['run_controller_id'], schema=config.OWS_ENV.upper() ) hook.run(insert_statement, autocommit=True)