You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2022/10/31 14:18:36 UTC

[iotdb] branch rel/0.13 updated: [To rel/0.13] [IOTDB-3624] Fix bug when inserting data in SQL without timestamp (#7716)

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

hui pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new 004fdd11ac [To rel/0.13] [IOTDB-3624] Fix bug when inserting data in SQL without timestamp (#7716)
004fdd11ac is described below

commit 004fdd11ac936f600ec72b04f9b382450625a4a8
Author: ly <33...@users.noreply.github.com>
AuthorDate: Mon Oct 31 22:18:28 2022 +0800

    [To rel/0.13] [IOTDB-3624] Fix bug when inserting data in SQL without timestamp (#7716)
---
 .../db/integration/IoTDBInsertWithoutTimeIT.java    | 21 ++++++++++++++++++++-
 .../org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 13 ++++++++++---
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertWithoutTimeIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertWithoutTimeIT.java
index 3e43055e2d..1abb836fbd 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertWithoutTimeIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertWithoutTimeIT.java
@@ -87,7 +87,7 @@ public class IoTDBInsertWithoutTimeIT {
   }
 
   @Test
-  public void testInsertWithoutTime() throws SQLException, InterruptedException {
+  public void testInsertWithoutTime1() throws SQLException, InterruptedException {
     Statement st0 = connection.createStatement();
     st0.execute("insert into root.t1.wf01.wt01(time, status, temperature) values (1, true, 11)");
     st0.execute(
@@ -105,6 +105,25 @@ public class IoTDBInsertWithoutTimeIT {
     st1.close();
   }
 
+  @Test
+  public void testInsertWithoutTime2() throws SQLException {
+    Statement st0 = connection.createStatement();
+    st0.execute("SET STORAGE GROUP TO root.t2");
+    st0.execute("CREATE TIMESERIES root.t2.wf01.wt01.status WITH DATATYPE=INT64, ENCODING=PLAIN");
+    st0.execute(
+        "CREATE TIMESERIES root.t2.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE");
+    st0.execute("insert into root.t2.wf01.wt01(status, temperature) values (1, 11)");
+
+    ResultSet rs1 = st0.executeQuery("select status, temperature from root.t2.wf01.wt01");
+    rs1.next();
+
+    long status = rs1.getLong("root.t2.wf01.wt01.status");
+    Assert.assertEquals(status, 1L);
+
+    double temperature = rs1.getFloat("root.t2.wf01.wt01.temperature");
+    Assert.assertEquals(temperature, 11.0, 0.00001);
+  }
+
   @Test(expected = Exception.class)
   public void testInsertWithTimesColumns() throws SQLException {
     Statement st1 = connection.createStatement();
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 67ffe2efe3..bae92be936 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
@@ -1762,10 +1762,18 @@ public class IoTDBSqlVisitor extends IoTDBSqlParserBaseVisitor<Operator> {
     for (int i = 0; i < insertMultiValues.size(); i++) {
       // parse timestamp
       long timestamp;
+      List<String> valueList = new ArrayList<>();
+
       if (insertMultiValues.get(i).timeValue() != null) {
         if (isTimeDefault) {
-          throw new SQLParserException(
-              "the measurementList's size is not consistent with the valueList's size");
+          if (insertMultiValues.size() != 1) {
+            throw new SQLParserException("need timestamps when insert multi rows");
+          }
+          valueList.add(insertMultiValues.get(i).timeValue().getText());
+          timestamp = DateTimeUtils.currentTime();
+        } else {
+          timestamp =
+              parseTimeValue(insertMultiValues.get(i).timeValue(), DateTimeUtils.currentTime());
         }
         timestamp =
             parseTimeValue(insertMultiValues.get(i).timeValue(), DateTimeUtils.currentTime());
@@ -1782,7 +1790,6 @@ public class IoTDBSqlVisitor extends IoTDBSqlParserBaseVisitor<Operator> {
       timeArray[i] = timestamp;
 
       // parse values
-      List<String> valueList = new ArrayList<>();
       List<IoTDBSqlParser.MeasurementValueContext> values =
           insertMultiValues.get(i).measurementValue();
       for (IoTDBSqlParser.MeasurementValueContext value : values) {