From 0bd2b5f28f8dc73e3a09f28cd98e604bf38bf881 Mon Sep 17 00:00:00 2001 From: Tim Ryan Date: Mon, 2 Oct 2023 18:02:12 -0400 Subject: [PATCH] RM-95 use Table --- records_mover/db/vertica/vertica_db_driver.py | 8 +++----- tests/unit/db/vertica/test_vertica_db_driver.py | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/records_mover/db/vertica/vertica_db_driver.py b/records_mover/db/vertica/vertica_db_driver.py index bc61b2548..4529745d9 100644 --- a/records_mover/db/vertica/vertica_db_driver.py +++ b/records_mover/db/vertica/vertica_db_driver.py @@ -1,7 +1,7 @@ from ..driver import DBDriver import sqlalchemy from sqlalchemy.sql import text -from records_mover.db.quoting import quote_schema_and_table +from sqlalchemy import select from sqlalchemy.schema import Table, Column import logging from typing import Optional, Union, Tuple @@ -47,10 +47,8 @@ def unloader(self) -> Optional[Unloader]: def has_table(self, schema: str, table: str) -> bool: try: - sql = ("SELECT 1 " - f"from {quote_schema_and_table(None, schema, table, db_engine=self.db_engine)} " - "limit 0;") - self.db_conn.execute(text(sql)) + table_to_check = Table(table, self.meta, schema=schema) + self.db_conn.execute(select(text("1"), table_to_check)) return True except sqlalchemy.exc.ProgrammingError: return False diff --git a/tests/unit/db/vertica/test_vertica_db_driver.py b/tests/unit/db/vertica/test_vertica_db_driver.py index e9b0ba9c5..fda4efc62 100644 --- a/tests/unit/db/vertica/test_vertica_db_driver.py +++ b/tests/unit/db/vertica/test_vertica_db_driver.py @@ -54,14 +54,14 @@ def test_schema_sql_but_not_from_export_objects(self): self.assertTrue(sql is not None) def test_has_table_true(self): - mock_schema = Mock(name='schema') - mock_table = Mock(name='table') + mock_schema = 'myschema' + mock_table = 'mytable' self.assertEqual(True, self.vertica_db_driver.has_table(mock_schema, mock_table)) def test_has_table_false(self): - mock_schema = Mock(name='schema') - mock_table = Mock(name='table') + mock_schema = 'myschema' + mock_table = 'mytable' self.mock_db_engine.execute.side_effect = sqlalchemy.exc.ProgrammingError('statement', {}, 'orig') self.assertEqual(False,