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/07/14 04:53:55 UTC
[incubator-iotdb] 01/01: make select use nodes
This is an automated email from the ASF dual-hosted git repository.
geniuspig pushed a commit to branch optimize_path
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 04d64762efeb3ccb8d7732a436861ecf4c0bc787
Author: zhutianci <zh...@gmail.com>
AuthorDate: Tue Jul 14 12:53:21 2020 +0800
make select use nodes
---
.../org/apache/iotdb/db/metadata/MManager.java | 14 ++++++
.../java/org/apache/iotdb/db/metadata/MTree.java | 51 ++++++++++++++++++++++
.../iotdb/db/qp/strategy/LogicalGenerator.java | 9 ++--
.../qp/strategy/optimizer/ConcatPathOptimizer.java | 12 ++---
.../org/apache/iotdb/tsfile/read/common/Path.java | 22 +++++++---
5 files changed, 91 insertions(+), 17 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index 6bc01ca..75cf379 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -808,6 +808,20 @@ public class MManager {
}
/**
+ * use nodes to get All Timeseries
+ * @param nodes a node list
+ */
+
+ public List<Path> getAllTimeseriesPath(List<String> nodes) throws MetadataException {
+ lock.readLock().lock();
+ try {
+ return mtree.getAllTimeseriesPath(nodes);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
* To calculate the count of timeseries for given prefix path.
*/
public int getAllTimeseriesCount(String prefixPath) throws MetadataException {
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 a0d90a3..d3921f7 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
@@ -562,6 +562,27 @@ public class MTree implements Serializable {
return paths;
}
+
+ /**
+ * Get all timeseries paths under the given path
+ *
+ * @param nodes a node list
+ */
+ List<Path> getAllTimeseriesPath(List<String> nodes) throws MetadataException {
+ Path prePath = new Path(nodes);
+ ShowTimeSeriesPlan plan = new ShowTimeSeriesPlan(prePath);
+ List<String[]> res = getAllMeasurementSchemaByNodes(plan);
+ List<Path> paths = new ArrayList<>();
+ for (String[] p : res) {
+ Path path = new Path(p[0]);
+ if (prePath.getMeasurement().equals(p[1])) {
+ path.setAlias(p[1]);
+ }
+ paths.add(path);
+ }
+ return paths;
+ }
+
/**
* Get the count of timeseries under the given prefix path.
*
@@ -696,6 +717,36 @@ public class MTree implements Serializable {
}
/**
+ * Get all time series schema under the given nodes
+ *
+ * <p>result: [name, alias, storage group, dataType, encoding, compression, offset]
+ */
+ List<String[]> getAllMeasurementSchemaByNodes(ShowTimeSeriesPlan plan) throws MetadataException {
+ List<String[]> res;
+ List<String> nodes = plan.getPath().getNodes();
+ if (nodes.size() == 0 || !nodes.get(0).equals(root.getName())) {
+ throw new IllegalPathException(plan.getPath().getFullPath());
+ }
+ limit.set(plan.getLimit());
+ offset.set(plan.getOffset());
+ curOffset.set(-1);
+ count.set(0);
+ if (offset.get() != 0 || limit.get() != 0) {
+ res = new LinkedList<>();
+ findPath(root, nodes.toArray(new String[0]), 1, "", res, true, false);
+ } else {
+ res = new LinkedList<>();
+ findPath(root, nodes.toArray(new String[0]), 1, "", res, false, false);
+ }
+ // avoid memory leaks
+ limit.remove();
+ offset.remove();
+ curOffset.remove();
+ count.remove();
+ return res;
+ }
+
+ /**
* Iterate through MTree to fetch metadata info of all leaf nodes under the given seriesPath
*
* @param needLast if false, lastTimeStamp in timeseriesSchemaList will be null
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 19b1aa8..6c17e46 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
@@ -1115,8 +1115,7 @@ public class LogicalGenerator extends SqlBaseBaseListener {
for (NodeNameWithoutStarContext nodeNameWithoutStar : nodeNamesWithoutStar) {
path.add(nodeNameWithoutStar.getText());
}
- return new Path(
- new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR));
+ return new Path(path);
}
@Override
@@ -1296,8 +1295,7 @@ public class LogicalGenerator extends SqlBaseBaseListener {
for (NodeNameContext nodeName : nodeNames) {
path.add(nodeName.getText());
}
- return new Path(
- new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR));
+ return new Path(path);
}
/**
@@ -1491,8 +1489,7 @@ public class LogicalGenerator extends SqlBaseBaseListener {
for (NodeNameContext nodeName : nodeNames) {
path.add(nodeName.getText());
}
- return new Path(
- new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR));
+ return new Path(path);
}
/**
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
index 62d0dec..7b35398 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
@@ -164,7 +164,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
// selectPath cannot start with ROOT, which is guaranteed by TSParser
Path selectPath = suffixPaths.get(i);
for (Path fromPath : fromPaths) {
- allPaths.add(Path.addPrefixPath(selectPath, fromPath));
+ allPaths.add(Path.addNotes(selectPath, fromPath));
extendListSafely(originAggregations, i, afterConcatAggregations);
}
}
@@ -225,7 +225,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
return operator;
}
List<Path> concatPaths = new ArrayList<>();
- fromPaths.forEach(fromPath -> concatPaths.add(Path.addPrefixPath(filterPath, fromPath)));
+ fromPaths.forEach(fromPath -> concatPaths.add(Path.addNotes(filterPath, fromPath)));
List<Path> noStarPaths = removeStarsInPathWithUnique(concatPaths);
filterPaths.addAll(noStarPaths);
if (noStarPaths.size() == 1) {
@@ -276,7 +276,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
HashSet<String> pathSet = new HashSet<>();
try {
for (Path path : paths) {
- List<Path> all = removeWildcard(path.getFullPath());
+ List<Path> all = removeWildcard(path.getNodes());
for (Path subPath : all) {
if (!pathSet.contains(subPath.getFullPath())) {
pathSet.add(subPath.getFullPath());
@@ -296,7 +296,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
List<String> newAggregations = new ArrayList<>();
for (int i = 0; i < paths.size(); i++) {
try {
- List<Path> actualPaths = removeWildcard(paths.get(i).getFullPath());
+ List<Path> actualPaths = removeWildcard(paths.get(i).getNodes());
for (Path actualPath : actualPaths) {
retPaths.add(actualPath);
if (afterConcatAggregations != null && !afterConcatAggregations.isEmpty()) {
@@ -311,7 +311,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
selectOperator.setAggregations(newAggregations);
}
- protected List<Path> removeWildcard(String path) throws MetadataException {
- return IoTDB.metaManager.getAllTimeseriesPath(path);
+ protected List<Path> removeWildcard(List<String> nodes) throws MetadataException {
+ return IoTDB.metaManager.getAllTimeseriesPath(nodes);
}
}
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 175d2d7..498381c 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
@@ -19,6 +19,8 @@
package org.apache.iotdb.tsfile.read.common;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.utils.StringContainer;
@@ -35,6 +37,7 @@ public class Path implements Serializable, Comparable<Path> {
private String alias = null;
private String device = null;
private String fullPath;
+ private List<String> nodes;
private static final String illegalPathArgument = "Path parameter is null";
public Path(StringContainer pathSc) {
@@ -52,11 +55,8 @@ public class Path implements Serializable, Comparable<Path> {
init(pathSc);
}
- public Path(String[] pathSc) {
- if (pathSc == null) {
- throw new IllegalArgumentException(illegalPathArgument);
- }
- init(new StringContainer(pathSc, TsFileConstant.PATH_SEPARATOR).toString());
+ public Path(List<String> nodes) {
+ this.nodes = nodes;
}
/**
@@ -134,6 +134,14 @@ public class Path implements Serializable, Comparable<Path> {
return new Path(sc);
}
+ public static Path addNotes(Path src, Path tail) {
+ if (tail.nodes.isEmpty()) {
+ return src;
+ }
+ src.nodes.addAll(tail.nodes);
+ return src;
+ }
+
/**
* add {@code prefix} as the prefix of {@code src}.
*
@@ -159,6 +167,10 @@ public class Path implements Serializable, Comparable<Path> {
public String getAlias() { return alias; }
+ public List<String> getNodes() {
+ return nodes;
+ }
+
public void setAlias(String alias) { this.alias = alias; }
public String getFullPathWithAlias() { return device + TsFileConstant.PATH_SEPARATOR + alias; }