Skip to content

Commit e48aa4f

Browse files
authored
Remove sqlalchemy upper version constraint for python client (apache#14083)
1 parent f1714d0 commit e48aa4f

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

iotdb-client/client-py/iotdb/sqlalchemy/IoTDBDialect.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818

1919
from sqlalchemy import types, util
2020
from sqlalchemy.engine import default
21+
from sqlalchemy.sql import text
2122
from sqlalchemy.sql.sqltypes import String
2223

2324
from iotdb import dbapi
2425

26+
from .IoTDBIdentifierPreparer import IoTDBIdentifierPreparer
2527
from .IoTDBSQLCompiler import IoTDBSQLCompiler
2628
from .IoTDBTypeCompiler import IoTDBTypeCompiler
27-
from .IoTDBIdentifierPreparer import IoTDBIdentifierPreparer
2829

2930
TYPES_MAP = {
3031
"BOOLEAN": types.Boolean,
@@ -68,6 +69,10 @@ def create_connect_args(self, url):
6869
opts.update({"sqlalchemy_mode": True})
6970
return [[], opts]
7071

72+
@classmethod
73+
def import_dbapi(cls):
74+
return dbapi
75+
7176
@classmethod
7277
def dbapi(cls):
7378
return dbapi
@@ -79,17 +84,19 @@ def has_table(self, connection, table_name, schema=None, **kw):
7984
return table_name in self.get_table_names(connection, schema=schema)
8085

8186
def get_schema_names(self, connection, **kw):
82-
cursor = connection.execute("SHOW DATABASES")
87+
cursor = connection.execute(text("SHOW DATABASES"))
8388
return [row[0] for row in cursor.fetchall()]
8489

8590
def get_table_names(self, connection, schema=None, **kw):
8691
cursor = connection.execute(
87-
"SHOW DEVICES %s.**" % (schema or self.default_schema_name)
92+
text("SHOW DEVICES %s.**" % (schema or self.default_schema_name))
8893
)
8994
return [row[0].replace(schema + ".", "", 1) for row in cursor.fetchall()]
9095

9196
def get_columns(self, connection, table_name, schema=None, **kw):
92-
cursor = connection.execute("SHOW TIMESERIES %s.%s.*" % (schema, table_name))
97+
cursor = connection.execute(
98+
text("SHOW TIMESERIES %s.%s.*" % (schema, table_name))
99+
)
93100
columns = [self._general_time_column_info()]
94101
for row in cursor.fetchall():
95102
columns.append(self._create_column_info(row, schema, table_name))

iotdb-client/client-py/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ pandas>=1.0.0
2121
numpy>=1.0.0
2222
thrift>=0.14.1
2323
# SQLAlchemy Dialect
24-
sqlalchemy<1.5,>=1.4
24+
sqlalchemy>=1.4
2525
sqlalchemy-utils>=0.37.8

iotdb-client/client-py/tests/integration/sqlalchemy/test_dialect.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
from sqlalchemy import create_engine, inspect
2222
from sqlalchemy.dialects import registry
23-
23+
from sqlalchemy.orm import Session
24+
from sqlalchemy.sql import text
2425
from tests.integration.iotdb_container import IoTDBContainer
2526

2627
final_flag = True
@@ -52,17 +53,26 @@ def test_dialect():
5253
)
5354
registry.register("iotdb", "iotdb.sqlalchemy.IoTDBDialect", "IoTDBDialect")
5455
eng = create_engine(url)
55-
eng.execute("create database root.cursor")
56-
eng.execute("create database root.cursor_s1")
57-
eng.execute(
58-
"create timeseries root.cursor.device1.temperature with datatype=FLOAT,encoding=RLE"
59-
)
60-
eng.execute(
61-
"create timeseries root.cursor.device1.status with datatype=FLOAT,encoding=RLE"
62-
)
63-
eng.execute(
64-
"create timeseries root.cursor.device2.temperature with datatype=FLOAT,encoding=RLE"
65-
)
56+
57+
with Session(eng) as session:
58+
session.execute(text("create database root.cursor"))
59+
session.execute(text("create database root.cursor_s1"))
60+
session.execute(
61+
text(
62+
"create timeseries root.cursor.device1.temperature with datatype=FLOAT,encoding=RLE"
63+
)
64+
)
65+
session.execute(
66+
text(
67+
"create timeseries root.cursor.device1.status with datatype=FLOAT,encoding=RLE"
68+
)
69+
)
70+
session.execute(
71+
text(
72+
"create timeseries root.cursor.device2.temperature with datatype=FLOAT,encoding=RLE"
73+
)
74+
)
75+
6676
insp = inspect(eng)
6777
# test get_schema_names
6878
schema_names = insp.get_schema_names()
@@ -79,8 +89,11 @@ def test_dialect():
7989
if len(columns) != 3:
8090
test_fail()
8191
print_message("test get_columns failed!")
82-
eng.execute("delete database root.cursor")
83-
eng.execute("delete database root.cursor_s1")
92+
93+
with Session(eng) as session:
94+
session.execute(text("delete database root.cursor"))
95+
session.execute(text("delete database root.cursor_s1"))
96+
8497
# close engine
8598
eng.dispose()
8699

0 commit comments

Comments
 (0)