Skip to content

Commit

Permalink
BUG: Connect fails with uri, and restoring connect function (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
datapythonista authored Oct 7, 2021
1 parent d41e07e commit 0508e47
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
38 changes: 36 additions & 2 deletions ibis_omniscidb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""OmniSciDB backend."""
from __future__ import annotations

import warnings
from typing import Optional, Union

import ibis.common.exceptions as com
Expand Down Expand Up @@ -108,14 +109,16 @@ def connect(

if session_id:
kwargs = {'sessionid': session_id}
elif uri is not None:
kwargs = {}
elif (
user is not None and password is not None and database is not None
):
kwargs = {'user': user, 'password': password, 'dbname': database}
else:
raise ValueError(
'If `session_id` is not provided, then `user`, '
'`password` and `database` must be provided.'
'If `session_id` is not provided, then the connection `uri` '
'or all `user`, `password` and `database` must be provided.'
)

new_backend.con = pyomnisci.connect(
Expand Down Expand Up @@ -771,3 +774,34 @@ def version(self):
Version of the backend library.
"""
return pyomnisci.__version__


def connect(
uri: Optional[str] = None,
user: Optional[str] = None,
password: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = 6274,
database: Optional[str] = None,
protocol: str = 'binary',
session_id: Optional[str] = None,
ipc: Optional[bool] = None,
gpu_device: Optional[int] = None,
):
warnings.warn(
'`ibis_omniscidb.connect(...)` is deprecated and will be removed in '
'a future version. Use `ibis.omniscidb.connect(...)` instead.',
FutureWarning,
)
return Backend().connect(
uri,
user,
password,
host,
port,
database,
protocol,
session_id,
ipc,
gpu_device,
)
4 changes: 4 additions & 0 deletions ibis_omniscidb/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
OMNISCIDB_PROTOCOL = os.environ.get('IBIS_TEST_OMNISCIDB_PROTOCOL', 'binary')
OMNISCIDB_DB = os.environ.get('IBIS_TEST_DATA_DB', 'ibis_testing')

URI_USER = f'{OMNISCIDB_USER}:{OMNISCIDB_PASS}'
URI_HOST = f'{OMNISCIDB_HOST}:{OMNISCIDB_PORT}'
URI = f'omniscidb://{URI_USER}@{URI_HOST}/{OMNISCIDB_DB}'


class TestConf(BackendTest, RoundAwayFromZero):
"""Backend-specific class with information for testing."""
Expand Down
13 changes: 13 additions & 0 deletions ibis_omniscidb/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
from ibis.tests.util import assert_equal
from pytest import param

import ibis_omniscidb

from . import conftest


def test_connect_with_uri(con):
con.connect(uri=conftest.URI)


def test_legacy_connect_warns():
with pytest.warns(FutureWarning):
ibis_omniscidb.connect(conftest.URI)


def test_table(alltypes):
assert isinstance(alltypes, ir.TableExpr)
Expand Down

0 comments on commit 0508e47

Please sign in to comment.