-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b73db5
commit 0870338
Showing
4 changed files
with
186 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,90 @@ | ||
# # | ||
# # Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending | ||
# # | ||
# import platform | ||
# import unittest | ||
# | ||
# Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending | ||
# | ||
import platform | ||
import unittest | ||
|
||
import turbodbc | ||
|
||
from deephaven import DHError, read_sql | ||
from deephaven.dbc import odbc as dhodbc, adbc as dhadbc | ||
from tests.testbase import BaseTestCase | ||
|
||
|
||
# noinspection SqlDialectInspection | ||
class DbcTestCase(BaseTestCase): | ||
|
||
def test_read_odbc(self): | ||
connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
with turbodbc.connect(connection_string=connection_string) as conn: | ||
with conn.cursor() as cursor: | ||
cursor.execute("SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES") | ||
table = dhodbc.read_cursor(cursor) | ||
self.assertEqual(table.size, cursor.rowcount) | ||
|
||
def test_read_adbc(self): | ||
import adbc_driver_postgresql.dbapi | ||
|
||
uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
with adbc_driver_postgresql.dbapi.connect(uri) as conn: | ||
with conn.cursor() as cursor: | ||
cursor.execute("SELECT t_ts, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10") | ||
table = dhadbc.read_cursor(cursor) | ||
# This is not ideal but ADBC might have a bug regarding cursor.rowcount it currently returns -1 | ||
# instead of the actual size | ||
self.assertEqual(table.size, 10) | ||
|
||
@unittest.skipIf(platform.machine() != "x86_64", reason="connectorx not available on Linux/Arm64" | ||
"https://github.com/sfu-db/connector-x/issues/386") | ||
def test_read_sql_connectorx(self): | ||
query = "SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10" | ||
postgres_url = "postgresql://test:test@postgres:5432/test" | ||
dh_table = read_sql(conn=postgres_url, query=query) | ||
self.assertEqual(len(dh_table.columns), 6) | ||
self.assertEqual(dh_table.size, 10) | ||
|
||
with self.assertRaises(DHError) as cm: | ||
dh_table = read_sql(conn="garbage", query=query) | ||
|
||
def test_read_sql(self): | ||
query = "SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10" | ||
|
||
with self.subTest("odbc"): | ||
connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
dh_table = read_sql(conn=connection_string, query=query, driver="odbc") | ||
self.assertEqual(len(dh_table.columns), 6) | ||
self.assertEqual(dh_table.size, 10) | ||
|
||
with self.subTest("adbc"): | ||
uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
dh_table = read_sql(conn=uri, query=query, driver="adbc") | ||
self.assertEqual(len(dh_table.columns), 6) | ||
self.assertEqual(dh_table.size, 10) | ||
|
||
with self.subTest("odbc-connection"): | ||
connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
with turbodbc.connect(connection_string=connection_string) as conn: | ||
dh_table = read_sql(conn=conn, query=query, driver="odbc") | ||
self.assertEqual(len(dh_table.columns), 6) | ||
self.assertEqual(dh_table.size, 10) | ||
|
||
with self.subTest("adbc-connection"): | ||
import adbc_driver_postgresql.dbapi | ||
uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
with adbc_driver_postgresql.dbapi.connect(uri) as conn: | ||
dh_table = read_sql(conn=conn, query=query, driver="adbc") | ||
self.assertEqual(len(dh_table.columns), 6) | ||
self.assertEqual(dh_table.size, 10) | ||
|
||
with self.assertRaises(DHError) as cm: | ||
dh_table = read_sql(conn=[None], query=query, driver="adbc") | ||
|
||
with self.assertRaises(DHError) as cm: | ||
dh_table = read_sql(conn="garbage", query=query, driver="adbc") | ||
|
||
with self.assertRaises(Exception) as cm: | ||
dh_table = read_sql(conn="garbage", query=query, driver="odbc") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
# import turbodbc | ||
# | ||
# from deephaven import DHError, read_sql | ||
# from deephaven.dbc import odbc as dhodbc, adbc as dhadbc | ||
# from tests.testbase import BaseTestCase | ||
# | ||
# | ||
# # noinspection SqlDialectInspection | ||
# class DbcTestCase(BaseTestCase): | ||
# | ||
# def test_read_odbc(self): | ||
# connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
# with turbodbc.connect(connection_string=connection_string) as conn: | ||
# with conn.cursor() as cursor: | ||
# cursor.execute("SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES") | ||
# table = dhodbc.read_cursor(cursor) | ||
# self.assertEqual(table.size, cursor.rowcount) | ||
# | ||
# def test_read_adbc(self): | ||
# import adbc_driver_postgresql.dbapi | ||
# | ||
# uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
# with adbc_driver_postgresql.dbapi.connect(uri) as conn: | ||
# with conn.cursor() as cursor: | ||
# cursor.execute("SELECT t_ts, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10") | ||
# table = dhadbc.read_cursor(cursor) | ||
# # This is not ideal but ADBC might have a bug regarding cursor.rowcount it currently returns -1 | ||
# # instead of the actual size | ||
# self.assertEqual(table.size, 10) | ||
# | ||
# @unittest.skipIf(platform.machine() != "x86_64", reason="connectorx not available on Linux/Arm64" | ||
# "https://github.com/sfu-db/connector-x/issues/386") | ||
# def test_read_sql_connectorx(self): | ||
# query = "SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10" | ||
# postgres_url = "postgresql://test:test@postgres:5432/test" | ||
# dh_table = read_sql(conn=postgres_url, query=query) | ||
# self.assertEqual(len(dh_table.columns), 6) | ||
# self.assertEqual(dh_table.size, 10) | ||
# | ||
# with self.assertRaises(DHError) as cm: | ||
# dh_table = read_sql(conn="garbage", query=query) | ||
# | ||
# def test_read_sql(self): | ||
# query = "SELECT t_ts, t_id, t_instrument, t_exchange, t_price, t_size FROM CRYPTO_TRADES LIMIT 10" | ||
# | ||
# with self.subTest("odbc"): | ||
# connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
# dh_table = read_sql(conn=connection_string, query=query, driver="odbc") | ||
# self.assertEqual(len(dh_table.columns), 6) | ||
# self.assertEqual(dh_table.size, 10) | ||
# | ||
# with self.subTest("adbc"): | ||
# uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
# dh_table = read_sql(conn=uri, query=query, driver="adbc") | ||
# self.assertEqual(len(dh_table.columns), 6) | ||
# self.assertEqual(dh_table.size, 10) | ||
# | ||
# with self.subTest("odbc-connection"): | ||
# connection_string = 'Driver={PostgreSQL};Server=postgres;Port=5432;Database=test;Uid=test;Pwd=test;' | ||
# with turbodbc.connect(connection_string=connection_string) as conn: | ||
# dh_table = read_sql(conn=conn, query=query, driver="odbc") | ||
# self.assertEqual(len(dh_table.columns), 6) | ||
# self.assertEqual(dh_table.size, 10) | ||
# | ||
# with self.subTest("adbc-connection"): | ||
# import adbc_driver_postgresql.dbapi | ||
# uri = "postgresql://postgres:5432/test?user=test&password=test" | ||
# with adbc_driver_postgresql.dbapi.connect(uri) as conn: | ||
# dh_table = read_sql(conn=conn, query=query, driver="adbc") | ||
# self.assertEqual(len(dh_table.columns), 6) | ||
# self.assertEqual(dh_table.size, 10) | ||
# | ||
# with self.assertRaises(DHError) as cm: | ||
# dh_table = read_sql(conn=[None], query=query, driver="adbc") | ||
# | ||
# with self.assertRaises(DHError) as cm: | ||
# dh_table = read_sql(conn="garbage", query=query, driver="adbc") | ||
# | ||
# with self.assertRaises(Exception) as cm: | ||
# dh_table = read_sql(conn="garbage", query=query, driver="odbc") | ||
# | ||
# | ||
# if __name__ == '__main__': | ||
# unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
# # | ||
# # Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
# # | ||
# | ||
# Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
# | ||
|
||
import jpy | ||
|
||
from deephaven import read_csv, empty_table | ||
from deephaven.execution_context import ExecutionContext | ||
from deephaven.experimental import sql | ||
from tests.testbase import BaseTestCase | ||
from test_helper import py_dh_session | ||
|
||
_JTableSpec = jpy.get_type("io.deephaven.qst.table.TableSpec") | ||
|
||
with ExecutionContext(j_exec_ctx=py_dh_session.getExecutionContext()): | ||
some_global_table = empty_table(42) | ||
|
||
|
||
class SqlTest(BaseTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
|
||
def test_eval_global(self): | ||
result_table = sql.evaluate("SELECT * FROM some_global_table") | ||
self.assertEqual(result_table.size, 42) | ||
|
||
def test_eval_local(self): | ||
# noinspection PyUnusedLocal | ||
test_table = read_csv("tests/data/test_table.csv") | ||
result_table = sql.evaluate("SELECT * FROM test_table LIMIT 5") | ||
self.assertEqual(result_table.size, 5) | ||
|
||
def test_dry_run_global(self): | ||
result_spec = sql.evaluate("SELECT * FROM some_global_table", dry_run=True) | ||
self.assertTrue(isinstance(result_spec, jpy.JType)) | ||
# Might be nice to extend jpy like this in the future? | ||
# self.assertTrue(isinstance(result_spec, _JTableSpec)) | ||
self.assertTrue(_JTableSpec.jclass.isInstance(result_spec)) | ||
|
||
def test_dry_run_local(self): | ||
# noinspection PyUnusedLocal | ||
test_table = read_csv("tests/data/test_table.csv") | ||
result_spec = sql.evaluate("SELECT * FROM test_table LIMIT 7", dry_run=True) | ||
self.assertTrue(isinstance(result_spec, jpy.JType)) | ||
# Might be nice to extend jpy like this in the future? | ||
# self.assertTrue(isinstance(result_spec, _JTableSpec)) | ||
self.assertTrue(_JTableSpec.jclass.isInstance(result_spec)) | ||
|
||
def test_local_takes_precedence(self): | ||
# noinspection PyUnusedLocal,PyShadowingNames | ||
some_global_table = empty_table(13) | ||
result_table = sql.evaluate("SELECT * FROM some_global_table") | ||
self.assertEqual(result_table.size, 13) | ||
|
||
def test_nested_non_local(self): | ||
# noinspection PyUnusedLocal | ||
test_table = read_csv("tests/data/test_table.csv") | ||
|
||
def do_sql(): | ||
nonlocal test_table | ||
return sql.evaluate("SELECT * FROM test_table LIMIT 3") | ||
|
||
result_table = do_sql() | ||
self.assertEqual(result_table.size, 3) | ||
|
||
def test_current_timestamp(self): | ||
result_table = sql.evaluate("SELECT CURRENT_TIMESTAMP") | ||
self.assertEqual(result_table.size, 1) | ||
|
||
def test_inner_func_local(self): | ||
def inner_func(my_table): | ||
return sql.evaluate("SELECT * FROM my_table LIMIT 13") | ||
|
||
result_table = inner_func(some_global_table) | ||
self.assertEqual(result_table.size, 13) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
# import jpy | ||
# | ||
# from deephaven import read_csv, empty_table | ||
# from deephaven.execution_context import ExecutionContext | ||
# from deephaven.experimental import sql | ||
# from tests.testbase import BaseTestCase | ||
# from test_helper import py_dh_session | ||
# | ||
# _JTableSpec = jpy.get_type("io.deephaven.qst.table.TableSpec") | ||
# | ||
# with ExecutionContext(j_exec_ctx=py_dh_session.getExecutionContext()): | ||
# some_global_table = empty_table(42) | ||
# | ||
# | ||
# class SqlTest(BaseTestCase): | ||
# def setUp(self): | ||
# super().setUp() | ||
# | ||
# def tearDown(self): | ||
# super().tearDown() | ||
# | ||
# def test_eval_global(self): | ||
# result_table = sql.evaluate("SELECT * FROM some_global_table") | ||
# self.assertEqual(result_table.size, 42) | ||
# | ||
# def test_eval_local(self): | ||
# # noinspection PyUnusedLocal | ||
# test_table = read_csv("tests/data/test_table.csv") | ||
# result_table = sql.evaluate("SELECT * FROM test_table LIMIT 5") | ||
# self.assertEqual(result_table.size, 5) | ||
# | ||
# def test_dry_run_global(self): | ||
# result_spec = sql.evaluate("SELECT * FROM some_global_table", dry_run=True) | ||
# self.assertTrue(isinstance(result_spec, jpy.JType)) | ||
# # Might be nice to extend jpy like this in the future? | ||
# # self.assertTrue(isinstance(result_spec, _JTableSpec)) | ||
# self.assertTrue(_JTableSpec.jclass.isInstance(result_spec)) | ||
# | ||
# def test_dry_run_local(self): | ||
# # noinspection PyUnusedLocal | ||
# test_table = read_csv("tests/data/test_table.csv") | ||
# result_spec = sql.evaluate("SELECT * FROM test_table LIMIT 7", dry_run=True) | ||
# self.assertTrue(isinstance(result_spec, jpy.JType)) | ||
# # Might be nice to extend jpy like this in the future? | ||
# # self.assertTrue(isinstance(result_spec, _JTableSpec)) | ||
# self.assertTrue(_JTableSpec.jclass.isInstance(result_spec)) | ||
# | ||
# def test_local_takes_precedence(self): | ||
# # noinspection PyUnusedLocal,PyShadowingNames | ||
# some_global_table = empty_table(13) | ||
# result_table = sql.evaluate("SELECT * FROM some_global_table") | ||
# self.assertEqual(result_table.size, 13) | ||
# | ||
# def test_nested_non_local(self): | ||
# # noinspection PyUnusedLocal | ||
# test_table = read_csv("tests/data/test_table.csv") | ||
# | ||
# def do_sql(): | ||
# nonlocal test_table | ||
# return sql.evaluate("SELECT * FROM test_table LIMIT 3") | ||
# | ||
# result_table = do_sql() | ||
# self.assertEqual(result_table.size, 3) | ||
# | ||
# def test_current_timestamp(self): | ||
# result_table = sql.evaluate("SELECT CURRENT_TIMESTAMP") | ||
# self.assertEqual(result_table.size, 1) | ||
# | ||
# def test_inner_func_local(self): | ||
# def inner_func(my_table): | ||
# return sql.evaluate("SELECT * FROM my_table LIMIT 13") | ||
# | ||
# result_table = inner_func(some_global_table) | ||
# self.assertEqual(result_table.size, 13) | ||
# | ||
# | ||
# if __name__ == "__main__": | ||
# unittest.main() |