You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ge...@apache.org on 2020/06/24 02:54:23 UTC

[incubator-iotdb] 01/01: measurement_with_quote

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

geniuspig pushed a commit to branch measurement_with_quote
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 847200ab58ffd65e4a97a0a9b842ea825daddd1c
Author: zhutianci <zh...@gmail.com>
AuthorDate: Wed Jun 24 10:53:55 2020 +0800

    measurement_with_quote
---
 .../src/main/java/org/apache/iotdb/db/metadata/MTree.java |  8 +-------
 .../main/java/org/apache/iotdb/db/metadata/MetaUtils.java | 15 +++++++++++----
 .../org/apache/iotdb/db/qp/strategy/LogicalGenerator.java |  3 ++-
 .../java/org/apache/iotdb/session/IoTDBSessionIT.java     |  2 +-
 .../iotdb/tsfile/common/constant/TsFileConstant.java      |  2 ++
 .../java/org/apache/iotdb/tsfile/read/common/Path.java    |  9 ++++-----
 .../org/apache/iotdb/tsfile/read/common/PathTest.java     |  8 ++++----
 7 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index b4eb3e0..1a48b60 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -720,13 +720,7 @@ public class MTree implements Serializable {
           return;
         }
       }
-      String nodeName;
-      if (node.getName().contains(TsFileConstant.PATH_SEPARATOR)) {
-        nodeName = "\"" + node + "\"";
-      } else {
-        nodeName = node.getName();
-      }
-      String nodePath = parent + nodeName;
+      String nodePath = parent + node;
       String[] tsRow = new String[8];
       tsRow[0] = nodePath;
       tsRow[1] = ((MeasurementMNode) node).getAlias();
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java b/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
index 0e1d953..06de18c 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.metadata;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.exception.metadata.IllegalPathException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
 
 import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_WILDCARD;
 
@@ -29,16 +30,22 @@ public class MetaUtils {
   public static final String PATH_SEPARATOR = "\\.";
 
   private MetaUtils() {
-
+    throw new IllegalStateException("Utility class");
   }
 
   public static String[] getNodeNames(String path) {
     String[] nodeNames;
     if (path.contains("\"") || path.contains("'")) {
       // e.g., root.sg.d1."s1.int"  ->  root.sg.d1, s1.int
-      String[] measurementDeviceNode = path.trim().replace("'", "\"").split("\"");
-      // s1.int
-      String measurement = measurementDeviceNode[1];
+      String measurement;
+      String[] measurementDeviceNode;
+      if (path.contains("\"")) {
+        measurementDeviceNode = path.split("\"");
+      } else {
+        measurementDeviceNode = path.split("\'");
+      }
+      // "s1.int"
+      measurement = TsFileConstant.DOUBLE_QUOTATION + measurementDeviceNode[1] + TsFileConstant.DOUBLE_QUOTATION;
       // root.sg.d1 -> root, sg, d1
       String[] deviceNodeName = measurementDeviceNode[0].split(PATH_SEPARATOR);
       int nodeNumber = deviceNodeName.length + 1;
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
index ebd41f0..70b7a2e 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
@@ -1062,8 +1062,9 @@ public class LogicalGenerator extends SqlBaseBaseListener {
     List<String> measurementList = new ArrayList<>();
     for (NodeNameWithoutStarContext nodeNameWithoutStar : nodeNamesWithoutStar) {
       String measurement = nodeNameWithoutStar.getText();
-      if (measurement.contains("\"") || measurement.contains("'")) {
+      if (measurement.contains("'")) {
         measurement = measurement.substring(1, measurement.length() - 1);
+        measurement = TsFileConstant.DOUBLE_QUOTATION + measurement + TsFileConstant.DOUBLE_QUOTATION;
       }
       measurementList.add(measurement);
     }
diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
index 7bc3a11..723eb86 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
@@ -883,7 +883,7 @@ public class IoTDBSessionIT {
       for (Field f : fields) {
         sb.append(f.getStringValue()).append(",");
       }
-      Assert.assertEquals("root.sg1.d1,11,0,11,", sb.toString());
+      Assert.assertEquals("root.sg1.d1,\"11\",0,\"11\",", sb.toString());
     }
     Assert.assertEquals(1000, count);
     sessionDataSet.closeOperationHandle();
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
index a0001c0..267fa29 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
@@ -27,6 +27,8 @@ public class TsFileConstant {
   public static final String PATH_UPGRADE = "tmp";
   public static final String PATH_SEPARATOR = ".";
   public static final String PATH_SEPARATER_NO_REGEX = "\\.";
+  public static final String DOUBLE_QUOTATION = "\"";
+  public static final String SINGLE_QUOTATION = "\'";
 
   private TsFileConstant() {
   }
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/Path.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/Path.java
index c7f74dd..74933f9 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/Path.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/Path.java
@@ -72,8 +72,7 @@ public class Path implements Serializable, Comparable<Path> {
     }
     this.device = device;
     this.measurement = measurement;
-    this.fullPath = device + TsFileConstant.PATH_SEPARATOR
-        + (measurement.contains(TsFileConstant.PATH_SEPARATOR) ? "\"" + measurement + "\"" : measurement);
+    this.fullPath = device + TsFileConstant.PATH_SEPARATOR + measurement;
   }
 
   /**
@@ -94,8 +93,8 @@ public class Path implements Serializable, Comparable<Path> {
     if ((i != 2 && i != 0) || (j != 2 && j != 0)) {
       throw new IllegalArgumentException("input pathSc single/double quotes error, not in pair or more than one pair!");
     }
-    if ((i == 2 && pathSc.length() - 1 != pathSc.lastIndexOf("\""))
-        || (j == 2 && pathSc.length() - 1 != pathSc.lastIndexOf("\'"))) {
+    if ((i == 2 && pathSc.length() - 1 != pathSc.lastIndexOf('\"'))
+        || (j == 2 && pathSc.length() - 1 != pathSc.lastIndexOf('\''))) {
       throw new IllegalArgumentException("input pathSc contains quoted string in the middle!");
     }
     String[] subStrs;
@@ -105,11 +104,11 @@ public class Path implements Serializable, Comparable<Path> {
       } else {
         subStrs = pathSc.split("\'");
       }
+      measurement = TsFileConstant.DOUBLE_QUOTATION + subStrs[1] + TsFileConstant.DOUBLE_QUOTATION;
       device = subStrs[0];
       if (!device.equals("")) {
         device = device.substring(0, subStrs[0].length() - 1);
       }
-      measurement = subStrs[1];
       fullPath = pathSc;
     } else {
       StringContainer sc = new StringContainer(pathSc.split(TsFileConstant.PATH_SEPARATER_NO_REGEX),
diff --git a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/common/PathTest.java b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/common/PathTest.java
index 6205582..626056d 100644
--- a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/common/PathTest.java
+++ b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/common/PathTest.java
@@ -41,7 +41,7 @@ public class PathTest {
     testPath(path, "", "", "");
     // with quote;
     path = new Path("root.d1.r1.\"x1.x2.x3\"");
-    testPath(path, "root.d1.r1", "x1.x2.x3", "root.d1.r1.\"x1.x2.x3\"");
+    testPath(path, "root.d1.r1", "\"x1.x2.x3\"", "root.d1.r1.\"x1.x2.x3\"");
   }
 
   @Test
@@ -64,7 +64,7 @@ public class PathTest {
     Path suffix2 = new Path("d.\"e.f\"");
     testPath(Path.mergePath(prefix, suffix), "a.b.c.d", "e", "a.b.c.d.e");
     testPath(Path.mergePath(prefix, suffix1), "a.b", "c", "a.b.c");
-    testPath(Path.mergePath(prefix, suffix2), "a.b.c.d", "e.f", "a.b.c.d.\"e.f\"");
+    testPath(Path.mergePath(prefix, suffix2), "a.b.c.d", "\"e.f\"", "a.b.c.d.\"e.f\"");
   }
 
   @Test
@@ -81,7 +81,7 @@ public class PathTest {
     Path desc = new Path("a.b.\"c\"");
     Path head = new Path("d.e");
     Path head1 = new Path("");
-    testPath(Path.addPrefixPath(desc, head), "d.e.a.b", "c", "d.e.a.b.\"c\"");
-    testPath(Path.mergePath(desc, head1), "a.b", "c", "a.b.\"c\"");
+    testPath(Path.addPrefixPath(desc, head), "d.e.a.b", "\"c\"", "d.e.a.b.\"c\"");
+    testPath(Path.mergePath(desc, head1), "a.b", "\"c\"", "a.b.\"c\"");
   }
 }
\ No newline at end of file