Skip to content

Commit

Permalink
RM-95 use Table
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantimjohn committed Oct 2, 2023
1 parent de1a591 commit 0bd2b5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions records_mover/db/vertica/vertica_db_driver.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/db/vertica/test_vertica_db_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0bd2b5f

Please sign in to comment.