Commit 77a1fc6b authored by Lukáš Lalinský's avatar Lukáš Lalinský

More tests

parent 9fb1bd6d
......@@ -39,9 +39,10 @@ If you need a Phoenix server for experimenting, you can get one running quickly
cd ansible-hadoop
vagrant up
Things to do:
Known problems:
* More testing.
* Better Python type handling.
* "Transaction" support, i.e. non-autocommit mode. Needs support in the Avatica RPC server first (`CALCITE-767 <https://issues.apache.org/jira/browse/CALCITE-767>`_).
* More specific exceptions. Also needs proper support in the Avatica RPC server (`CALCITE-645 <https://issues.apache.org/jira/browse/CALCITE-767>`_).
* "Transaction" support, i.e. non-autocommit mode. Needs support in the Avatica RPC server first. (`CALCITE-767 <https://issues.apache.org/jira/browse/CALCITE-767>`_)
* Proper exception handling, currently it tries to parse the HTML error page it receives from the server. (`CALCITE-645 <https://issues.apache.org/jira/browse/CALCITE-767>`_)
* Can't pass long string as parameters. (`CALCITE-780 <https://issues.apache.org/jira/browse/CALCITE-780>`_)
* Can't use BINARY(n) columns properly. You can insert non-binary data to a BINARY column, but you can't insert arbitrary binary data and you will always receive base64-encoded string back. (`CALCITE-781 <https://issues.apache.org/jira/browse/CALCITE-781>`_)
* Can't use TIME/DATE columns. The server returns incomplete data and expects different format on input and output. (`discussion <http://mail-archives.apache.org/mod_mbox/phoenix-user/201506.mbox/%3CCAGUtLj8HDeq7chOSTz%3DVznB-v79%3DCmJ5%3Dt1N9Bbe4wE_m1%3D3zg%40mail.gmail.com%3E>`_)
......@@ -12,15 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import json
import pprint
import urllib3
import logging
import uuid
import weakref
import collections
from phoenixdb import errors
from phoenixdb.errors import OperationalError, NotSupportedError, ProgrammingError
__all__ = ['Cursor', 'ColumnDescription']
......
......@@ -98,5 +98,87 @@ class TypesTest(DatabaseTestCase):
def test_time(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val time")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, '12:00:00')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, '12')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, NULL)")
def test_varchar(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val varchar")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, 'abc')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, NULL)")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (3, ?)", ['abc'])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", [None])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (5, '')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (6, ?)", [''])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, 'abc'], [2, None], [3, 'abc'], [4, None], [5, None], [6, None]])
@unittest.skip("broken")
def test_varchar_very_long(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val varchar")
with self.conn.cursor() as cursor:
value = '1234567890' * 1000
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, ?)", [value])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, value]])
def test_varchar_limited(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val varchar(2)")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, 'ab')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, NULL)")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (3, ?)", ['ab'])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", [None])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (5, '')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (6, ?)", [''])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, 'ab'], [2, None], [3, 'ab'], [4, None], [5, None], [6, None]])
self.assertRaises(self.conn.DataError, cursor.execute, "UPSERT INTO phoenixdb_test_tbl1 VALUES (100, 'abc')")
@unittest.skip("broken")
def test_char_null(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val char(2)")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, NULL)")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", [None])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (5, '')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (6, ?)", [''])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, 'abc'], [2, None], [3, 'abc'], [4, None], [5, None], [6, None]])
self.assertRaises(self.conn.DataError, cursor.execute, "UPSERT INTO phoenixdb_test_tbl1 VALUES (100, 'abc')")
def test_char(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val char(2)")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, 'ab')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, ?)", ['ab'])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (3, 'a')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", ['b'])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, 'ab'], [2, 'ab'], [3, 'a'], [4, 'b']])
self.assertRaises(self.conn.DataError, cursor.execute, "UPSERT INTO phoenixdb_test_tbl1 VALUES (100, 'abc')")
def test_binary(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val binary(2)")
with self.conn.cursor() as cursor:
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, 'ab')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (2, ?)", ['ab'])
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (3, '\x01\x00')")
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", ['\x01\x00'])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [
[1, 'ab'.encode('base64').strip()],
[2, 'ab'.encode('base64').strip()],
[3, '\x01\x00'.encode('base64').strip()],
[4, '\x01\x00'.encode('base64').strip()],
])
@unittest.skip("broken")
def test_binary2(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val binary(2)")
with self.conn.cursor() as cursor:
value = ''
for i in range(256):
value += chr(i)
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (1, ?)", [phoenixdb.Binary(value)])
self.assertEqual(cursor.fetchall(), [[1, value.encode('base64').strip()]])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment