This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/groupByTimeParser
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/groupByTimeParser by this
push:
new dd232f5b0b6 Support for group by time sql paser
dd232f5b0b6 is described below
commit dd232f5b0b607f436ef8b53c249360d5a7de5aaf
Author: JackieTien97 <[email protected]>
AuthorDate: Fri Jun 14 17:30:33 2024 +0800
Support for group by time sql paser
---
.../java/org/apache/iotdb/db/utils/DateTimeUtils.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
index dc24893f32a..98e0a6f09aa 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
@@ -815,30 +815,33 @@ public class DateTimeUtils {
long temp = 0;
long monthDuration = 0;
long nonMonthDuration = 0;
- for (int i = 0; i < duration.length(); i++) {
+ int i = 0;
+ for (; i < duration.length(); i++) {
char ch = duration.charAt(i);
if (Character.isDigit(ch)) {
temp *= 10;
temp += (ch - '0');
} else {
- String unit = String.valueOf(duration.charAt(i));
- // This is to identify units with two letters.
- if (i + 1 < duration.length() && !Character.isDigit(duration.charAt(i
+ 1))) {
+ StringBuilder unit = new
StringBuilder(String.valueOf(duration.charAt(i)));
+ i++;
+ // This is to identify units.
+ while (i < duration.length() &&
!Character.isDigit(duration.charAt(i))) {
+ unit.append(duration.charAt(i));
i++;
- unit += duration.charAt(i);
}
- if ("y".equals(unit) || "year".equals(unit)) {
+ i--;
+ if ("y".contentEquals(unit) || "year".contentEquals(unit)) {
monthDuration += temp * 12;
temp = 0;
continue;
}
- if ("mo".equals(unit) || "month".equals(unit)) {
+ if ("mo".contentEquals(unit) || "month".contentEquals(unit)) {
monthDuration += temp;
temp = 0;
continue;
}
nonMonthDuration +=
- DateTimeUtils.convertDurationStrToLong(-1, temp, unit,
currTimePrecision);
+ DateTimeUtils.convertDurationStrToLong(-1, temp, unit.toString(),
currTimePrecision);
temp = 0;
}
}