You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pankajastro (via GitHub)" <gi...@apache.org> on 2023/12/09 15:43:08 UTC

Re: [PR] Make pyodbc.Row and databricks.Row JSON-serializable via new `make_serializable` method [airflow]

pankajastro commented on code in PR #32319:
URL: https://github.com/apache/airflow/pull/32319#discussion_r1421437350


##########
airflow/providers/databricks/hooks/databricks_sql.py:
##########
@@ -240,6 +240,13 @@ def run(
         else:
             return results
 
+    @staticmethod
+    def _make_serializable(result):
+        """Transform the databricks Row objects into a JSON-serializable list of rows."""
+        if result is not None:
+            return [list(row) for row in result]

Review Comment:
   Hey @Joffreybvn  I feel If the handler callable returns non-iterable then this would fail. 
   
   I call the run method like below and it's breaking my DAG
   ```
   run( f"SELECT COUNT(*) FROM {table}", handler=lambda x: x.fetchone())
   ```
   
   **Error**
   ```
   packages/airflow/providers/databricks/hooks/databricks_sql.py", line 247, in <listcomp>
       return [list(row) for row in result]
   TypeError: 'int' object is not iterable
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org