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