Skip to content

Commit

Permalink
add snowflake as sqlalchemy duct protocol (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
danfrankj authored Sep 9, 2018
1 parent 49f7073 commit 8b3e5c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions omniduct/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
'pyspark', # Primary client
],

'snowflake': [
'snowflake-sqlalchemy',
],

# Filesystems
'webhdfs': [
'pywebhdfs', # Primary client
Expand Down
7 changes: 4 additions & 3 deletions omniduct/databases/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class SQLAlchemyClient(DatabaseClient, SchemasMixin):

PROTOCOLS = ['sqlalchemy', 'firebird', 'mssql', 'mysql', 'oracle', 'postgresql', 'sybase']
PROTOCOLS = ['sqlalchemy', 'firebird', 'mssql', 'mysql', 'oracle', 'postgresql', 'sybase', 'snowflake']
NAMESPACE_NAMES = ['database', 'table']
NAMESPACE_QUOTECHAR = '"' # TODO: Apply overrides depending on protocol?
NAMESPACE_SEPARATOR = '.'

def _init(self, dialect=None, driver=None, database=''):
def _init(self, dialect=None, driver=None, database='', engine_opts=None):

assert self._port is not None, "Omniduct requires SQLAlchemy databases to manually specify a port, as " \
"it will often be the case that ports are being forwarded."
Expand All @@ -27,6 +27,7 @@ def _init(self, dialect=None, driver=None, database=''):
self.driver = driver
self.database = database
self.connection_fields += ('schema',)
self.engine_opts = engine_opts or {}

self.engine = None
self.connection = None
Expand All @@ -43,7 +44,7 @@ def db_uri(self):
def _connect(self):
import sqlalchemy

self.engine = sqlalchemy.create_engine(self.db_uri)
self.engine = sqlalchemy.create_engine(self.db_uri, **self.engine_opts)
self._sqlalchemy_metadata = sqlalchemy.MetaData(self.engine)

def _is_connected(self):
Expand Down
5 changes: 3 additions & 2 deletions omniduct/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ class Duct(with_metaclass(ProtocolRegisteringQuirkDocumentedABCMeta, object)):
class Type(Enum):
"""
The `Duct.Type` enum specifies all of the permissible values of
`Duct.DUCT_TYPE`.
`Duct.DUCT_TYPE`. Also determines the order in which ducts are loaded by DuctRegistry.
"""
REMOTE = 'remotes'
FILESYSTEM = 'filesystems'
DATABASE = 'databases'
CACHE = 'caches'
RESTFUL = 'rest_clients'
DATABASE = 'databases'
OTHER = 'other'

AUTO_LOGGING_SCOPE = True
Expand Down Expand Up @@ -405,6 +405,7 @@ def _prepare(self):
and '_password'.
- Ensures value of self.port is an integer (or None).
"""

# Import necessary classes lazily (to prevent dependency cycles)
from omniduct.registry import DuctRegistry
from omniduct.caches.base import Cache
Expand Down

0 comments on commit 8b3e5c6

Please sign in to comment.