Skip to content

Commit ae5bc1b

Browse files
committed
format code
1 parent dfe9b27 commit ae5bc1b

2 files changed

Lines changed: 14 additions & 35 deletions

File tree

iotdb-client/client-py/iotdb/dbapi/Cursor.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,13 @@ def execute(self, operation, parameters=None):
110110
else:
111111
sql = operation % parameters
112112

113-
time_index = []
114-
time_names = []
115-
if self.__sqlalchemy_mode:
116-
sql_seqs = []
117-
seqs = sql.split("\n")
118-
for seq in seqs:
119-
if seq.find("FROM Time Index") >= 0:
120-
time_index = [
121-
int(index)
122-
for index in seq.replace("FROM Time Index", "").split()
123-
]
124-
elif seq.find("FROM Time Name") >= 0:
125-
time_names = [
126-
name for name in seq.replace("FROM Time Name", "").split()
127-
]
128-
else:
129-
sql_seqs.append(seq)
130-
sql = "\n".join(sql_seqs)
131-
132113
data_set = self.__session.execute_statement(sql)
133114
col_names = None
134115
col_types = None
135116
rows = []
136117

137118
if data_set:
138119
data = data_set.todf()
139-
140-
if self.__sqlalchemy_mode and time_index:
141-
time_column = data.columns[0]
142-
time_column_value = data.Time
143-
del data[time_column]
144-
for i in range(len(time_index)):
145-
data.insert(time_index[i], time_names[i], time_column_value)
146-
147120
col_names = data.columns.tolist()
148121
col_types = data_set.get_column_types()
149122
rows = data.values.tolist()

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"INT32": types.Integer,
3838
"INT64": types.BigInteger,
3939
"FLOAT": types.Float,
40-
"DOUBLE": types.Float,
40+
"DOUBLE": types.Float(precision=53),
4141
"STRING": types.String,
4242
"TEXT": types.Text,
4343
"BLOB": types.LargeBinary,
@@ -86,7 +86,9 @@ def dbapi(cls):
8686
def create_connect_args(self, url):
8787
opts = url.translate_connect_args()
8888
opts.update(url.query)
89+
opts["sqlalchemy_mode"] = True
8990
opts["sql_dialect"] = "table"
91+
self._url_database = opts.get("database")
9092
return ([], opts)
9193

9294
def initialize(self, connection):
@@ -96,7 +98,7 @@ def _get_server_version_info(self, connection):
9698
return None
9799

98100
def _get_default_schema_name(self, connection):
99-
return None
101+
return getattr(self, "_url_database", None)
100102

101103
def has_schema(self, connection, schema_name, **kw):
102104
return schema_name in self.get_schema_names(connection)
@@ -110,16 +112,20 @@ def get_schema_names(self, connection, **kw):
110112

111113
def get_table_names(self, connection, schema=None, **kw):
112114
if schema:
113-
connection.execute(text("USE %s" % schema))
114-
cursor = connection.execute(text("SHOW TABLES"))
115+
quoted = self.identifier_preparer.quote_identifier(schema)
116+
cursor = connection.execute(text("SHOW TABLES FROM %s" % quoted))
117+
else:
118+
cursor = connection.execute(text("SHOW TABLES"))
115119
return [row[0] for row in cursor.fetchall()]
116120

117121
def get_columns(self, connection, table_name, schema=None, **kw):
122+
quoted_table = self.identifier_preparer.quote_identifier(table_name)
118123
if schema:
119-
connection.execute(text("USE %s" % schema))
120-
cursor = connection.execute(
121-
text("SHOW COLUMNS FROM %s" % table_name)
122-
)
124+
quoted_schema = self.identifier_preparer.quote_identifier(schema)
125+
qualified = "%s.%s" % (quoted_schema, quoted_table)
126+
else:
127+
qualified = quoted_table
128+
cursor = connection.execute(text("DESC %s" % qualified))
123129
columns = []
124130
for row in cursor.fetchall():
125131
col_name = row[0]

0 commit comments

Comments
 (0)