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

jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/TableModelGrammar by this 
push:
     new 31dc7ac16a0 Fix PartialPath deserialization
31dc7ac16a0 is described below

commit 31dc7ac16a0faf4955d77e784a25aa877efdfc18
Author: Jiang Tian <[email protected]>
AuthorDate: Fri Jul 26 17:43:07 2024 +0800

    Fix PartialPath deserialization
---
 .../db/queryengine/plan/parser/ASTVisitor.java     | 18 +++++++-
 .../iotdb/commons/partition/SchemaPartition.java   |  5 ++
 .../org/apache/iotdb/commons/path/AlignedPath.java |  4 +-
 .../apache/iotdb/commons/path/MeasurementPath.java |  4 +-
 .../org/apache/iotdb/commons/path/PartialPath.java | 26 ++---------
 .../apache/iotdb/commons/path/PartialPathTest.java | 53 ++++++++++++++++++++++
 pom.xml                                            |  2 +-
 7 files changed, 84 insertions(+), 28 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index 962a0ffeb78..60421946298 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -323,7 +323,7 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
   public Statement 
visitCreateAlignedTimeseries(IoTDBSqlParser.CreateAlignedTimeseriesContext ctx) 
{
     CreateAlignedTimeSeriesStatement createAlignedTimeSeriesStatement =
         new CreateAlignedTimeSeriesStatement();
-    
createAlignedTimeSeriesStatement.setDevicePath(parseFullPath(ctx.fullPath()));
+    
createAlignedTimeSeriesStatement.setDevicePath(parseAlignedDevice(ctx.fullPath()));
     parseAlignedMeasurements(ctx.alignedMeasurements(), 
createAlignedTimeSeriesStatement);
     return createAlignedTimeSeriesStatement;
   }
@@ -2015,6 +2015,22 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
     return new MeasurementPath(path);
   }
 
+  // IoTDB Objects 
========================================================================
+  private PartialPath parseAlignedDevice(IoTDBSqlParser.FullPathContext ctx) {
+    List<IoTDBSqlParser.NodeNameWithoutWildcardContext> nodeNamesWithoutStar =
+        ctx.nodeNameWithoutWildcard();
+    String[] path = new String[nodeNamesWithoutStar.size() + 1];
+    int i = 0;
+    if (ctx.ROOT() != null) {
+      path[0] = ctx.ROOT().getText();
+    }
+    for (IoTDBSqlParser.NodeNameWithoutWildcardContext nodeNameWithoutStar : 
nodeNamesWithoutStar) {
+      i++;
+      path[i] = parseNodeNameWithoutWildCard(nodeNameWithoutStar);
+    }
+    return new PartialPath(path);
+  }
+
   private PartialPath parseFullPathInExpression(
       IoTDBSqlParser.FullPathInExpressionContext ctx, boolean canUseFullPath) {
     List<IoTDBSqlParser.NodeNameContext> nodeNames = ctx.nodeName();
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
index c32b46d6fcd..fa783fcf214 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
@@ -114,4 +114,9 @@ public class SchemaPartition extends Partition {
         });
     return new ArrayList<>(distributionMap.values());
   }
+
+  @Override
+  public String toString() {
+    return "SchemaPartition{" + "schemaPartitionMap=" + schemaPartitionMap + 
'}';
+  }
 }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/AlignedPath.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/AlignedPath.java
index 2de9043dfa3..6bb91921769 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/AlignedPath.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/AlignedPath.java
@@ -373,8 +373,8 @@ public class AlignedPath extends PartialPath {
     alignedPath.measurementList = measurements;
     alignedPath.schemaList = measurementSchemas;
     alignedPath.nodes = partialPath.getNodes();
-    alignedPath.device = partialPath.getIDeviceID();
-    alignedPath.fullPath = partialPath.getFullPath();
+    alignedPath.device = alignedPath.getIDeviceID();
+    alignedPath.fullPath = alignedPath.getFullPath();
     return alignedPath;
   }
 
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/MeasurementPath.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/MeasurementPath.java
index 096266b7cba..7a39c955337 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/MeasurementPath.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/MeasurementPath.java
@@ -298,8 +298,8 @@ public class MeasurementPath extends PartialPath {
     measurementPath.isUnderAlignedEntity = 
ReadWriteIOUtils.readBoolObject(byteBuffer);
     measurementPath.measurementAlias = ReadWriteIOUtils.readString(byteBuffer);
     measurementPath.nodes = partialPath.getNodes();
-    measurementPath.device = partialPath.getIDeviceID();
-    measurementPath.fullPath = partialPath.getFullPath();
+    measurementPath.device = measurementPath.getIDeviceID();
+    measurementPath.fullPath = measurementPath.getFullPath();
     return measurementPath;
   }
 
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
index 119895d4bf2..454a40d3ee1 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
@@ -822,22 +822,10 @@ public class PartialPath extends Path implements 
Comparable<Path>, Cloneable {
     return device;
   }
 
+  @Deprecated
   /** This PartialPath represents for full device path */
   public IDeviceID getIDeviceIDAsFullDevice() {
-    if (device != null) {
-      return device;
-    } else {
-      if (nodes.length == 1) {
-        return Factory.DEFAULT_FACTORY.create("");
-      }
-      StringBuilder s = new StringBuilder(nodes[0]);
-      for (int i = 1; i < nodes.length; i++) {
-        s.append(TsFileConstant.PATH_SEPARATOR);
-        s.append(nodes[i]);
-      }
-      device = Factory.DEFAULT_FACTORY.create(s.toString());
-    }
-    return device;
+    return getIDeviceID();
   }
 
   // todo remove measurement related interface after invoker using 
MeasurementPath explicitly
@@ -949,16 +937,10 @@ public class PartialPath extends Path implements 
Comparable<Path>, Cloneable {
 
   public ByteBuffer serialize() throws IOException {
     PublicBAOS publicBAOS = new PublicBAOS();
-    serialize((OutputStream) publicBAOS);
+    serialize(publicBAOS);
     return ByteBuffer.wrap(publicBAOS.getBuf(), 0, publicBAOS.size());
   }
 
-  @Override
-  public void serialize(OutputStream stream) throws IOException {
-    PathType.Partial.serialize(stream);
-    serializeWithoutType(stream);
-  }
-
   @Override
   public void serialize(ByteBuffer byteBuffer) {
     PathType.Partial.serialize(byteBuffer);
@@ -966,7 +948,7 @@ public class PartialPath extends Path implements 
Comparable<Path>, Cloneable {
   }
 
   @Override
-  public void serialize(PublicBAOS stream) throws IOException {
+  public void serialize(OutputStream stream) throws IOException {
     PathType.Partial.serialize(stream);
     serializeWithoutType(stream);
   }
diff --git 
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
index cc995119aa0..e282481d4e4 100644
--- 
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
+++ 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
@@ -20,10 +20,15 @@ package org.apache.iotdb.commons.path;
 
 import org.apache.iotdb.commons.exception.IllegalPathException;
 
+import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.IDeviceID;
+import org.apache.tsfile.write.schema.MeasurementSchema;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -868,6 +873,54 @@ public class PartialPathTest {
     assertEquals("root.a.b", deviceID.getTableName());
   }
 
+  @Test
+  public void testSerialization() throws IllegalPathException, IOException {
+    PartialPath partialPath = new PartialPath("root.a.b.c.d.s1");
+    ByteBuffer buffer = partialPath.serialize();
+    PartialPath deserialized = (PartialPath) 
PathDeserializeUtil.deserialize(buffer);
+    assertEquals(partialPath, deserialized);
+
+    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+      partialPath.serialize(baos);
+      buffer = ByteBuffer.wrap(baos.toByteArray());
+      deserialized = (PartialPath) PathDeserializeUtil.deserialize(buffer);
+      assertEquals(partialPath, deserialized);
+    }
+
+    MeasurementPath measurementPath = new MeasurementPath("root.a.b.c.d.s1");
+    measurementPath.setMeasurementAlias("ss1");
+    measurementPath.setMeasurementSchema(new MeasurementSchema("s1", 
TSDataType.DOUBLE));
+    measurementPath.setTagMap(Collections.singletonMap("tag1", "tagValue1"));
+    buffer = measurementPath.serialize();
+    MeasurementPath deserializedMeasurementPath =
+        (MeasurementPath) PathDeserializeUtil.deserialize(buffer);
+    assertEquals(measurementPath, deserializedMeasurementPath);
+
+    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+      measurementPath.serialize(baos);
+      buffer = ByteBuffer.wrap(baos.toByteArray());
+      deserializedMeasurementPath = (MeasurementPath) 
PathDeserializeUtil.deserialize(buffer);
+      assertEquals(measurementPath, deserializedMeasurementPath);
+    }
+
+    AlignedPath alignedPath = new AlignedPath("root.a.b.c.d");
+    alignedPath.setMeasurementList(Arrays.asList("s1", "s2"));
+    alignedPath.setSchemaList(
+        Arrays.asList(
+            new MeasurementSchema("s1", TSDataType.DOUBLE),
+            new MeasurementSchema("s2", TSDataType.TEXT)));
+    buffer = alignedPath.serialize();
+    AlignedPath deserializedAlignedPath = (AlignedPath) 
PathDeserializeUtil.deserialize(buffer);
+    assertEquals(alignedPath, deserializedAlignedPath);
+
+    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+      alignedPath.serialize(baos);
+      buffer = ByteBuffer.wrap(baos.toByteArray());
+      deserializedAlignedPath = (AlignedPath) 
PathDeserializeUtil.deserialize(buffer);
+      assertEquals(alignedPath, deserializedAlignedPath);
+    }
+  }
+
   private void checkIntersect(PartialPath pattern, PartialPath prefix, 
Set<PartialPath> expected) {
     List<PartialPath> actual = pattern.intersectWithPrefixPattern(prefix);
     for (PartialPath path : actual) {
diff --git a/pom.xml b/pom.xml
index 17148a40e50..04b2fbea5b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -166,7 +166,7 @@
         <thrift.version>0.14.1</thrift.version>
         <xz.version>1.9</xz.version>
         <zstd-jni.version>1.5.6-3</zstd-jni.version>
-        <tsfile.version>1.0.1-tsfilev4-SNAPSHOT</tsfile.version>
+        <tsfile.version>1.0.1-tsfilev4-240726-SNAPSHOT</tsfile.version>
     </properties>
     <!--
     if we claim dependencies in dependencyManagement, then we do not claim

Reply via email to