from apollo_utils.core.constants.dsp import DSP from src import config from src.constants import DataType from src.constants.queries.mysql.tracks_top_playlists import DESTINATION_TABLE_TRACKS_TOP_PLAYLISTS, \ DOWNLOAD_COLUMNS_TRACKS_TOP_PLAYLISTS, ID_COLUMN_TRACKS_TOP_PLAYLISTS from src.constants.queries.snowflake.tracks_top_playlists import AGGREGATE_TRACKS_TOP_PLAYLISTS from src.processors.base import BaseProcessor class TracksTopPlaylistsProcessor(BaseProcessor): _data_type = DataType.TRACKS_TOP_PLAYLISTS _save_temp_table = True _snowflake_query = AGGREGATE_TRACKS_TOP_PLAYLISTS _destination_table = DESTINATION_TABLE_TRACKS_TOP_PLAYLISTS _destination_columns = DOWNLOAD_COLUMNS_TRACKS_TOP_PLAYLISTS _id_column = ID_COLUMN_TRACKS_TOP_PLAYLISTS @property def snowflake_query(self) -> str: return self._snowflake_query[self._dsp].format( main_database=config.Snowflake.PUBLIC_DATA_MAIN_DATABASE, main_schema=config.Snowflake.PUBLIC_DATA_MAIN_PLAYLISTS_SCHEMA, top_database=( config.Snowflake.PUBLIC_DATA_MAIN_DATABASE if self._dsp == DSP.SPOTIFY.value else config.Snowflake.EXPLORATION_DATABASE ), top_schema=( config.Snowflake.PUBLIC_DATA_MAIN_PLAYLISTS_SCHEMA if self._dsp == DSP.SPOTIFY.value else config.Snowflake.EXPLORATION_MAIN_SCHEMA ), ) @property def destination_table(self) -> str: return self._destination_table[self._dsp] @property def destination_columns(self) -> str: return self._destination_columns[self._dsp] def parse_type_specific_data(self): self._dsp = self._payload["dsp"] if self._dsp not in (DSP.SPOTIFY.value, DSP.APPLE.value): raise ValueError(f"Invalid dsp {self._dsp}")