This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new e56adc8e41 Add _serialize_cell method to TrinoHook and PrestoHook 
(#27724)
e56adc8e41 is described below

commit e56adc8e415059d17799638e0d56938edf74471d
Author: Alexander Malyga <[email protected]>
AuthorDate: Wed Nov 16 22:39:29 2022 +0100

    Add _serialize_cell method to TrinoHook and PrestoHook (#27724)
---
 airflow/providers/presto/hooks/presto.py    | 12 ++++++++++++
 airflow/providers/trino/hooks/trino.py      | 12 ++++++++++++
 tests/providers/presto/hooks/test_presto.py |  4 ++++
 tests/providers/trino/hooks/test_trino.py   |  4 ++++
 4 files changed, 32 insertions(+)

diff --git a/airflow/providers/presto/hooks/presto.py 
b/airflow/providers/presto/hooks/presto.py
index b5f8fab545..825b28ad60 100644
--- a/airflow/providers/presto/hooks/presto.py
+++ b/airflow/providers/presto/hooks/presto.py
@@ -224,3 +224,15 @@ class PrestoHook(DbApiHook):
             commit_every = 0
 
         super().insert_rows(table, rows, target_fields, commit_every)
+
+    @staticmethod
+    def _serialize_cell(cell: Any, conn: Connection | None = None) -> Any:
+        """
+        Presto will adapt all arguments to the execute() method internally,
+        hence we return cell without any conversion.
+
+        :param cell: The cell to insert into the table
+        :param conn: The database connection
+        :return: The cell
+        """
+        return cell
diff --git a/airflow/providers/trino/hooks/trino.py 
b/airflow/providers/trino/hooks/trino.py
index 56cf5d0795..63c75446ea 100644
--- a/airflow/providers/trino/hooks/trino.py
+++ b/airflow/providers/trino/hooks/trino.py
@@ -239,3 +239,15 @@ class TrinoHook(DbApiHook):
             commit_every = 0
 
         super().insert_rows(table, rows, target_fields, commit_every, replace)
+
+    @staticmethod
+    def _serialize_cell(cell: Any, conn: Connection | None = None) -> Any:
+        """
+        Trino will adapt all arguments to the execute() method internally,
+        hence we return cell without any conversion.
+
+        :param cell: The cell to insert into the table
+        :param conn: The database connection
+        :return: The cell
+        """
+        return cell
diff --git a/tests/providers/presto/hooks/test_presto.py 
b/tests/providers/presto/hooks/test_presto.py
index e1b1365f53..7831e441c9 100644
--- a/tests/providers/presto/hooks/test_presto.py
+++ b/tests/providers/presto/hooks/test_presto.py
@@ -278,3 +278,7 @@ class TestPrestoHook(unittest.TestCase):
         assert result_sets[1][0] == df.values.tolist()[1][0]
 
         self.cur.execute.assert_called_once_with(statement, None)
+
+    def test_serialize_cell(self):
+        assert "foo" == self.db_hook._serialize_cell("foo", None)
+        assert 1 == self.db_hook._serialize_cell(1, None)
diff --git a/tests/providers/trino/hooks/test_trino.py 
b/tests/providers/trino/hooks/test_trino.py
index 9f17ec69a3..85bfb0e194 100644
--- a/tests/providers/trino/hooks/test_trino.py
+++ b/tests/providers/trino/hooks/test_trino.py
@@ -311,6 +311,10 @@ class TestTrinoHook(unittest.TestCase):
         assert status is False
         assert msg == "Test"
 
+    def test_serialize_cell(self):
+        assert "foo" == self.db_hook._serialize_cell("foo", None)
+        assert 1 == self.db_hook._serialize_cell(1, None)
+
 
 class TestTrinoHookIntegration(unittest.TestCase):
     @pytest.mark.integration("trino")

Reply via email to