You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2021/07/05 02:17:32 UTC
[iotdb] branch 0.12nowbug created (now 7fd6eb4)
This is an automated email from the ASF dual-hosted git repository.
xiangweiwei pushed a change to branch 0.12nowbug
in repository https://gitbox.apache.org/repos/asf/iotdb.git.
at 7fd6eb4 Fix now() bug
This branch includes the following new commits:
new 7fd6eb4 Fix now() bug
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[iotdb] 01/01: Fix now() bug
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiangweiwei pushed a commit to branch 0.12nowbug
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 7fd6eb4437bc0bc8b2bf0288f9a28c0120a69a7f
Author: Alima777 <wx...@gmail.com>
AuthorDate: Sat Jul 3 17:12:11 2021 +0800
Fix now() bug
---
.../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 41 +++++++++++++++++++---
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
index ae7f473..5006628 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
@@ -1607,19 +1607,20 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
private void parseTimeInterval(TimeIntervalContext timeInterval, QueryOperator queryOp) {
long startTime;
long endTime;
+ long currentTime = DatetimeUtils.currentTime();
if (timeInterval.timeValue(0).INT() != null) {
startTime = Long.parseLong(timeInterval.timeValue(0).INT().getText());
} else if (timeInterval.timeValue(0).dateExpression() != null) {
- startTime = parseDateExpression(timeInterval.timeValue(0).dateExpression());
+ startTime = parseDateExpression(timeInterval.timeValue(0).dateExpression(), currentTime);
} else {
- startTime = parseTimeFormat(timeInterval.timeValue(0).dateFormat().getText());
+ startTime = parseTimeFormat(timeInterval.timeValue(0).dateFormat().getText(), currentTime);
}
if (timeInterval.timeValue(1).INT() != null) {
endTime = Long.parseLong(timeInterval.timeValue(1).INT().getText());
} else if (timeInterval.timeValue(1).dateExpression() != null) {
- endTime = parseDateExpression(timeInterval.timeValue(1).dateExpression());
+ endTime = parseDateExpression(timeInterval.timeValue(1).dateExpression(), currentTime);
} else {
- endTime = parseTimeFormat(timeInterval.timeValue(1).dateFormat().getText());
+ endTime = parseTimeFormat(timeInterval.timeValue(1).dateFormat().getText(), currentTime);
}
queryOp.setStartTime(startTime);
@@ -1851,6 +1852,19 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
return time;
}
+ private Long parseDateExpression(DateExpressionContext ctx, long currentTime) {
+ long time;
+ time = parseTimeFormat(ctx.getChild(0).getText(), currentTime);
+ for (int i = 1; i < ctx.getChildCount(); i = i + 2) {
+ if (ctx.getChild(i).getText().equals("+")) {
+ time += DatetimeUtils.convertDurationStrToLong(time, ctx.getChild(i + 1).getText());
+ } else {
+ time -= DatetimeUtils.convertDurationStrToLong(time, ctx.getChild(i + 1).getText());
+ }
+ }
+ return time;
+ }
+
/**
* parse time unit or sliding step in group by query. If 'mo' is used, then other units can not be
* used together, like '1mo1d'.
@@ -2107,4 +2121,23 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
timestampStr));
}
}
+
+ public long parseTimeFormat(String timestampStr, long currentTime) throws SQLParserException {
+ if (timestampStr == null || timestampStr.trim().equals("")) {
+ throw new SQLParserException("input timestamp cannot be empty");
+ }
+ if (timestampStr.equalsIgnoreCase(SQLConstant.NOW_FUNC)) {
+ return currentTime;
+ }
+ try {
+ return DatetimeUtils.convertDatetimeStrToLong(timestampStr, zoneId);
+ } catch (Exception e) {
+ throw new SQLParserException(
+ String.format(
+ "Input time format %s error. "
+ + "Input like yyyy-MM-dd HH:mm:ss, yyyy-MM-ddTHH:mm:ss or "
+ + "refer to user document for more info.",
+ timestampStr));
+ }
+ }
}