Handle pyodbc.Row returned by ODBCHook with SELECT statememt #32058
Unanswered
Joffreybvn
asked this question in
Ideas
Replies: 2 comments 6 replies
-
I vote for option 5. Make the results returned by ODBCHook Json Serialzable. We've done something simillar for Databricks (but there the operator was already implemented) https://github.com/apache/airflow/pull/31780/files - I believe the solution is to make a very similar change to convert whatever PyODBC returns from the hook (non-serializable) into serializables. |
Beta Was this translation helpful? Give feedback.
4 replies
-
For future reference, to make custom objects serializable either do the following:
The is no need for custom serialization schemes. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Using the ODBCHook with the SQLExecuteQueryOperator works fine for any SQL query that do not return data. However, it fails when doing a SELECT, because the ODBCHook (powered by PyODBC) returns a list of pyodbc.Row objects (instead of a list of tuple like psycopg2). More specifically, the XCom backend receive those Row objects and fails to serialize them.
Example:
Will throw:
Solution
I would like to improve the behavior of the SQLExecuteQueryOperator so that result of a SELECT statement made with the ODBCHook can be passed via XCom and used by downstream tasks. Yes, I'm whilling to submit a PR ✅.
But, given that a pyodbc.Row object can be converted into a sequence (list / tuple), or into a dictionnary (with column' names as key), they are several solutions possible:
And here I need the light of the community:
My prefered solution is the (2): Simple inheritance with minimal maintenance.
But, the _process_output method (solution 3), created to run just before a return / just before reaching the XCom backend, sounds also like a good place to fix this. Maybe the scope of the handler is not to prepare for serialization ?
What do you think ?
Beta Was this translation helpful? Give feedback.
All reactions