"""Snowflake connector class for the Kugou's tasks.""" from snowflake_connector.etl_connector import SQLLoader from feed_ingestion.common.fact_analytics_sf.base_executor \ import SnowflakeSQLExecutorFA from feed_ingestion.flows.kugou import config sql_loader = SQLLoader(__file__) class Kugou(SnowflakeSQLExecutorFA): """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, and a key of executors dict in feed_ingestion/common/ fact_analytics_sf/__init__.py file. Returns: str: Feed name, e.g. 'deezer_daily_sf'. """ return '_'.join([config.feed_name, self.licensor]) @property def feedid(self): """Id of the feed. Returns: str: Feed id """ return config.feedid @property def storeid(self): """Storeid of feed data. Should match dim_store and feed config value. Returns: integer: Feed's storeid. """ return config.storeid @property def staging_raw_table(self): """Name of staging raw table. Returns: str: staging_raw table name """ return config.snowflake_table_names['staging_raw'] def load_staging_fact_table(self, date): """Load staging fact_analytics table from staging_raw table. Args: date (str): Date of the data being process (YYYY-MM-DD). """ self.execute_query( sql_loader, 'load_staging_fact', params=dict( db=self.sf_config['db'], schema=self.sf_config['schema'], staging_fact_table=self.staging_fact_table(date), staging_raw_table=self.staging_raw_table, feedid=self.feedid, storeid=self.storeid, reportdate=date, licensor=self.licensor)) def load_fact_error_data(self, date, **kwargs): """Load unmatched data into fact_analytics_error. Args: date (str): Date of the data being process (YYYY-MM-DD). """ self.execute_query( sql_loader, 'load_fact_analytics_error', params=dict( db=self.sf_config['db'], schema=self.sf_config['schema'], fact_error_table=self.fact_error_table, staging_fact_table=self.staging_fact_table(date), staging_raw_table=self.staging_raw_table, feedid=self.feedid, reportdate=date, **kwargs )) class KugouTheOrchardFA(Kugou): """Helper class to abstract Snowflake operations.""" @property def licensor(self): """Licensor.""" return 'theorchard' class KugouSMEFA(Kugou): """Helper class to abstract Snowflake operations.""" @property def licensor(self): """Licensor.""" return 'sme'