You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by er...@apache.org on 2022/08/09 06:06:55 UTC

[iotdb] branch master updated: [IOTDB-4065] support negative timestamp (before 1970 year.) (#6918)

This is an automated email from the ASF dual-hosted git repository.

ericpai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e514211827 [IOTDB-4065] support negative timestamp (before 1970 year.) (#6918)
e514211827 is described below

commit e51421182787a0ca982a291bf57a1c3497ace303
Author: Jamber <ja...@sina.com>
AuthorDate: Tue Aug 9 14:06:50 2022 +0800

    [IOTDB-4065] support negative timestamp (before 1970 year.) (#6918)
---
 .../main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4  |  2 +-
 .../java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java  |  3 +++
 .../main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java |  3 +++
 server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java  | 11 +++++++++++
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index ffa922239c..127e497d0e 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -838,7 +838,7 @@ realLiteral
 timeValue
     : datetimeLiteral
     | dateExpression
-    | INTEGER_LITERAL
+    | (PLUS | MINUS)? INTEGER_LITERAL
     ;
 
 // Expression & Predicate
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index c4dd40d837..e0c6bf0442 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -2210,6 +2210,9 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
 
   private long parseTimeValue(IoTDBSqlParser.TimeValueContext ctx, long currentTime) {
     if (ctx.INTEGER_LITERAL() != null) {
+      if (ctx.MINUS() != null) {
+        return -Long.parseLong(ctx.INTEGER_LITERAL().getText());
+      }
       return Long.parseLong(ctx.INTEGER_LITERAL().getText());
     } else if (ctx.dateExpression() != null) {
       return parseDateExpression(ctx.dateExpression(), currentTime);
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 7ac4e8d573..f348f44e9e 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
@@ -2791,6 +2791,9 @@ public class IoTDBSqlVisitor extends IoTDBSqlParserBaseVisitor<Operator> {
 
   private long parseTimeValue(IoTDBSqlParser.TimeValueContext ctx, long currentTime) {
     if (ctx.INTEGER_LITERAL() != null) {
+      if (ctx.MINUS() != null) {
+        return -Long.parseLong(ctx.INTEGER_LITERAL().getText());
+      }
       return Long.parseLong(ctx.INTEGER_LITERAL().getText());
     } else if (ctx.dateExpression() != null) {
       return parseDateExpression(ctx.dateExpression(), currentTime);
diff --git a/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java b/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
index c9cb46e7d3..9a621011f8 100644
--- a/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
@@ -246,6 +246,17 @@ public class PlannerTest {
     assertEquals(Double.NaN, Double.parseDouble("NaN"), 1e-15);
   }
 
+  @Test
+  public void insertStatementWithNegativeTimeStamp()
+      throws QueryProcessException, MetadataException {
+    String createTSStatement = "insert into root.vehicle.d0(time,s0) values(-1000, 111)";
+    PhysicalPlan physicalPlan = processor.parseSQLToPhysicalPlan(createTSStatement);
+
+    assertTrue(physicalPlan instanceof InsertRowPlan);
+    assertEquals(-1000, ((InsertRowPlan) physicalPlan).getTime());
+    assertEquals("111", ((InsertRowPlan) physicalPlan).getValues()[0]);
+  }
+
   @Test
   public void rawDataQueryReqToPhysicalPlanTest()
       throws QueryProcessException, IllegalPathException {