Skip to content

Add RedshiftDialect_redshift_connector#232

Merged
jklukas merged 7 commits into
sqlalchemy-redshift:mainfrom
Brooke-white:redshift-connector-dialect
Sep 20, 2021
Merged

Add RedshiftDialect_redshift_connector#232
jklukas merged 7 commits into
sqlalchemy-redshift:mainfrom
Brooke-white:redshift-connector-dialect

Conversation

@Brooke-white

Copy link
Copy Markdown
Contributor

Adds a dialect to support use of redshift_connector database driver.

Modifies sqlalchemy-redshift init requirement for psycopg2 to dialect dbapi method to avoid raising an ImportError for users using RedshiftDialect_redshift_connector

Modifies pytest to accept a command line option, dbdriver, to provide 1 or more database drivers to run the test suite against (e.g. —dbdriver psycopg2 —dbdriver redshift_connector). By default tests will run for psycopg2 and psycopg2cffi

Modifies tox configuration to test with —dbdriver redshift_connector for compatible Python versions (i.e. py36 >=), and to use a version of requests.

Reworks test_dialects.py to use a mock sqlalchemy engine.

Todos

  • MIT compatible
  • Tests
  • Documentation
  • Updated CHANGES.rst

@Brooke-white Brooke-white marked this pull request as draft September 10, 2021 23:19
@Brooke-white

Copy link
Copy Markdown
Contributor Author

These changes to the tests seem to be slowing down things quite a bit, I'll take another look on Monday.

):
pass
@classmethod
def dbapi(cls):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be defined in Psycopg2RedshiftDialectMixin or does it have to be a classmethod on each concrete dialect? I assume this is some hook in the SQLAlchemy machinery, but I'm struggling to find documentation about a dbapi classmethod. Can you point to background on this approach?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move this to Psycopg2RedshiftDialectMixin if we did something like this, using the value of driver defined by the dialect (e.g. defined here for the psycopg2cfifi dialect).

class Psycopg2RedshiftDialectMixin(RedshiftDialectMixin): 
   @classmethod
    def dbapi(cls):
        try:
            return __import__(self.driver)
        except ImportError:
            raise ImportError(
                'No module named {}.'.format(self.driver)
            )

For the dbapi classmethod, looking to the DefaultDialect class (from which PGDialect inherits from) it is used in DefaultDialect.connect(), as well as for defining the dbapi paramstyle that will be used.

I was unable to find any docs for the dpapi classmethod either, as I stumbled upon it when looking for where the driver's connect method is called.

@Brooke-white Brooke-white marked this pull request as ready for review September 15, 2021 16:49

@jklukas jklukas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I've kicked off integration tests. Do you have any more info on duration of tests with this change?

Comment thread sqlalchemy_redshift/dialect.py Outdated
@classmethod
def dbapi(cls):
try:
return __import__(cls.driver)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in edfb456

@Brooke-white

Copy link
Copy Markdown
Contributor Author

Do you have any more info on duration of tests with this change?

It seems like the tests which make a connection to a Redshift cluster take about twice as long. The unit tests are pretty quick. I think this has something to do with the dynamic parameterization of the fixtures, as the slow down came once I introduced that logic.

@jklukas jklukas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Kicked off integration tests again and will merge when done.

@jklukas jklukas merged commit d43b544 into sqlalchemy-redshift:main Sep 20, 2021
@Brooke-white

Copy link
Copy Markdown
Contributor Author

thanks for the quick turn around, @jklukas! When do you plan on making the next release? We'd like to get this feature out to customers as soon as we can.

@jklukas

jklukas commented Sep 22, 2021

Copy link
Copy Markdown
Member

I just pushed 0.8.6 which includes this new connector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants