from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults

class LoadFactOperator(BaseOperator):

    ui_color = '#F98866'

    @apply_defaults
    def __init__(self,
                 redshift = '',
                 table = '',
                 sql_statement = '',
                 append_only = False,
                 *args, **kwargs):

        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only

    def execute(self, context):
        self.log.info(f'LOADINGFACT... to {self.table}')
        redshift = PostgresHook(postgres_conn_id=self.redshift)
        
        if not self.append_only:
          self.log.info(f"DELETING... from {self.table}")
          redshift.run("DELETE FROM {}".format(self.table))
        
        self.log.info(f"INSERTING... to {self.table}")        
        formatted_sql = """
          INSERT INTO {}
          {};
        """.format(
          self.table,
          self.sql_statement
        )
        redshift.run(formatted_sql)


3111b3a924402201a783a289bf1b67cc6c68ae7b
<mask token>


class LoadFactOperator(BaseOperator):
    <mask token>

    @apply_defaults
    def __init__(self, redshift='', table='', sql_statement='', append_only
        =False, *args, **kwargs):
        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only
    <mask token>

<mask token>


class LoadFactOperator(BaseOperator):
    <mask token>

    @apply_defaults
    def __init__(self, redshift='', table='', sql_statement='', append_only
        =False, *args, **kwargs):
        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only

    def execute(self, context):
        self.log.info(f'LOADINGFACT... to {self.table}')
        redshift = PostgresHook(postgres_conn_id=self.redshift)
        if not self.append_only:
            self.log.info(f'DELETING... from {self.table}')
            redshift.run('DELETE FROM {}'.format(self.table))
        self.log.info(f'INSERTING... to {self.table}')
        formatted_sql = ("""
          INSERT INTO {}
          {};
        """
            .format(self.table, self.sql_statement))
        redshift.run(formatted_sql)

<mask token>


class LoadFactOperator(BaseOperator):
    ui_color = '#F98866'

    @apply_defaults
    def __init__(self, redshift='', table='', sql_statement='', append_only
        =False, *args, **kwargs):
        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only

    def execute(self, context):
        self.log.info(f'LOADINGFACT... to {self.table}')
        redshift = PostgresHook(postgres_conn_id=self.redshift)
        if not self.append_only:
            self.log.info(f'DELETING... from {self.table}')
            redshift.run('DELETE FROM {}'.format(self.table))
        self.log.info(f'INSERTING... to {self.table}')
        formatted_sql = ("""
          INSERT INTO {}
          {};
        """
            .format(self.table, self.sql_statement))
        redshift.run(formatted_sql)

from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults


class LoadFactOperator(BaseOperator):
    ui_color = '#F98866'

    @apply_defaults
    def __init__(self, redshift='', table='', sql_statement='', append_only
        =False, *args, **kwargs):
        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only

    def execute(self, context):
        self.log.info(f'LOADINGFACT... to {self.table}')
        redshift = PostgresHook(postgres_conn_id=self.redshift)
        if not self.append_only:
            self.log.info(f'DELETING... from {self.table}')
            redshift.run('DELETE FROM {}'.format(self.table))
        self.log.info(f'INSERTING... to {self.table}')
        formatted_sql = ("""
          INSERT INTO {}
          {};
        """
            .format(self.table, self.sql_statement))
        redshift.run(formatted_sql)

from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults

class LoadFactOperator(BaseOperator):

    ui_color = '#F98866'

    @apply_defaults
    def __init__(self,
                 redshift = '',
                 table = '',
                 sql_statement = '',
                 append_only = False,
                 *args, **kwargs):

        super(LoadFactOperator, self).__init__(*args, **kwargs)
        self.redshift = redshift
        self.table = table
        self.sql_statement = sql_statement
        self.append_only = append_only

    def execute(self, context):
        self.log.info(f'LOADINGFACT... to {self.table}')
        redshift = PostgresHook(postgres_conn_id=self.redshift)
        
        if not self.append_only:
          self.log.info(f"DELETING... from {self.table}")
          redshift.run("DELETE FROM {}".format(self.table))
        
        self.log.info(f"INSERTING... to {self.table}")        
        formatted_sql = """
          INSERT INTO {}
          {};
        """.format(
          self.table,
          self.sql_statement
        )
        redshift.run(formatted_sql)

