from abc import abstractmethod from typing import Any, Dict from ...base import BaseStep from ...mixins import SnowflakeMixin __all__ = ["PrepareBase"] class PrepareBase(SnowflakeMixin, BaseStep): query_params: Dict[str, Any] = {} @property @abstractmethod def table_name(self) -> str: pass @property @abstractmethod def query(self) -> str: pass @property def alt_table_name(self) -> str: # TODO: use self.timestamp instead of "alt" # but need to find a way to delete tables by wildcard like "DROP TABLE TABLE_NAME_*" return f"{self.table_name}_alt" def process(self) -> Dict[str, Any]: self.create_empty_table(self.table_name) self.drop_table(self.alt_table_name) self.create_table_from_query(self.alt_table_name, self.query, self.query_params) self.swap_tables(self.alt_table_name, self.table_name) self.drop_table(self.alt_table_name) return {"status": "ok"}