airflow-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamara Mendt ...@hellofresh.com>
Subject MySQL operator that returns rows
Date Mon, 01 Aug 2016 13:32:37 GMT
Hello,

I would like to use an operator which executes an SQL command and passes
the result of this command to the next downstream operator. However, I
noticed that the MySqlOperator only executes the command, without fetching
the results.

The solution I came up with was to create a new operator class that looks
like this:

class ReturnRowsMySqlOperator(MySqlOperator):

    def execute(self, context):

        logging.info('Executing: ' + str(self.sql))
        hook = MySqlHook(mysql_conn_id=self.mysql_conn_id)
        return_value = hook.get_records(self.sql,
                                        parameters=self.parameters)
        return return_value


It is a child class to the MySqlOperator, but overwrites the execute
function to fetch the results of the execution and return them, so they are
accessible by the following task. Is there any better way to achieve this?


Thanks and cheers,

Tamara

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message