Skip to content

Commit

Permalink
test(mysql): clean up version parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed May 22, 2023
1 parent 8db5624 commit 92399b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
5 changes: 4 additions & 1 deletion ibis/backends/base/sql/alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def do_connect(self, con: sa.engine.Engine) -> None:

@property
def version(self):
if self._inspector is None:
self._inspector = sa.inspect(self.con)
return '.'.join(map(str, self.con.dialect.server_version_info))

def list_tables(self, like=None, database=None):
Expand All @@ -143,7 +145,8 @@ def list_databases(self, like=None):
def inspector(self):
if self._inspector is None:
self._inspector = sa.inspect(self.con)
self._inspector.info_cache.clear()
else:
self._inspector.info_cache.clear()
return self._inspector

def _to_sql(self, expr: ir.Expr, **kwargs) -> str:
Expand Down
28 changes: 9 additions & 19 deletions ibis/backends/mysql/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,16 @@ def service_spec(cls, data_dir: Path) -> ServiceSpec:

def __init__(self, data_directory: Path) -> None:
super().__init__(data_directory)
# mariadb supports window operations after version 10.2
# but the sqlalchemy version string looks like:
# 5.5.5.10.2.12.MariaDB.10.2.12+maria~jessie
# or 10.4.12.MariaDB.1:10.4.12+maria~bionic
# example of possible results:
# https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_3/
# test/dialect/mysql/test_dialect.py#L244-L268
con = self.connection
if 'MariaDB' in str(con.version):
# we might move this parsing step to the mysql client
version_detail = con.con.dialect._parse_server_version(str(con.version))
version = (
version_detail[:3]
if version_detail[3] == 'MariaDB'
else version_detail[3:6]
)
self.__class__.supports_window_operations = version >= (10, 2)
elif parse_version(con.version) >= parse_version('8.0'):
# mysql supports window operations after version 8
self.__class__.supports_window_operations = True
with con.begin() as c:
version = c.exec_driver_sql("SELECT VERSION()").scalar()

# mariadb supports window operations after version 10.2
# mysql supports window operations after version 8
min_version = "10.2" if "MariaDB" in version else "8.0"
self.__class__.supports_window_operations = parse_version(
con.version
) >= parse_version(min_version)

@staticmethod
def _load_data(
Expand Down

0 comments on commit 92399b5

Please sign in to comment.