This is an automated email from the ASF dual-hosted git repository.
haonan 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 18a514c384 [IOTDB-3456] Optimize PathPattarnTree for improving write
performance (#6294)
18a514c384 is described below
commit 18a514c38471c53286637a654b035e6bc1ebd403
Author: liuminghui233 <[email protected]>
AuthorDate: Thu Jun 16 16:52:12 2022 +0800
[IOTDB-3456] Optimize PathPattarnTree for improving write performance
(#6294)
---
.../iotdb/confignode/manager/ConfigManager.java | 4 +-
.../thrift/ConfigNodeRPCServiceProcessor.java | 2 +-
.../thrift/ConfigNodeRPCServiceProcessorTest.java | 2 +-
.../iotdb/db/localconfignode/LocalConfigNode.java | 4 +-
.../db/mpp/common/schematree/PathPatternTree.java | 276 +++++++++------------
.../operator/schema/SchemaFetchScanOperator.java | 2 +-
.../apache/iotdb/db/mpp/plan/analyze/Analyzer.java | 94 +++----
.../mpp/plan/analyze/ClusterPartitionFetcher.java | 4 +-
.../db/mpp/plan/analyze/ClusterSchemaFetcher.java | 14 +-
.../db/mpp/plan/analyze/ExpressionAnalyzer.java | 6 +-
.../mpp/plan/analyze/StandaloneSchemaFetcher.java | 20 +-
.../db/mpp/plan/planner/LogicalPlanBuilder.java | 11 +-
.../statement/internal/SchemaFetchStatement.java | 2 +-
.../mpp/common/schematree/PathPatternTreeTest.java | 10 +-
.../schema/SchemaFetchScanOperatorTest.java | 4 +-
.../metadata/read/SchemaFetchScanNodeTest.java | 9 +-
16 files changed, 230 insertions(+), 234 deletions(-)
diff --git
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index cdf760114e..e234d8e30e 100644
---
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -297,7 +297,7 @@ public class ConfigManager implements Manager {
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
GetSchemaPartitionReq getSchemaPartitionReq = new
GetSchemaPartitionReq();
Map<String, Set<TSeriesPartitionSlot>> partitionSlotsMap = new
HashMap<>();
- List<PartialPath> relatedPaths = patternTree.splitToPathList();
+ List<PartialPath> relatedPaths = patternTree.getAllPathPatterns();
List<String> allStorageGroups =
getClusterSchemaManager().getStorageGroupNames();
Map<String, Boolean> scanAllRegions = new HashMap<>();
for (PartialPath path : relatedPaths) {
@@ -359,7 +359,7 @@ public class ConfigManager implements Manager {
public DataSet getOrCreateSchemaPartition(PathPatternTree patternTree) {
TSStatus status = confirmLeader();
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
- List<String> devicePaths = patternTree.findAllDevicePaths();
+ List<String> devicePaths = patternTree.getAllDevicePatterns();
List<String> storageGroups =
getClusterSchemaManager().getStorageGroupNames();
GetOrCreateSchemaPartitionReq getOrCreateSchemaPartitionReq =
diff --git
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
index 4d0cf0e5c0..ccf897bac7 100644
---
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
+++
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
@@ -291,7 +291,7 @@ public class ConfigNodeRPCServiceProcessor implements
ConfigIService.Iface {
throws TException {
PathPatternTree patternTree =
PathPatternTree.deserialize(ByteBuffer.wrap(req.getPathPatternTree()));
- PartialPath partialPath = patternTree.splitToPathList().get(0);
+ PartialPath partialPath = patternTree.getAllPathPatterns().get(0);
SchemaNodeManagementResp schemaNodeManagementResp;
schemaNodeManagementResp =
(SchemaNodeManagementResp)
configManager.getNodePathsPartition(partialPath, req.getLevel());
diff --git
a/confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessorTest.java
b/confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessorTest.java
index 106b9f964b..0109d1e8f2 100644
---
a/confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessorTest.java
+++
b/confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessorTest.java
@@ -343,7 +343,7 @@ public class ConfigNodeRPCServiceProcessorTest {
throws IllegalPathException, IOException {
PathPatternTree patternTree = new PathPatternTree();
for (String path : paths) {
- patternTree.appendPath(new PartialPath(path));
+ patternTree.appendPathPattern(new PartialPath(path));
}
patternTree.constructTree();
diff --git
a/server/src/main/java/org/apache/iotdb/db/localconfignode/LocalConfigNode.java
b/server/src/main/java/org/apache/iotdb/db/localconfignode/LocalConfigNode.java
index 9dad431bd1..66dada1109 100644
---
a/server/src/main/java/org/apache/iotdb/db/localconfignode/LocalConfigNode.java
+++
b/server/src/main/java/org/apache/iotdb/db/localconfignode/LocalConfigNode.java
@@ -893,7 +893,7 @@ public class LocalConfigNode {
Map<String, Map<TSeriesPartitionSlot, TRegionReplicaSet>>
partitionSlotsMap = new HashMap<>();
patternTree.constructTree();
- List<PartialPath> partialPathList = patternTree.splitToPathList();
+ List<PartialPath> partialPathList = patternTree.getAllPathPatterns();
try {
for (PartialPath path : partialPathList) {
List<PartialPath> storageGroups = getBelongedStorageGroups(path);
@@ -920,7 +920,7 @@ public class LocalConfigNode {
public Map<String, Map<TSeriesPartitionSlot, TRegionReplicaSet>>
getOrCreateSchemaPartition(
PathPatternTree patternTree) {
- List<String> devicePaths = patternTree.findAllDevicePaths();
+ List<String> devicePaths = patternTree.getAllDevicePatterns();
Map<String, Map<TSeriesPartitionSlot, TRegionReplicaSet>>
partitionSlotsMap = new HashMap<>();
try {
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
index 840eb3ccb6..ef0e7a4e97 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
@@ -20,7 +20,6 @@
package org.apache.iotdb.db.mpp.common.schematree;
import org.apache.iotdb.commons.conf.IoTDBConstant;
-import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.qp.constant.SQLConstant;
@@ -33,61 +32,20 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.stream.Collectors;
public class PathPatternTree {
private PathPatternNode root;
- private List<PartialPath> pathList;
-
- public PathPatternTree(PathPatternNode root) {
- this.root = root;
- this.pathList = new ArrayList<>();
- }
-
- public PathPatternTree(PartialPath devicePath, String[] measurements) {
- this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
- appendPaths(devicePath, Arrays.asList(measurements));
- }
-
- public PathPatternTree(PartialPath devicePath, List<String> measurements) {
- this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
- appendPaths(devicePath, measurements);
- }
-
- public PathPatternTree(Map<PartialPath, List<String>>
deviceToMeasurementsMap) {
- this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
- for (Map.Entry<PartialPath, List<String>> entry :
deviceToMeasurementsMap.entrySet()) {
- appendPaths(entry.getKey(), entry.getValue());
- }
- }
-
- public PathPatternTree(List<PartialPath> pathList) {
- this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
- for (PartialPath path : pathList) {
- appendPath(path);
- }
- }
-
- public PathPatternTree(PartialPath fullPath) {
- this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
- appendPath(fullPath);
- }
+ private List<PartialPath> pathPatternList;
public PathPatternTree() {
this.root = new PathPatternNode(SQLConstant.ROOT);
- this.pathList = new ArrayList<>();
+ this.pathPatternList = new ArrayList<>();
}
public PathPatternNode getRoot() {
@@ -98,83 +56,52 @@ public class PathPatternTree {
this.root = root;
}
- /** @return all device path patterns in the path pattern tree. */
- public List<String> findAllDevicePaths() {
- List<String> nodes = new ArrayList<>();
- List<String> pathPatternList = new ArrayList<>();
- findAllDevicePaths(root, nodes, pathPatternList);
- return pathPatternList;
- }
+
/////////////////////////////////////////////////////////////////////////////////////////////////
+ // Operations for constructing tree
+
/////////////////////////////////////////////////////////////////////////////////////////////////
- private void findAllDevicePaths(
- PathPatternNode curNode, List<String> nodes, List<String>
pathPatternList) {
- nodes.add(curNode.getName());
- if (curNode.isLeaf()) {
- if (!curNode.getName().equals(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD)) {
- pathPatternList.add(
- nodes.size() == 1 ? "" : parseNodesToString(nodes.subList(0,
nodes.size() - 1)));
- } else {
- pathPatternList.add(parseNodesToString(nodes));
- }
- nodes.remove(nodes.size() - 1);
- return;
- }
- if (curNode.isWildcard()) {
- pathPatternList.add(parseNodesToString(nodes));
- nodes.remove(nodes.size() - 1);
- return;
- }
- for (PathPatternNode childNode : curNode.getChildren().values()) {
- findAllDevicePaths(childNode, nodes, pathPatternList);
- }
- nodes.remove(nodes.size() - 1);
+ /** Append a fullPath (without wildcards) as a branch on the tree. */
+ public void appendFullPath(PartialPath fullPath) {
+ appendBranchWithoutPrune(root, fullPath.getNodes(), 0);
}
- private String parseNodesToString(List<String> nodes) {
- StringBuilder fullPathBuilder = new StringBuilder(nodes.get(0));
- for (int i = 1; i < nodes.size(); i++) {
-
fullPathBuilder.append(TsFileConstant.PATH_SEPARATOR).append(nodes.get(i));
- }
- return fullPathBuilder.toString();
+ /** Append a fullPath consisting of device and measurement as a branch on
the tree. */
+ public void appendFullPath(PartialPath devicePath, String measurement) {
+ int deviceNodeLength = devicePath.getNodeLength();
+ String[] pathNodes = new String[deviceNodeLength + 1];
+ System.arraycopy(devicePath.getNodes(), 0, pathNodes, 0, deviceNodeLength);
+ pathNodes[deviceNodeLength] = measurement;
+
+ appendBranchWithoutPrune(root, pathNodes, 0);
}
- // append path to pathList
- public void appendPath(PartialPath newPath) {
+ /** Add a pathPattern (may contain wildcards) to pathPatternList. */
+ public void appendPathPattern(PartialPath pathPattern) {
boolean isExist = false;
- for (PartialPath path : pathList) {
- if (path.matchFullPath(newPath)) {
- // path already exists in pathList
+ for (PartialPath path : pathPatternList) {
+ if (path.matchFullPath(pathPattern)) {
+ // path already exists in pathPatternList
isExist = true;
break;
}
}
if (!isExist) {
- // remove duplicate path in pathList
- pathList.removeAll(
-
pathList.stream().filter(newPath::matchFullPath).collect(Collectors.toList()));
- pathList.add(newPath);
- }
- }
-
- public void appendPaths(PartialPath device, List<String>
measurementNameList) {
- try {
- for (String measurementName : measurementNameList) {
- appendPath(new PartialPath(device.getFullPath(), measurementName));
- }
- } catch (IllegalPathException e) {
- e.printStackTrace();
+ // remove duplicate path in pathPatternList
+ pathPatternList.removeAll(
+
pathPatternList.stream().filter(pathPattern::matchFullPath).collect(Collectors.toList()));
+ pathPatternList.add(pathPattern);
}
}
- // construct tree according to pathList
+ /** Construct tree according to the pathPatternList. */
public void constructTree() {
- for (PartialPath path : pathList) {
- searchAndConstruct(root, path.getNodes(), 0);
+ for (PartialPath path : pathPatternList) {
+ appendBranchWithoutPrune(root, path.getNodes(), 0);
}
- pathList.clear();
+ pathPatternList.clear();
}
- private void searchAndConstruct(PathPatternNode curNode, String[] pathNodes,
int pos) {
+ private void appendBranchWithoutPrune(PathPatternNode curNode, String[]
pathNodes, int pos) {
if (pos == pathNodes.length - 1) {
return;
}
@@ -182,13 +109,13 @@ public class PathPatternTree {
PathPatternNode nextNode = curNode.getChildren(pathNodes[pos + 1]);
if (nextNode != null) {
- searchAndConstruct(nextNode, pathNodes, pos + 1);
+ appendBranchWithoutPrune(nextNode, pathNodes, pos + 1);
} else {
- appendTree(curNode, pathNodes, pos + 1);
+ constructBranch(curNode, pathNodes, pos + 1);
}
}
- private void appendTree(PathPatternNode curNode, String[] pathNodes, int
pos) {
+ private void constructBranch(PathPatternNode curNode, String[] pathNodes,
int pos) {
for (int i = pos; i < pathNodes.length; i++) {
PathPatternNode newNode = new PathPatternNode(pathNodes[i]);
curNode.addChild(newNode);
@@ -196,59 +123,90 @@ public class PathPatternTree {
}
}
- public void serialize(PublicBAOS outputStream) throws IOException {
- constructTree();
- root.serialize(outputStream);
- }
+
/////////////////////////////////////////////////////////////////////////////////////////////////
+ // Operations for querying tree
+
/////////////////////////////////////////////////////////////////////////////////////////////////
- public void serialize(DataOutputStream stream) throws IOException {
- constructTree();
- root.serialize(stream);
- }
-
- public void serialize(ByteBuffer buffer) {
- constructTree();
- root.serialize(buffer);
+ public boolean isEmpty() {
+ return (root.getChildren() == null || root.getChildren().isEmpty())
+ && (pathPatternList == null || pathPatternList.isEmpty());
}
- public static PathPatternTree deserialize(ByteBuffer buffer) {
- PathPatternNode root = deserializeNode(buffer);
- return new PathPatternTree(root);
+ public List<String> getAllDevicePatterns() {
+ List<String> nodes = new ArrayList<>();
+ List<String> results = new ArrayList<>();
+ searchDevicePattern(root, nodes, results);
+ return results;
}
- private static PathPatternNode deserializeNode(ByteBuffer buffer) {
- PathPatternNode node = new
PathPatternNode(ReadWriteIOUtils.readString(buffer));
- int childrenSize = ReadWriteIOUtils.readInt(buffer);
- while (childrenSize > 0) {
- PathPatternNode tmpNode = deserializeNode(buffer);
- node.addChild(tmpNode);
- childrenSize--;
+ private void searchDevicePattern(
+ PathPatternNode curNode, List<String> nodes, List<String> results) {
+ nodes.add(curNode.getName());
+ if (curNode.isLeaf()) {
+ if (!curNode.getName().equals(IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD)) {
+ results.add(
+ nodes.size() == 1 ? "" : convertNodesToString(nodes.subList(0,
nodes.size() - 1)));
+ } else {
+ results.add(convertNodesToString(nodes));
+ }
+ nodes.remove(nodes.size() - 1);
+ return;
}
- return node;
+ if (curNode.isWildcard()) {
+ results.add(convertNodesToString(nodes));
+ nodes.remove(nodes.size() - 1);
+ return;
+ }
+ for (PathPatternNode childNode : curNode.getChildren().values()) {
+ searchDevicePattern(childNode, nodes, results);
+ }
+ nodes.remove(nodes.size() - 1);
}
- public List<PartialPath> splitToPathList() {
+ public List<PartialPath> getAllPathPatterns() {
List<PartialPath> result = new ArrayList<>();
Deque<String> ancestors = new ArrayDeque<>();
- searchFullPath(root, ancestors, result);
+ searchPathPattern(root, ancestors, result);
return result;
}
- private void searchFullPath(
+ private void searchPathPattern(
PathPatternNode node, Deque<String> ancestors, List<PartialPath>
fullPaths) {
if (node.isLeaf()) {
- fullPaths.add(constructFullPath(node, ancestors));
+ fullPaths.add(convertNodesToPartialPath(node, ancestors));
return;
}
ancestors.push(node.getName());
for (PathPatternNode child : node.getChildren().values()) {
- searchFullPath(child, ancestors, fullPaths);
+ searchPathPattern(child, ancestors, fullPaths);
}
ancestors.pop();
}
- private PartialPath constructFullPath(PathPatternNode node, Deque<String>
ancestors) {
+ public List<PartialPath> getOverlappedPathPatterns(PartialPath pattern) {
+ if (pathPatternList.isEmpty()) {
+ pathPatternList = getAllPathPatterns();
+ }
+
+ List<PartialPath> results = new ArrayList<>();
+ for (PartialPath path : pathPatternList) {
+ if (pattern.overlapWith(path)) {
+ results.add(path);
+ }
+ }
+ return results;
+ }
+
+ private String convertNodesToString(List<String> nodes) {
+ StringBuilder fullPathBuilder = new StringBuilder(nodes.get(0));
+ for (int i = 1; i < nodes.size(); i++) {
+
fullPathBuilder.append(TsFileConstant.PATH_SEPARATOR).append(nodes.get(i));
+ }
+ return fullPathBuilder.toString();
+ }
+
+ private PartialPath convertNodesToPartialPath(PathPatternNode node,
Deque<String> ancestors) {
Iterator<String> iterator = ancestors.descendingIterator();
List<String> nodeList = new ArrayList<>(ancestors.size() + 1);
while (iterator.hasNext()) {
@@ -258,22 +216,41 @@ public class PathPatternTree {
return new PartialPath(nodeList.toArray(new String[0]));
}
- public PathPatternTree findOverlappedPattern(PartialPath pattern) {
- return new PathPatternTree(findOverlappedPaths(pattern));
+
/////////////////////////////////////////////////////////////////////////////////////////////////
+ // serialize & deserialize
+
/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public void serialize(PublicBAOS outputStream) throws IOException {
+ constructTree();
+ root.serialize(outputStream);
}
- public List<PartialPath> findOverlappedPaths(PartialPath pattern) {
- if (pathList.isEmpty()) {
- pathList = splitToPathList();
- }
+ public void serialize(DataOutputStream stream) throws IOException {
+ constructTree();
+ root.serialize(stream);
+ }
- List<PartialPath> results = new ArrayList<>();
- for (PartialPath path : pathList) {
- if (pattern.overlapWith(path)) {
- results.add(path);
- }
+ public void serialize(ByteBuffer buffer) {
+ constructTree();
+ root.serialize(buffer);
+ }
+
+ public static PathPatternTree deserialize(ByteBuffer buffer) {
+ PathPatternNode root = deserializeNode(buffer);
+ PathPatternTree deserializedPatternTree = new PathPatternTree();
+ deserializedPatternTree.setRoot(root);
+ return deserializedPatternTree;
+ }
+
+ private static PathPatternNode deserializeNode(ByteBuffer buffer) {
+ PathPatternNode node = new
PathPatternNode(ReadWriteIOUtils.readString(buffer));
+ int childrenSize = ReadWriteIOUtils.readInt(buffer);
+ while (childrenSize > 0) {
+ PathPatternNode tmpNode = deserializeNode(buffer);
+ node.addChild(tmpNode);
+ childrenSize--;
}
- return results;
+ return node;
}
@TestOnly
@@ -286,9 +263,4 @@ public class PathPatternTree {
}
return this.getRoot().equalWith(that.getRoot());
}
-
- public boolean isEmpty() {
- return (root.getChildren() == null || root.getChildren().isEmpty())
- && (pathList == null || pathList.isEmpty());
- }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperator.java
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperator.java
index 542d974c5b..282559195f 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperator.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperator.java
@@ -102,7 +102,7 @@ public class SchemaFetchScanOperator implements
SourceOperator {
private void fetchSchema() throws MetadataException {
SchemaTree schemaTree = new SchemaTree();
- List<PartialPath> partialPathList = patternTree.splitToPathList();
+ List<PartialPath> partialPathList = patternTree.getAllPathPatterns();
for (PartialPath path : partialPathList) {
schemaTree.appendMeasurementPaths(schemaRegion.getMeasurementPaths(path,
false));
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
index ae40bfcd6f..d1e3c4cdf8 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
@@ -940,9 +940,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(createTimeSeriesStatement);
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendFullPath(createTimeSeriesStatement.getPath());
SchemaPartition schemaPartitionInfo =
- partitionFetcher.getOrCreateSchemaPartition(
- new PathPatternTree(createTimeSeriesStatement.getPath()));
+ partitionFetcher.getOrCreateSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
return analysis;
}
@@ -962,12 +963,14 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(createAlignedTimeSeriesStatement);
+ PathPatternTree pathPatternTree = new PathPatternTree();
+ for (String measurement :
createAlignedTimeSeriesStatement.getMeasurements()) {
+ pathPatternTree.appendFullPath(
+ createAlignedTimeSeriesStatement.getDevicePath(), measurement);
+ }
+
SchemaPartition schemaPartitionInfo;
- schemaPartitionInfo =
- partitionFetcher.getOrCreateSchemaPartition(
- new PathPatternTree(
- createAlignedTimeSeriesStatement.getDevicePath(),
- createAlignedTimeSeriesStatement.getMeasurements()));
+ schemaPartitionInfo =
partitionFetcher.getOrCreateSchemaPartition(pathPatternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
return analysis;
}
@@ -981,12 +984,14 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(internalCreateTimeSeriesStatement);
+ PathPatternTree pathPatternTree = new PathPatternTree();
+ for (String measurement :
internalCreateTimeSeriesStatement.getMeasurements()) {
+ pathPatternTree.appendFullPath(
+ internalCreateTimeSeriesStatement.getDevicePath(), measurement);
+ }
+
SchemaPartition schemaPartitionInfo;
- schemaPartitionInfo =
- partitionFetcher.getOrCreateSchemaPartition(
- new PathPatternTree(
- internalCreateTimeSeriesStatement.getDevicePath(),
- internalCreateTimeSeriesStatement.getMeasurements()));
+ schemaPartitionInfo =
partitionFetcher.getOrCreateSchemaPartition(pathPatternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
return analysis;
}
@@ -998,9 +1003,12 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(createMultiTimeSeriesStatement);
+ PathPatternTree patternTree = new PathPatternTree();
+ for (PartialPath path : createMultiTimeSeriesStatement.getPaths()) {
+ patternTree.appendFullPath(path);
+ }
SchemaPartition schemaPartitionInfo =
- partitionFetcher.getOrCreateSchemaPartition(
- new PathPatternTree(createMultiTimeSeriesStatement.getPaths()));
+ partitionFetcher.getOrCreateSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
return analysis;
}
@@ -1012,10 +1020,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(alterTimeSeriesStatement);
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendFullPath(alterTimeSeriesStatement.getPath());
SchemaPartition schemaPartitionInfo;
- schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new PathPatternTree(alterTimeSeriesStatement.getPath()));
+ schemaPartitionInfo = partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
return analysis;
}
@@ -1138,13 +1146,12 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(showTimeSeriesStatement);
- SchemaPartition schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new PathPatternTree(showTimeSeriesStatement.getPathPattern()));
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(showTimeSeriesStatement.getPathPattern());
+ SchemaPartition schemaPartitionInfo =
partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
if (showTimeSeriesStatement.isOrderByHeat()) {
- PathPatternTree patternTree = new
PathPatternTree(showTimeSeriesStatement.getPathPattern());
patternTree.constructTree();
// request schema fetch API
logger.info("{} fetch query schema...", getLogHeader());
@@ -1200,12 +1207,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(showDevicesStatement);
- SchemaPartition schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new PathPatternTree(
- showDevicesStatement
- .getPathPattern()
- .concatNode(IoTDBConstant.ONE_LEVEL_PATH_WILDCARD)));
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(
+
showDevicesStatement.getPathPattern().concatNode(IoTDBConstant.ONE_LEVEL_PATH_WILDCARD));
+ SchemaPartition schemaPartitionInfo =
partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
analysis.setRespDatasetHeader(
@@ -1248,12 +1253,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(countDevicesStatement);
- SchemaPartition schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new PathPatternTree(
- countDevicesStatement
- .getPartialPath()
- .concatNode(IoTDBConstant.ONE_LEVEL_PATH_WILDCARD)));
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(
+
countDevicesStatement.getPartialPath().concatNode(IoTDBConstant.ONE_LEVEL_PATH_WILDCARD));
+ SchemaPartition schemaPartitionInfo =
partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
analysis.setRespDatasetHeader(HeaderConstant.countDevicesHeader);
@@ -1266,9 +1269,9 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(countTimeSeriesStatement);
- SchemaPartition schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new PathPatternTree(countTimeSeriesStatement.getPartialPath()));
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(countTimeSeriesStatement.getPartialPath());
+ SchemaPartition schemaPartitionInfo =
partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
analysis.setRespDatasetHeader(HeaderConstant.countTimeSeriesHeader);
@@ -1281,9 +1284,9 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(countLevelTimeSeriesStatement);
- SchemaPartition schemaPartitionInfo =
- partitionFetcher.getSchemaPartition(
- new
PathPatternTree(countLevelTimeSeriesStatement.getPartialPath()));
+ PathPatternTree patternTree = new PathPatternTree();
+
patternTree.appendPathPattern(countLevelTimeSeriesStatement.getPartialPath());
+ SchemaPartition schemaPartitionInfo =
partitionFetcher.getSchemaPartition(patternTree);
analysis.setSchemaPartitionInfo(schemaPartitionInfo);
analysis.setRespDatasetHeader(HeaderConstant.countLevelTimeSeriesHeader);
@@ -1295,9 +1298,11 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(countStatement);
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(countStatement.getPartialPath());
SchemaNodeManagementPartition schemaNodeManagementPartition =
partitionFetcher.getSchemaNodeManagementPartitionWithLevel(
- new PathPatternTree(countStatement.getPartialPath()),
countStatement.getLevel());
+ patternTree, countStatement.getLevel());
if (schemaNodeManagementPartition == null) {
return analysis;
@@ -1336,8 +1341,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(statement);
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(path);
SchemaNodeManagementPartition schemaNodeManagementPartition =
- partitionFetcher.getSchemaNodeManagementPartition(new
PathPatternTree(path));
+ partitionFetcher.getSchemaNodeManagementPartition(patternTree);
if (schemaNodeManagementPartition == null) {
return analysis;
@@ -1360,7 +1367,10 @@ public class Analyzer {
Analysis analysis = new Analysis();
analysis.setStatement(deleteDataStatement);
- PathPatternTree patternTree = new
PathPatternTree(deleteDataStatement.getPathList());
+ PathPatternTree patternTree = new PathPatternTree();
+ for (PartialPath pathPattern : deleteDataStatement.getPathList()) {
+ patternTree.appendPathPattern(pathPattern);
+ }
SchemaPartition schemaPartition =
partitionFetcher.getSchemaPartition(patternTree);
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java
index 6ca63f54c4..8435e4b457 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java
@@ -108,7 +108,7 @@ public class ClusterPartitionFetcher implements
IPartitionFetcher {
try (ConfigNodeClient client =
configNodeClientManager.borrowClient(ConfigNodeInfo.partitionRegionId)) {
patternTree.constructTree();
- List<String> devicePaths = patternTree.findAllDevicePaths();
+ List<String> devicePaths = patternTree.getAllDevicePatterns();
Map<String, String> deviceToStorageGroupMap =
getDeviceToStorageGroup(devicePaths, false);
SchemaPartition schemaPartition =
partitionCache.getSchemaPartition(deviceToStorageGroupMap);
if (null == schemaPartition) {
@@ -132,7 +132,7 @@ public class ClusterPartitionFetcher implements
IPartitionFetcher {
try (ConfigNodeClient client =
configNodeClientManager.borrowClient(ConfigNodeInfo.partitionRegionId)) {
patternTree.constructTree();
- List<String> devicePaths = patternTree.findAllDevicePaths();
+ List<String> devicePaths = patternTree.getAllDevicePatterns();
Map<String, String> deviceToStorageGroupMap =
getDeviceToStorageGroup(devicePaths, true);
SchemaPartition schemaPartition =
partitionCache.getSchemaPartition(deviceToStorageGroupMap);
if (null == schemaPartition) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
index c314051244..2d2d06e2f1 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
@@ -142,8 +142,10 @@ public class ClusterSchemaFetcher implements
ISchemaFetcher {
Pair<List<String>, List<TSDataType>> missingMeasurements =
checkMissingMeasurements(schemaTree, devicePath, measurements,
tsDataTypes);
- PathPatternTree patternTree =
- new PathPatternTree(devicePath, missingMeasurements.left.toArray(new
String[0]));
+ PathPatternTree patternTree = new PathPatternTree();
+ for (String measurement : missingMeasurements.left) {
+ patternTree.appendFullPath(devicePath, measurement);
+ }
if (patternTree.isEmpty()) {
return schemaTree;
@@ -188,14 +190,16 @@ public class ClusterSchemaFetcher implements
ISchemaFetcher {
PathPatternTree patternTree = new PathPatternTree();
for (int i = 0; i < devicePathList.size(); i++) {
schemaTree.mergeSchemaTree(schemaCache.get(devicePathList.get(i),
measurementsList.get(i)));
- patternTree.appendPaths(
- devicePathList.get(i),
+ List<String> missingMeasurements =
checkMissingMeasurements(
schemaTree,
devicePathList.get(i),
measurementsList.get(i),
tsDataTypesList.get(i))
- .left);
+ .left;
+ for (String measurement : missingMeasurements) {
+ patternTree.appendFullPath(devicePathList.get(i), measurement);
+ }
}
if (patternTree.isEmpty()) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ExpressionAnalyzer.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ExpressionAnalyzer.java
index 1b6b7c363e..1cee37386b 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ExpressionAnalyzer.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ExpressionAnalyzer.java
@@ -192,7 +192,7 @@ public class ExpressionAnalyzer {
} else {
for (PartialPath prefixPath : prefixPaths) {
PartialPath concatPath = prefixPath.concatPath(rawPath);
- patternTree.appendPath(concatPath);
+ patternTree.appendPathPattern(concatPath);
actualPaths.add(concatPath);
}
}
@@ -232,12 +232,12 @@ public class ExpressionAnalyzer {
} else if (predicate instanceof TimeSeriesOperand) {
PartialPath rawPath = ((TimeSeriesOperand) predicate).getPath();
if (rawPath.getFullPath().startsWith(SQLConstant.ROOT +
TsFileConstant.PATH_SEPARATOR)) {
- patternTree.appendPath(rawPath);
+ patternTree.appendPathPattern(rawPath);
return;
}
for (PartialPath prefixPath : prefixPaths) {
PartialPath concatPath = prefixPath.concatPath(rawPath);
- patternTree.appendPath(concatPath);
+ patternTree.appendPathPattern(concatPath);
}
} else if (predicate instanceof TimestampOperand || predicate instanceof
ConstantOperand) {
// do nothing
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandaloneSchemaFetcher.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandaloneSchemaFetcher.java
index 599d608a80..cc61c86362 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandaloneSchemaFetcher.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandaloneSchemaFetcher.java
@@ -64,7 +64,7 @@ public class StandaloneSchemaFetcher implements
ISchemaFetcher {
patternTree.constructTree();
Set<String> storageGroupSet = new HashSet<>();
SchemaTree schemaTree = new SchemaTree();
- List<PartialPath> partialPathList = patternTree.splitToPathList();
+ List<PartialPath> partialPathList = patternTree.getAllPathPatterns();
try {
for (PartialPath path : partialPathList) {
List<PartialPath> storageGroups =
localConfigNode.getBelongedStorageGroups(path);
@@ -94,7 +94,7 @@ public class StandaloneSchemaFetcher implements
ISchemaFetcher {
patternTree.constructTree();
Set<String> storageGroupSet = new HashSet<>();
SchemaTree schemaTree = new SchemaTree();
- List<PartialPath> partialPathList = patternTree.splitToPathList();
+ List<PartialPath> partialPathList = patternTree.getAllPathPatterns();
try {
for (PartialPath path : partialPathList) {
String storageGroup =
localConfigNode.getBelongedStorageGroup(path).getFullPath();
@@ -115,7 +115,10 @@ public class StandaloneSchemaFetcher implements
ISchemaFetcher {
PartialPath devicePath, String[] measurements, TSDataType[] tsDataTypes,
boolean aligned) {
SchemaTree schemaTree = new SchemaTree();
- PathPatternTree patternTree = new PathPatternTree(devicePath,
measurements);
+ PathPatternTree patternTree = new PathPatternTree();
+ for (String measurement : measurements) {
+ patternTree.appendFullPath(devicePath, measurement);
+ }
if (patternTree.isEmpty()) {
return schemaTree;
@@ -150,7 +153,9 @@ public class StandaloneSchemaFetcher implements
ISchemaFetcher {
SchemaTree schemaTree = new SchemaTree();
PathPatternTree patternTree = new PathPatternTree();
for (int i = 0; i < devicePathList.size(); i++) {
- patternTree.appendPaths(devicePathList.get(i),
Arrays.asList(measurementsList.get(i)));
+ for (String measurement : measurementsList.get(i)) {
+ patternTree.appendFullPath(devicePathList.get(i), measurement);
+ }
}
if (patternTree.isEmpty()) {
@@ -229,8 +234,11 @@ public class StandaloneSchemaFetcher implements
ISchemaFetcher {
internalCreateTimeseries(
devicePath, missingMeasurements, dataTypesOfMissingMeasurement,
isAligned);
- SchemaTree reFetchSchemaTree =
- fetchSchema(new PathPatternTree(devicePath, missingMeasurements));
+ PathPatternTree patternTree = new PathPatternTree();
+ for (String measurement : missingMeasurements) {
+ patternTree.appendFullPath(devicePath, measurement);
+ }
+ SchemaTree reFetchSchemaTree = fetchSchema(patternTree);
Pair<List<String>, List<TSDataType>> recheckResult =
checkMissingMeasurements(
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
index fde0f78372..3f0eed38de 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanBuilder.java
@@ -716,12 +716,15 @@ public class LogicalPlanBuilder {
for (String storageGroup : storageGroupList) {
try {
storageGroupPath = new PartialPath(storageGroup);
+ PathPatternTree overlappedPatternTree = new PathPatternTree();
+ for (PartialPath pathPattern :
+ patternTree.getOverlappedPathPatterns(
+ storageGroupPath.concatNode(MULTI_LEVEL_PATH_WILDCARD))) {
+ overlappedPatternTree.appendPathPattern(pathPattern);
+ }
this.root.addChild(
new SchemaFetchScanNode(
- context.getQueryId().genPlanNodeId(),
- storageGroupPath,
- patternTree.findOverlappedPattern(
- storageGroupPath.concatNode(MULTI_LEVEL_PATH_WILDCARD))));
+ context.getQueryId().genPlanNodeId(), storageGroupPath,
overlappedPatternTree));
} catch (IllegalPathException e) {
// definitely won't happen
throw new RuntimeException(e);
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/internal/SchemaFetchStatement.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/internal/SchemaFetchStatement.java
index 9ab133be35..fde6a01a08 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/internal/SchemaFetchStatement.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/internal/SchemaFetchStatement.java
@@ -59,6 +59,6 @@ public class SchemaFetchStatement extends Statement {
@Override
public List<PartialPath> getPaths() {
- return patternTree.splitToPathList();
+ return patternTree.getAllPathPatterns();
}
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTreeTest.java
b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTreeTest.java
index 16b93e2247..614430f4fb 100644
---
a/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTreeTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTreeTest.java
@@ -143,13 +143,13 @@ public class PathPatternTreeTest {
throws IOException {
PathPatternTree patternTree = new PathPatternTree();
for (PartialPath path : paths) {
- patternTree.appendPath(path);
+ patternTree.appendPathPattern(path);
}
patternTree.constructTree();
PathPatternTree resultPatternTree = new PathPatternTree();
for (PartialPath path : compressedPaths) {
- resultPatternTree.appendPath(path);
+ resultPatternTree.appendPathPattern(path);
}
resultPatternTree.constructTree();
@@ -160,7 +160,7 @@ public class PathPatternTreeTest {
.map(PartialPath::getFullPath)
.sorted()
.collect(Collectors.toList()),
-
patternTree.findAllDevicePaths().stream().sorted().collect(Collectors.toList()));
+
patternTree.getAllDevicePatterns().stream().sorted().collect(Collectors.toList()));
PublicBAOS outputStream = new PublicBAOS();
resultPatternTree.serialize(outputStream);
@@ -182,12 +182,12 @@ public class PathPatternTreeTest {
PathPatternTree patternTree = new PathPatternTree();
for (PartialPath path : partialPathList) {
- patternTree.appendPath(path);
+ patternTree.appendPathPattern(path);
}
patternTree.constructTree();
Assert.assertEquals(
Arrays.asList(new PartialPath("root.sg1.*.t1.s1"), new
PartialPath("root.sg1.d1.t2.s2")),
- patternTree.splitToPathList());
+ patternTree.getAllPathPatterns());
}
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperatorTest.java
b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperatorTest.java
index 4b204bdd70..dd76bf4631 100644
---
a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperatorTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaFetchScanOperatorTest.java
@@ -66,8 +66,8 @@ public class SchemaFetchScanOperatorTest {
ISchemaRegion schemaRegion = prepareSchemaRegion();
PathPatternTree patternTree = new PathPatternTree();
- patternTree.appendPath(new PartialPath("root.**.status"));
- patternTree.appendPath(new PartialPath("root.**.s1"));
+ patternTree.appendPathPattern(new PartialPath("root.**.status"));
+ patternTree.appendPathPattern(new PartialPath("root.**.s1"));
patternTree.constructTree();
SchemaFetchScanOperator schemaFetchScanOperator =
diff --git
a/server/src/test/java/org/apache/iotdb/db/mpp/plan/plan/node/metadata/read/SchemaFetchScanNodeTest.java
b/server/src/test/java/org/apache/iotdb/db/mpp/plan/plan/node/metadata/read/SchemaFetchScanNodeTest.java
index 0caefd0ad2..ea3b5543e6 100644
---
a/server/src/test/java/org/apache/iotdb/db/mpp/plan/plan/node/metadata/read/SchemaFetchScanNodeTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/mpp/plan/plan/node/metadata/read/SchemaFetchScanNodeTest.java
@@ -35,17 +35,16 @@ public class SchemaFetchScanNodeTest {
@Test
public void testSerialization() throws IllegalPathException {
+ PathPatternTree patternTree = new PathPatternTree();
+ patternTree.appendPathPattern(new PartialPath("root.sg.**.*"));
SchemaFetchScanNode schemaFetchScanNode =
- new SchemaFetchScanNode(
- new PlanNodeId("0"),
- new PartialPath("root.sg"),
- new PathPatternTree(new PartialPath("root.sg.**.*")));
+ new SchemaFetchScanNode(new PlanNodeId("0"), new
PartialPath("root.sg"), patternTree);
ByteBuffer byteBuffer = ByteBuffer.allocate(1024 * 1024);
schemaFetchScanNode.serialize(byteBuffer);
byteBuffer.flip();
SchemaFetchScanNode recoveredNode = (SchemaFetchScanNode)
PlanNodeType.deserialize(byteBuffer);
Assert.assertEquals("root.sg",
recoveredNode.getStorageGroup().getFullPath());
Assert.assertEquals(
- "root.sg.**.*",
recoveredNode.getPatternTree().splitToPathList().get(0).getFullPath());
+ "root.sg.**.*",
recoveredNode.getPatternTree().getAllPathPatterns().get(0).getFullPath());
}
}