Skip to content

Commit

Permalink
Throw exception if version number <4.6 (#220)
Browse files Browse the repository at this point in the history
With #188, we need to prevent users using OmniSci <=4.5 from using pymapd >= 0.11. This is because of the backend change to switch encoding of dates from epoch seconds to epoch days. It was determined by myself and JP that it's better to throw the error on login, rather than allow user to have a script blow up unexpectedly once using columnar load.
  • Loading branch information
randyzwitch authored Apr 22, 2019
1 parent a3fd5b9 commit 268acf8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
11 changes: 11 additions & 0 deletions pymapd/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from ._pandas_loaders import build_row_desc, _serialize_arrow_payload
from . import _pandas_loaders

from packaging.version import Version


ConnectionInfo = namedtuple("ConnectionInfo", ['user', 'password', 'host',
'port', 'dbname', 'protocol'])
Expand Down Expand Up @@ -174,6 +176,15 @@ def __init__(self,
except TMapDException as e:
raise _translate_exception(e) from e

# if OmniSci version <4.6, raise RuntimeError, as data import can be
# incorrect for columnar date loads
# Caused by https://github.com/omnisci/pymapd/pull/188
semver = self._client.get_version()
if Version(semver.split("-")[0]) < Version("4.6"):
raise RuntimeError(f"Version {semver} of OmniSci detected. "
"Please use pymapd <0.11. See release notes "
"for more details.")

def __repr__(self):
# type: () -> str
tpl = ('Connection(mapd://{user}:***@{host}:{port}/{dbname}?protocol'
Expand Down
29 changes: 9 additions & 20 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pymapd._parsers import ColumnDetails, _extract_column_details


@pytest.mark.usefixtures("mapd_server")
class TestConnect:

def test_host_specified(self):
Expand All @@ -16,33 +17,21 @@ def test_raises_right_exception(self):
with pytest.raises(OperationalError):
connect(host='localhost', protocol='binary', port=1234)

def test_close(self, mock_client):
con = connect(user='user', password='password',
host='localhost', dbname='dbname')
assert con.closed == 0
con.close()
assert con.closed == 1

def test_connect(self, mock_client):
con = connect(user='user', password='password',
host='localhost', dbname='dbname')
assert mock_client.call_count == 1
assert con._client.connect.call_args == [
('user', 'password', 'dbname')
]
def test_close(self):
conn = connect(user='mapd', password='HyperInteractive',
host='localhost', dbname='mapd')
assert conn.closed == 0
conn.close()
assert conn.closed == 1

def test_context_manager(self, mock_client):
con = connect(user='user', password='password',
host='localhost', dbname='dbname')
def test_context_manager(self, con):
with con as cur:
pass

assert isinstance(cur, Cursor)
assert con.closed == 0

def test_commit_noop(self, mock_client):
con = connect(user='user', password='password',
host='localhost', dbname='dbname')
def test_commit_noop(self, con):
result = con.commit() # it worked
assert result is None

Expand Down
5 changes: 0 additions & 5 deletions tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ def test_empty_iterable(self):
result = list(c)
assert result == []

def test_context_manager(self, mock_connection):
c = mock_connection.cursor()
with c:
c.execute("select 1;")

def test_escape_basic(self):
query = "select * from foo where bar > :baz"
result = str(_bind_parameters(query, {"baz": 10}))
Expand Down

0 comments on commit 268acf8

Please sign in to comment.