"""Snowflake connector class for Dynamo sync tasks.""" from snowflake_connector.etl_connector import SnowflakeSQLExecutor from snowflake_connector.etl_connector import SQLLoader sql_loader = SQLLoader(__file__) class SnowflakeSyncExecutor(SnowflakeSQLExecutor): """Helper class for sync data queries.""" def unload_to_s3( self, model_type, s3_path, sync_from_date, full_refresh, aws): """Unload required data to S3. This method uses `COPY INTO` SQL statement for uploading data to S3. The query for selecting of data is based on passed model type. Args: model_type (str): One of the acceptable model types. sync_from_date (str): We're looking for any changes after this date. full_refresh (bool): The flag whether the run is incremental or the full refresh. s3_path (str): S3 path for data uploading. aws (dict): AWS credentials. """ data_query_template = sql_loader.load_query(model_type) data_query_params = { 'db': self.sf_config['db'], 'schema': self.sf_config['schema']} data_sql, _ = ( self.validator.format_identifiers( data_query_template, data_query_params)) unload_template = sql_loader.load_query('unload_to_s3') params = { 's3_path': s3_path, 'aws_key_id': aws['access_key'], 'aws_secret_key': aws['access_secret'], 'full_refresh': full_refresh, 'sync_from_date': sync_from_date} unload_data_sql = unload_template.format(select_query=data_sql) self.execute(unload_data_sql, params=params)