Cpaulyz commented on code in PR #10261:
URL: https://github.com/apache/iotdb/pull/10261#discussion_r1293275559
##########
iotdb-client/client-py/iotdb/dbapi/Cursor.py:
##########
@@ -125,10 +129,49 @@ def execute(self, operation, parameters=None):
time_names = [
name for name in seq.replace("FROM Time Name",
"").split()
]
+ elif seq.find("GROUP BY") >= 0:
+ time_group_sql = seq
+ time_group_flag = True
else:
sql_seqs.append(seq)
sql = "\n".join(sql_seqs)
+ if time_group_flag:
+ temp_sql = sql
+ min_sql_seqs = []
+ max_sql_seqs = []
+ temp_seqs = temp_sql.split("\n")
+ for seq in temp_seqs:
+ if seq.find("SELECT") >= 0:
+ min_seq = seq
+ max_seq = seq
+ aggregate_functions = ["count", "max_value",
"min_value", "sum", "avg"]
+ for func in aggregate_functions:
+ max_seq = re.sub(r"\b" + func + r"\b", "MAX_TIME",
max_seq)
+ min_seq = re.sub(r"\b" + func + r"\b", "MIN_TIME",
min_seq)
Review Comment:
This should be case insensitive.
```suggestion
aggregate_functions = ["count", "max_value",
"min_value", "sum", "avg"]
for func in aggregate_functions:
max_seq = re.sub(r"\b" + func + r"\b",
"MAX_TIME", max_seq, flags=re.IGNORECASE)
min_seq = re.sub(r"\b" + func + r"\b",
"MIN_TIME", min_seq, flags=re.IGNORECASE)
```
##########
iotdb-client/client-py/iotdb/dbapi/Cursor.py:
##########
@@ -125,10 +129,49 @@ def execute(self, operation, parameters=None):
time_names = [
name for name in seq.replace("FROM Time Name",
"").split()
]
+ elif seq.find("GROUP BY") >= 0:
+ time_group_sql = seq
+ time_group_flag = True
else:
sql_seqs.append(seq)
sql = "\n".join(sql_seqs)
+ if time_group_flag:
+ temp_sql = sql
+ min_sql_seqs = []
+ max_sql_seqs = []
+ temp_seqs = temp_sql.split("\n")
+ for seq in temp_seqs:
+ if seq.find("SELECT") >= 0:
+ min_seq = seq
+ max_seq = seq
+ aggregate_functions = ["count", "max_value",
"min_value", "sum", "avg"]
+ for func in aggregate_functions:
+ max_seq = re.sub(r"\b" + func + r"\b", "MAX_TIME",
max_seq)
+ min_seq = re.sub(r"\b" + func + r"\b", "MIN_TIME",
min_seq)
+ min_sql_seqs.append(min_seq)
+ max_sql_seqs.append(max_seq)
+ else:
+ min_sql_seqs.append(seq)
+ max_sql_seqs.append(seq)
+ min_sql = "\n".join(min_sql_seqs)
+ max_sql = "\n".join(max_sql_seqs)
+ min_data_set = self.__session.execute_statement(min_sql)
+ min_data = pd.DataFrame(min_data_set.todf())
+ min_value = min_data.iloc[0, 0]
+ max_data_set = self.__session.execute_statement(max_sql)
+ max_data = pd.DataFrame(max_data_set.todf())
+ max_value = max_data.iloc[0, 0]
+ time_group_sql = re.sub(r"startTime", str(min_value),
time_group_sql)
+ time_group_sql = re.sub(r"endTime", str(max_value),
time_group_sql)
Review Comment:
Other aggregations also need to find starttime and endtime, taking the
smallest starttime and endtime as the result for replacement.
For example,
```
SELECT AVG(_93741819) AS `AVG(_93741819)`,
AVG(_24646171) AS `AVG(_24646171)`,
AVG(_03380912) AS `AVG(_03380912)`
FROM root.view.speed.hebei
```
In the current implementation, we will only translate the first one (`if
seq.find("SELECT") >= 0`). That is, set starttime according to
MIN_TIME(_93741819)
However, we should translate it to
```
select MIN_TIME(_93741819), MIN_TIME(_24646171), MIN_TIME(_03380912) from
root.view.fuel.hebei
```
And then choose the smallest time as starttime.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]