This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch TyShowTimeSeries in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit cc272f925f0d02e81bda92fa8ec7026ced4b5c37 Author: JackieTien97 <[email protected]> AuthorDate: Mon Jul 6 09:33:30 2020 +0800 lack docs --- .../zh/SystemDesign/SchemaManager/SchemaManager.md | 3 ++ .../java/org/apache/iotdb/db/metadata/MTree.java | 52 +++++++++++----------- .../db/qp/physical/sys/ShowTimeSeriesPlan.java | 10 +++++ .../db/query/dataset/ShowTimeseriesDataSet.java | 4 +- .../org/apache/iotdb/db/service/TSServiceImpl.java | 35 +++++++++++++-- .../java/org/apache/iotdb/db/utils/QueryUtils.java | 3 ++ 6 files changed, 76 insertions(+), 31 deletions(-) diff --git a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md index ff948b9..7dd5981 100644 --- a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md +++ b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md @@ -280,3 +280,6 @@ IoTDB 的元数据管理采用目录树的形式,倒数第二层为设备层 > tagsSize (tag1=v1, tag2=v2) attributesSize (attr1=v1, attr2=v2) +## 元数据查询 + +### \ No newline at end of file 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 5136124..d847041 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 @@ -102,12 +102,12 @@ public class MTree implements Serializable { * Create a timeseries with a full path from root to leaf node Before creating a timeseries, the * storage group should be set first, throw exception otherwise * - * @param path timeseries path - * @param dataType data type - * @param encoding encoding + * @param path timeseries path + * @param dataType data type + * @param encoding encoding * @param compressor compressor - * @param props props - * @param alias alias of measurement + * @param props props + * @param alias alias of measurement */ MeasurementMNode createTimeseries( String path, @@ -650,7 +650,7 @@ public class MTree implements Serializable { } List<String[]> allMatchedNodes = new ArrayList<>(); - findPath(root, nodes, 1, "", allMatchedNodes, false, true); + findPath(root, nodes, 1, allMatchedNodes, false, true); Stream<String[]> sortedStream = allMatchedNodes.stream().sorted( Comparator.comparingLong((String[] s) -> Long.parseLong(s[7])).reversed() @@ -682,10 +682,10 @@ public class MTree implements Serializable { count.set(0); if (offset.get() != 0 || limit.get() != 0) { res = new LinkedList<>(); - findPath(root, nodes, 1, "", res, true, false); + findPath(root, nodes, 1, res, true, false); } else { res = new LinkedList<>(); - findPath(root, nodes, 1, "", res, false, false); + findPath(root, nodes, 1, res, false, false); } // avoid memory leaks limit.remove(); @@ -698,13 +698,12 @@ public class MTree implements Serializable { /** * 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 + * @param needLast if false, lastTimeStamp in timeseriesSchemaList will be null * @param timeseriesSchemaList List<timeseriesSchema> result: [name, alias, storage group, - * dataType, encoding, compression, offset, lastTimeStamp] + * dataType, encoding, compression, offset, lastTimeStamp] */ - private void findPath(MNode node, String[] nodes, int idx, String parent, - List<String[]> timeseriesSchemaList, boolean hasLimit, boolean needLast) - throws MetadataException { + private void findPath(MNode node, String[] nodes, int idx, List<String[]> timeseriesSchemaList, + boolean hasLimit, boolean needLast) throws MetadataException { if (node instanceof MeasurementMNode && nodes.length <= idx) { if (hasLimit) { curOffset.set(curOffset.get() + 1); @@ -718,7 +717,7 @@ public class MTree implements Serializable { } else { nodeName = node.getName(); } - String nodePath = parent + nodeName; + String nodePath = node.getParent().getFullPath() + nodeName; String[] tsRow = new String[8]; tsRow[0] = nodePath; tsRow[1] = ((MeasurementMNode) node).getAlias(); @@ -738,16 +737,19 @@ public class MTree implements Serializable { String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes); if (!nodeReg.contains(PATH_WILDCARD)) { if (node.hasChild(nodeReg)) { - findPath(node.getChild(nodeReg), nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR, - timeseriesSchemaList, hasLimit, needLast); + findPath(node.getChild(nodeReg), nodes, idx + 1, timeseriesSchemaList, hasLimit, needLast); } } else { for (MNode child : node.getChildren().values()) { if (!Pattern.matches(nodeReg.replace("*", ".*"), child.getName())) { continue; } - findPath(child, nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR, - timeseriesSchemaList, hasLimit, needLast); + findPath(child, nodes, idx + 1, timeseriesSchemaList, hasLimit, needLast); + if (hasLimit) { + if (count.get().intValue() == limit.get().intValue()) { + return; + } + } } } } @@ -788,11 +790,11 @@ public class MTree implements Serializable { /** * Traverse the MTree to match all child node path in next level * - * @param node the current traversing node - * @param nodes split the prefix path with '.' - * @param idx the current index of array nodes + * @param node the current traversing node + * @param nodes split the prefix path with '.' + * @param idx the current index of array nodes * @param parent store the node string having traversed - * @param res store all matched device names + * @param res store all matched device names * @param length expected length of path */ private void findChildNodePathInNextLevel( @@ -848,10 +850,10 @@ public class MTree implements Serializable { /** * Traverse the MTree to match all devices with prefix path. * - * @param node the current traversing node + * @param node the current traversing node * @param nodes split the prefix path with '.' - * @param idx the current index of array nodes - * @param res store all matched device names + * @param idx the current index of array nodes + * @param res store all matched device names */ private void findDevices(MNode node, String[] nodes, int idx, Set<String> res) { String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes); diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTimeSeriesPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTimeSeriesPlan.java index 0740870..78bf51c 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTimeSeriesPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTimeSeriesPlan.java @@ -36,6 +36,8 @@ public class ShowTimeSeriesPlan extends ShowPlan { // if is true, the result will be sorted according to the inserting frequency of the timeseries private boolean orderByHeat; + private boolean hasLimit; + public ShowTimeSeriesPlan(Path path) { super(ShowContentType.TIMESERIES); this.path = path; @@ -97,6 +99,14 @@ public class ShowTimeSeriesPlan extends ShowPlan { this.orderByHeat = orderByHeat; } + public boolean hasLimit() { + return hasLimit; + } + + public void setHasLimit(boolean hasLimit) { + this.hasLimit = hasLimit; + } + @Override public void serialize(DataOutputStream outputStream) throws IOException { outputStream.write(PhysicalPlanType.SHOW_TIMESERIES.ordinal()); diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/ShowTimeseriesDataSet.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/ShowTimeseriesDataSet.java index 403a3f7..128f40b 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/dataset/ShowTimeseriesDataSet.java +++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/ShowTimeseriesDataSet.java @@ -32,10 +32,10 @@ import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet; public class ShowTimeseriesDataSet extends QueryDataSet { - private ShowTimeSeriesPlan plan; + private final ShowTimeSeriesPlan plan; private List<RowRecord> result = new ArrayList<>(); private int index = 0; - public static boolean hasLimit; + public boolean hasLimit; public ShowTimeseriesDataSet(List<Path> paths, List<TSDataType> dataTypes, ShowTimeSeriesPlan showTimeSeriesPlan) { diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java index 19f668b..5fa8ea4 100644 --- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java +++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java @@ -81,7 +81,6 @@ import org.apache.iotdb.db.query.control.TracingManager; import org.apache.iotdb.db.query.dataset.AlignByDeviceDataSet; import org.apache.iotdb.db.query.dataset.NonAlignEngineDataSet; import org.apache.iotdb.db.query.dataset.RawQueryDataSetWithoutValueFilter; -import org.apache.iotdb.db.query.dataset.ShowTimeseriesDataSet; import org.apache.iotdb.db.tools.watermark.GroupedLSBWatermarkEncoder; import org.apache.iotdb.db.tools.watermark.WatermarkEncoder; import org.apache.iotdb.db.utils.FilePathUtils; @@ -89,7 +88,35 @@ import org.apache.iotdb.db.utils.QueryDataSetUtils; import org.apache.iotdb.db.utils.SchemaUtils; import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; -import org.apache.iotdb.service.rpc.thrift.*; +import org.apache.iotdb.service.rpc.thrift.ServerProperties; +import org.apache.iotdb.service.rpc.thrift.TSCancelOperationReq; +import org.apache.iotdb.service.rpc.thrift.TSCloseOperationReq; +import org.apache.iotdb.service.rpc.thrift.TSCloseSessionReq; +import org.apache.iotdb.service.rpc.thrift.TSCreateMultiTimeseriesReq; +import org.apache.iotdb.service.rpc.thrift.TSCreateTimeseriesReq; +import org.apache.iotdb.service.rpc.thrift.TSDeleteDataReq; +import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementReq; +import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq; +import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp; +import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq; +import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp; +import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq; +import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp; +import org.apache.iotdb.service.rpc.thrift.TSGetTimeZoneResp; +import org.apache.iotdb.service.rpc.thrift.TSIService; +import org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq; +import org.apache.iotdb.service.rpc.thrift.TSInsertRecordsReq; +import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordReq; +import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordsReq; +import org.apache.iotdb.service.rpc.thrift.TSInsertTabletReq; +import org.apache.iotdb.service.rpc.thrift.TSInsertTabletsReq; +import org.apache.iotdb.service.rpc.thrift.TSOpenSessionReq; +import org.apache.iotdb.service.rpc.thrift.TSOpenSessionResp; +import org.apache.iotdb.service.rpc.thrift.TSProtocolVersion; +import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet; +import org.apache.iotdb.service.rpc.thrift.TSQueryNonAlignDataSet; +import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException; import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; @@ -530,9 +557,9 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext { //If the user does not pass the limit, then set limit = fetchSize and haslimit=false,else set haslimit = true if (((ShowTimeSeriesPlan) plan).getLimit() == 0) { ((ShowTimeSeriesPlan) plan).setLimit(fetchSize); - ShowTimeseriesDataSet.hasLimit = false; + ((ShowTimeSeriesPlan) plan).setHasLimit(false); } else { - ShowTimeseriesDataSet.hasLimit = true; + ((ShowTimeSeriesPlan) plan).setHasLimit(true); } } if (plan instanceof QueryPlan && !((QueryPlan) plan).isAlignByTime()) { diff --git a/server/src/main/java/org/apache/iotdb/db/utils/QueryUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/QueryUtils.java index ca74ea3..d3c38c7 100644 --- a/server/src/main/java/org/apache/iotdb/db/utils/QueryUtils.java +++ b/server/src/main/java/org/apache/iotdb/db/utils/QueryUtils.java @@ -150,6 +150,9 @@ public class QueryUtils { constructPathAndDataTypes(paths, dataTypes, timeseriesList); ShowTimeseriesDataSet showTimeseriesDataSet = new ShowTimeseriesDataSet(paths, dataTypes, showTimeSeriesPlan); + + showTimeseriesDataSet.hasLimit = showTimeSeriesPlan.hasLimit(); + for (ShowTimeSeriesResult result : timeseriesList) { RowRecord record = new RowRecord(0); updateRecord(record, result.getName());
