"""Snowflake connector class for the amazon_unlimited_marketshare tasks.""" from snowflake_connector.etl_connector import SQLLoader from feed_ingestion.common.marketshare_sf.base_executor import \ SnowflakeSQLExecutorMS from feed_ingestion.flows.amazon_unlimited_marketshare import config sql_loader = SQLLoader(__file__) class AmazonUnlimitedMarketshareSF(SnowflakeSQLExecutorMS): """Helper class to abstract Snowflake operations. This class inherits from SnowflakeSQLExecutor class, which provides basic set of methods. This class extends SnowflakeSQLExecutor with some specific methods, which are useful to encapsulate some flow specific operations. """ @property def feed_name(self): """Name of the feed. Should match dir name of this feed, feed_name in config.py of a feed Returns: str: Feed name """ return config.feed_name @property def staging_raw_table(self): """Name of the staging_raw table for the feed. Returns: str: staging_raw_{feed} table name. """ return config.snowflake_table_names['staging_raw'] @property def storeid(self): """Storeid of feed data. Should match dim_store and feed config value. Returns: integer: Feed's storeid. """ return 716 def create_temp_staging_raw_table(self, temp_staging_raw_table): """Create a temporary staging raw table. Args: temp_staging_raw_table (str): A table name in Snowflake. """ params = dict( db=self.sf_config['db'], schema=self.sf_config['schema'], temp_staging_raw_table=temp_staging_raw_table) self.execute_query(sql_loader, 'create_temp_staging_raw', params) def load_marketshare_data(self, date): """Load data into fact_market_share. Args: date (str): Date of the data being process (YYYY-MM-DD). """ params = dict( db=self.sf_config['db'], schema=self.sf_config['schema'], main_market_share_table=self.main_marketshare_table, staging_raw_table=self.staging_raw_table, storeid=self.storeid, date=date) self.execute_query(sql_loader, 'load_main_market_share', params=params)