This is an automated email from the ASF dual-hosted git repository. geniuspig pushed a commit to branch optimize_path_v2 in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit b4dd28372d39eb210718094904d860dbe6970339 Author: zhutianci <[email protected]> AuthorDate: Thu Aug 13 20:05:03 2020 +0800 sql->logical->physical --- .../org/apache/iotdb/db/qp/strategy/SqlBase.g4 | 84 +++++++------- .../org/apache/iotdb/db/metadata/MManager.java | 8 +- .../java/org/apache/iotdb/db/metadata/MTree.java | 33 +++--- .../org/apache/iotdb/db/metadata/MetaUtils.java | 42 +++++++ .../org/apache/iotdb/db/metadata/PartialPath.java | 101 +++++++++++++++++ .../org/apache/iotdb/db/metadata/mnode/MNode.java | 14 +++ .../org/apache/iotdb/db/monitor/StatMonitor.java | 3 +- .../apache/iotdb/db/qp/constant/SQLConstant.java | 6 + .../db/qp/logical/crud/BasicFunctionOperator.java | 12 +- .../iotdb/db/qp/logical/crud/FilterOperator.java | 17 +-- .../iotdb/db/qp/logical/crud/FromOperator.java | 8 +- .../iotdb/db/qp/logical/crud/InOperator.java | 12 +- .../iotdb/db/qp/logical/crud/SFWOperator.java | 6 +- .../iotdb/db/qp/logical/crud/SelectOperator.java | 15 ++- .../db/qp/logical/sys/AlterTimeSeriesOperator.java | 11 +- .../iotdb/db/qp/logical/sys/AuthorOperator.java | 8 +- .../iotdb/db/qp/logical/sys/CountOperator.java | 9 +- .../qp/logical/sys/CreateTimeSeriesOperator.java | 7 +- .../qp/logical/sys/DeleteStorageGroupOperator.java | 9 +- .../qp/logical/sys/DeleteTimeSeriesOperator.java | 7 +- .../iotdb/db/qp/logical/sys/FlushOperator.java | 8 +- .../db/qp/logical/sys/SetStorageGroupOperator.java | 8 +- .../iotdb/db/qp/logical/sys/SetTTLOperator.java | 7 +- .../db/qp/logical/sys/ShowChildPathsOperator.java | 8 +- .../db/qp/logical/sys/ShowDevicesOperator.java | 7 +- .../iotdb/db/qp/logical/sys/ShowTTLOperator.java | 8 +- .../db/qp/logical/sys/ShowTimeSeriesOperator.java | 7 +- .../apache/iotdb/db/qp/physical/PhysicalPlan.java | 9 +- .../iotdb/db/qp/physical/crud/DeletePlan.java | 28 ++--- .../iotdb/db/qp/physical/crud/InsertPlan.java | 7 +- .../iotdb/db/qp/physical/crud/InsertRowPlan.java | 35 +++--- .../iotdb/db/qp/physical/crud/QueryPlan.java | 7 +- .../db/qp/physical/sys/AlterTimeSeriesPlan.java | 9 +- .../iotdb/db/qp/physical/sys/AuthorPlan.java | 21 ++-- .../apache/iotdb/db/qp/physical/sys/CountPlan.java | 9 +- .../db/qp/physical/sys/CreateTimeSeriesPlan.java | 18 +-- .../db/qp/physical/sys/DeleteStorageGroupPlan.java | 22 ++-- .../db/qp/physical/sys/DeleteTimeSeriesPlan.java | 21 ++-- .../apache/iotdb/db/qp/physical/sys/FlushPlan.java | 8 +- .../db/qp/physical/sys/SetStorageGroupPlan.java | 21 ++-- .../iotdb/db/qp/physical/sys/SetTTLPlan.java | 23 ++-- .../db/qp/physical/sys/ShowChildPathsPlan.java | 7 +- .../iotdb/db/qp/physical/sys/ShowDevicesPlan.java | 8 +- .../apache/iotdb/db/qp/physical/sys/ShowPlan.java | 3 +- .../iotdb/db/qp/physical/sys/ShowTTLPlan.java | 10 +- .../db/qp/physical/sys/ShowTimeSeriesPlan.java | 16 +-- .../iotdb/db/qp/strategy/LogicalGenerator.java | 124 +++++++++++---------- .../iotdb/db/qp/strategy/PhysicalGenerator.java | 59 +++++----- .../org/apache/iotdb/db/utils/SchemaUtils.java | 5 +- .../iotdb/db/writelog/io/BatchLogReader.java | 3 +- 50 files changed, 575 insertions(+), 363 deletions(-) diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4 old mode 100644 new mode 100755 index 7a49244..d25a28d --- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4 +++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4 @@ -19,70 +19,72 @@ grammar SqlBase; +@parser::members {public static boolean hasSingleQuoteString;} + singleStatement : statement EOF ; statement - : CREATE TIMESERIES fullPath alias? WITH attributeClauses #createTimeseries - | DELETE TIMESERIES prefixPath (COMMA prefixPath)* #deleteTimeseries - | ALTER TIMESERIES fullPath alterClause #alterTimeseries - | INSERT INTO fullPath insertColumnSpec VALUES insertValuesSpec #insertStatement - | UPDATE prefixPath setClause whereClause? #updateStatement - | DELETE FROM prefixPath (COMMA prefixPath)* (whereClause)? #deleteStatement - | SET STORAGE GROUP TO fullPath #setStorageGroup - | DELETE STORAGE GROUP fullPath (COMMA fullPath)* #deleteStorageGroup + : {hasSingleQuoteString = false;} CREATE TIMESERIES fullPath alias? WITH attributeClauses #createTimeseries + | {hasSingleQuoteString = false;} DELETE TIMESERIES prefixPath (COMMA prefixPath)* #deleteTimeseries + | {hasSingleQuoteString = false;} ALTER TIMESERIES fullPath alterClause #alterTimeseries + | {hasSingleQuoteString = false;} INSERT INTO prefixPath insertColumnSpec VALUES insertValuesSpec #insertStatement + | {hasSingleQuoteString = false;} UPDATE prefixPath setClause whereClause? #updateStatement + | {hasSingleQuoteString = false;} DELETE FROM prefixPath (COMMA prefixPath)* (whereClause)? #deleteStatement + | {hasSingleQuoteString = false;} SET STORAGE GROUP TO prefixPath #setStorageGroup + | {hasSingleQuoteString = false;} DELETE STORAGE GROUP prefixPath (COMMA prefixPath)* #deleteStorageGroup | SHOW METADATA #showMetadata // not support yet | DESCRIBE prefixPath #describePath // not support yet | CREATE INDEX ON fullPath USING function=ID indexWithClause? whereClause? #createIndex //not support yet | DROP INDEX function=ID ON fullPath #dropIndex //not support yet | MERGE #merge - | FLUSH prefixPath? (COMMA prefixPath)* (booleanClause)?#flush + | {hasSingleQuoteString = false;}FLUSH prefixPath? (COMMA prefixPath)* (booleanClause)?#flush | FULL MERGE #fullMerge | CLEAR CACHE #clearcache - | CREATE USER userName=ID password=STRING_LITERAL #createUser - | ALTER USER userName=(ROOT|ID) SET PASSWORD password=STRING_LITERAL #alterUser + | {hasSingleQuoteString = true;} CREATE USER userName=ID password= stringLiteral#createUser + | {hasSingleQuoteString = true;} ALTER USER userName=(ROOT|ID) SET PASSWORD password=stringLiteral #alterUser | DROP USER userName=ID #dropUser | CREATE ROLE roleName=ID #createRole | DROP ROLE roleName=ID #dropRole - | GRANT USER userName=ID PRIVILEGES privileges ON prefixPath #grantUser - | GRANT ROLE roleName=ID PRIVILEGES privileges ON prefixPath #grantRole - | REVOKE USER userName=ID PRIVILEGES privileges ON prefixPath #revokeUser - | REVOKE ROLE roleName=ID PRIVILEGES privileges ON prefixPath #revokeRole + | GRANT USER userName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false;} prefixPath #grantUser + | GRANT ROLE roleName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false;} prefixPath #grantRole + | REVOKE USER userName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false;} prefixPath #revokeUser + | REVOKE ROLE roleName=ID PRIVILEGES privileges ON {hasSingleQuoteString = false;} prefixPath #revokeRole | GRANT roleName=ID TO userName=ID #grantRoleToUser | REVOKE roleName = ID FROM userName = ID #revokeRoleFromUser - | LOAD TIMESERIES (fileName=STRING_LITERAL) prefixPath #loadStatement + | {hasSingleQuoteString = true;} LOAD TIMESERIES (fileName=stringLiteral) prefixPath#loadStatement | GRANT WATERMARK_EMBEDDING TO rootOrId (COMMA rootOrId)* #grantWatermarkEmbedding | REVOKE WATERMARK_EMBEDDING FROM rootOrId (COMMA rootOrId)* #revokeWatermarkEmbedding | LIST USER #listUser | LIST ROLE #listRole - | LIST PRIVILEGES USER username=ID ON prefixPath #listPrivilegesUser - | LIST PRIVILEGES ROLE roleName=ID ON prefixPath #listPrivilegesRole + | LIST PRIVILEGES USER username=ID ON {hasSingleQuoteString = false;} prefixPath #listPrivilegesUser + | LIST PRIVILEGES ROLE roleName=ID ON {hasSingleQuoteString = false;} prefixPath #listPrivilegesRole | LIST USER PRIVILEGES username = ID #listUserPrivileges | LIST ROLE PRIVILEGES roleName = ID #listRolePrivileges | LIST ALL ROLE OF USER username = ID #listAllRoleOfUser | LIST ALL USER OF ROLE roleName = ID #listAllUserOfRole - | SET TTL TO path=prefixPath time=INT #setTTLStatement - | UNSET TTL TO path=prefixPath #unsetTTLStatement - | SHOW TTL ON prefixPath (COMMA prefixPath)* #showTTLStatement + | {hasSingleQuoteString = false;} SET TTL TO path=prefixPath time=INT #setTTLStatement + | {hasSingleQuoteString = false;} UNSET TTL TO path=prefixPath #unsetTTLStatement + | {hasSingleQuoteString = false;} SHOW TTL ON prefixPath (COMMA prefixPath)* #showTTLStatement | SHOW ALL TTL #showAllTTLStatement | SHOW FLUSH TASK INFO #showFlushTaskInfo | SHOW DYNAMIC PARAMETER #showDynamicParameter | SHOW VERSION #showVersion - | SHOW LATEST? TIMESERIES prefixPath? showWhereClause? limitClause? #showTimeseries + | {hasSingleQuoteString = false;} SHOW LATEST? TIMESERIES prefixPath? showWhereClause? limitClause? #showTimeseries | SHOW STORAGE GROUP #showStorageGroup - | SHOW CHILD PATHS prefixPath? #showChildPaths - | SHOW DEVICES prefixPath? #showDevices + | {hasSingleQuoteString = false;} SHOW CHILD PATHS prefixPath? #showChildPaths + | {hasSingleQuoteString = false;} SHOW DEVICES prefixPath? #showDevices | SHOW MERGE #showMergeStatus | TRACING ON #tracingOn | TRACING OFF #tracingOff | COUNT TIMESERIES prefixPath? (GROUP BY LEVEL OPERATOR_EQ INT)? #countTimeseries | COUNT NODES prefixPath LEVEL OPERATOR_EQ INT #countNodes | LOAD CONFIGURATION (MINUS GLOBAL)? #loadConfigurationStatement - | LOAD STRING_LITERAL autoCreateSchema? #loadFiles - | REMOVE STRING_LITERAL #removeFile - | MOVE STRING_LITERAL STRING_LITERAL #moveFile - | DELETE PARTITION prefixPath INT(COMMA INT)* #deletePartition + | {hasSingleQuoteString = true;} LOAD stringLiteral autoCreateSchema?#loadFiles + | {hasSingleQuoteString = true;} REMOVE stringLiteral #removeFile + | {hasSingleQuoteString = true;} MOVE stringLiteral stringLiteral #moveFile + | {hasSingleQuoteString = false;} DELETE PARTITION prefixPath INT(COMMA INT)* #deletePartition | CREATE SNAPSHOT FOR SCHEMA #createSnapshot | SELECT INDEX func=ID //not support yet LR_BRACKET @@ -92,7 +94,7 @@ statement fromClause whereClause? specialClause? #selectIndexStatement - | SELECT selectElements + | {hasSingleQuoteString = true;} SELECT selectElements fromClause whereClause? specialClause? #selectStatement @@ -101,7 +103,7 @@ statement selectElements : functionCall (COMMA functionCall)* #functionElement | suffixPath (COMMA suffixPath)* #selectElement - | STRING_LITERAL (COMMA STRING_LITERAL)* #selectConstElement + | stringLiteral (COMMA stringLiteral)* #selectConstElement | lastClause #lastElement ; @@ -202,7 +204,7 @@ inClause ; fromClause - : FROM prefixPath (COMMA prefixPath)* + : {hasSingleQuoteString = false;} FROM prefixPath (COMMA prefixPath)* ; specialClause @@ -332,7 +334,7 @@ setCol ; privileges - : STRING_LITERAL (COMMA STRING_LITERAL)* + : {hasSingleQuoteString = true;} stringLiteral (COMMA stringLiteral)* ; rootOrId @@ -354,7 +356,7 @@ timeValue propertyValue : INT | ID - | STRING_LITERAL + | {hasSingleQuoteString = true;} stringLiteral | constant ; @@ -373,7 +375,7 @@ suffixPath nodeName : ID | STAR - | STRING_LITERAL + | stringLiteral | ID STAR | DURATION | encoding @@ -484,7 +486,7 @@ nodeName nodeNameWithoutStar : ID - | STRING_LITERAL + | stringLiteral | DURATION | encoding | dataType @@ -606,7 +608,7 @@ constant | NaN | MINUS? realLiteral | MINUS? INT - | STRING_LITERAL + | {hasSingleQuoteString = true;} stringLiteral | booleanClause ; @@ -1206,9 +1208,9 @@ UNDERLINE : '_'; NaN : 'NaN'; -STRING_LITERAL - : DOUBLE_QUOTE_STRING_LITERAL - | SINGLE_QUOTE_STRING_LITERAL +stringLiteral + : {hasSingleQuoteString}? SINGLE_QUOTE_STRING_LITERAL + | DOUBLE_QUOTE_STRING_LITERAL ; INT : [0-9]+; @@ -1268,11 +1270,11 @@ fragment CN_CHAR : '\u2E80'..'\u9FFF' ; -fragment DOUBLE_QUOTE_STRING_LITERAL +DOUBLE_QUOTE_STRING_LITERAL : '"' ('\\' . | ~'"' )*? '"' ; -fragment SINGLE_QUOTE_STRING_LITERAL +SINGLE_QUOTE_STRING_LITERAL : '\'' ('\\' . | ~'\'' )*? '\'' ; 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 dd04ac1..f915a62 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 @@ -664,10 +664,10 @@ public class MManager { * * @param path full path */ - public TSDataType getSeriesType(String path) throws MetadataException { + public TSDataType getSeriesType(PartialPath path) throws MetadataException { lock.readLock().lock(); try { - if (path.equals(SQLConstant.RESERVED_TIME)) { + if (path.equals(SQLConstant.TIME_PATH)) { return TSDataType.INT64; } @@ -703,7 +703,7 @@ public class MManager { * wildcard can only match one level, otherwise it can match to the tail. * @return A HashSet instance which stores devices names with given prefixPath. */ - public Set<String> getDevices(String prefixPath) throws MetadataException { + public Set<PartialPath> getDevices(PartialPath prefixPath) throws MetadataException { lock.readLock().lock(); try { return mtree.getDevices(prefixPath); @@ -782,7 +782,7 @@ public class MManager { * @param prefixPath can be a prefix or a full path. if the wildcard is not at the tail, then each * wildcard can only match one level, otherwise it can match to the tail. */ - public List<String> getAllTimeseriesName(String prefixPath) throws MetadataException { + public List<String> getAllTimeseriesName(PartialPath prefixPath) throws MetadataException { lock.readLock().lock(); try { return mtree.getAllTimeseriesName(prefixPath); 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 935a767..f40a7b6 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 @@ -50,6 +50,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.regex.Pattern; import java.util.stream.Stream; +import javax.servlet.http.Part; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory; @@ -338,7 +339,7 @@ public class MTree implements Serializable { /** * Get measurement schema for a given path. Path must be a complete Path from root to leaf node. */ - MeasurementSchema getSchema(String path) throws MetadataException { + MeasurementSchema getSchema(PartialPath path) throws MetadataException { MeasurementMNode node = (MeasurementMNode) getNodeByPath(path); return node.getSchema(); } @@ -392,15 +393,15 @@ public class MTree implements Serializable { * * @return last node in given seriesPath */ - MNode getNodeByPath(String path) throws MetadataException { - String[] nodes = MetaUtils.getNodeNames(path); + MNode getNodeByPath(PartialPath path) throws MetadataException { + String[] nodes = path.getNodes(); if (nodes.length == 0 || !nodes[0].equals(root.getName())) { - throw new IllegalPathException(path); + throw new IllegalPathException(path.toString()); } MNode cur = root; for (int i = 1; i < nodes.length; i++) { if (!cur.hasChild(nodes[i])) { - throw new PathNotExistException(path); + throw new PathNotExistException(path.toString()); } cur = cur.getChild(nodes[i]); } @@ -533,8 +534,8 @@ public class MTree implements Serializable { * * @param prefixPath a prefix path or a full path, may contain '*'. */ - List<String> getAllTimeseriesName(String prefixPath) throws MetadataException { - ShowTimeSeriesPlan plan = new ShowTimeSeriesPlan(new Path(prefixPath)); + List<String> getAllTimeseriesName(PartialPath prefixPath) throws MetadataException { + ShowTimeSeriesPlan plan = new ShowTimeSeriesPlan(prefixPath); List<String[]> res = getAllMeasurementSchema(plan); List<String> paths = new ArrayList<>(); for (String[] p : res) { @@ -673,9 +674,9 @@ public class MTree implements Serializable { */ List<String[]> getAllMeasurementSchema(ShowTimeSeriesPlan plan) throws MetadataException { List<String[]> res; - String[] nodes = MetaUtils.getNodeNames(plan.getPath().getFullPath()); + String[] nodes = plan.getPath().getNodes(); if (nodes.length == 0 || !nodes[0].equals(root.getName())) { - throw new IllegalPathException(plan.getPath().getFullPath()); + throw new IllegalPathException(plan.getPath().toString()); } limit.set(plan.getLimit()); offset.set(plan.getOffset()); @@ -842,12 +843,12 @@ public class MTree implements Serializable { * * @return a list contains all distinct devices names */ - Set<String> getDevices(String prefixPath) throws MetadataException { - String[] nodes = MetaUtils.getNodeNames(prefixPath); + Set<PartialPath> getDevices(PartialPath prefixPath) throws MetadataException { + String[] nodes = prefixPath.getNodes(); if (nodes.length == 0 || !nodes[0].equals(root.getName())) { - throw new IllegalPathException(prefixPath); + throw new IllegalPathException(prefixPath.toString()); } - Set<String> devices = new TreeSet<>(); + Set<PartialPath> devices = new TreeSet<>(); findDevices(root, nodes, 1, devices); return devices; } @@ -860,12 +861,12 @@ public class MTree implements Serializable { * @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) { + private void findDevices(MNode node, String[] nodes, int idx, Set<PartialPath> res) { String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes); if (!(PATH_WILDCARD).equals(nodeReg)) { if (node.hasChild(nodeReg)) { if (node.getChild(nodeReg) instanceof MeasurementMNode) { - res.add(node.getFullPath()); + res.add(node.getPartialPath()); } else { findDevices(node.getChild(nodeReg), nodes, idx + 1, res); } @@ -874,7 +875,7 @@ public class MTree implements Serializable { boolean deviceAdded = false; for (MNode child : node.getChildren().values()) { if (child instanceof MeasurementMNode && !deviceAdded) { - res.add(node.getFullPath()); + res.add(node.getPartialPath()); deviceAdded = true; } findDevices(child, nodes, idx + 1, res); 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..255d1be 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 @@ -18,6 +18,8 @@ */ package org.apache.iotdb.db.metadata; +import java.util.ArrayList; +import java.util.List; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.exception.metadata.IllegalPathException; import org.apache.iotdb.db.exception.metadata.MetadataException; @@ -56,6 +58,46 @@ public class MetaUtils { return idx >= nodes.length ? PATH_WILDCARD : nodes[idx]; } + public static String getPathByDetachedPath(String[] nodes) { + StringBuilder s = new StringBuilder(nodes[0]); + for(int i = 1; i < nodes.length; i++) { + s.append(nodes[i]); + } + return s.toString(); + } + + /** + * + * @param path the path will split. ex, root.ln + * @return string array. ex, [root, ln] + * @throws IllegalPathException if path isn't correct, the exception will throw + */ + public static String[] splitPathToDetachedPath(String path) throws IllegalPathException { + List<String> nodes = new ArrayList<>(); + int startIndex = 0; + for (int i = 0; i < path.length(); i++) { + if (path.charAt(i) == IoTDBConstant.PATH_SEPARATOR) { + nodes.add(path.substring(startIndex, i)); + startIndex = i + 1; + } else if (path.charAt(i) == '"') { + int endIndex = path.indexOf('"', i + 1); + if (endIndex != -1 && (endIndex == path.length() - 1 || path.charAt(endIndex + 1) == '.')) { + nodes.add(path.substring(startIndex, endIndex + 1)); + i = endIndex + 1; + startIndex = endIndex + 2; + } else { + throw new IllegalPathException("Illegal path: " + path); + } + } else if (path.charAt(i) == '\'') { + throw new IllegalPathException("Illegal path with single quote: " + path); + } + } + if (startIndex <= path.length() - 1) { + nodes.add(path.substring(startIndex)); + } + return nodes.toArray(new String[0]); + } + /** * Get storage group name when creating schema automatically is enable * diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/PartialPath.java b/server/src/main/java/org/apache/iotdb/db/metadata/PartialPath.java new file mode 100755 index 0000000..b60d65f --- /dev/null +++ b/server/src/main/java/org/apache/iotdb/db/metadata/PartialPath.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.db.metadata; + +import java.util.Arrays; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.tsfile.common.constant.TsFileConstant; + +/** + * A prefix path, suffix path or fullPath generated from SQL + */ +public class PartialPath { + + private String[] nodes; + private String path; + + public PartialPath(String path) throws IllegalPathException { + this.nodes = MetaUtils.splitPathToDetachedPath(path); + this.path = path; + } + + public PartialPath(String[] partialNodes) { + nodes = partialNodes; + } + + public void concatPath(PartialPath partialPath) { + int len = nodes.length; + this.nodes = Arrays.copyOf(nodes, nodes.length + partialPath.nodes.length); + System.arraycopy(partialPath.nodes, 0, nodes, len, partialPath.nodes.length); + } + + public void concatPath(String[] otherNodes) { + int len = nodes.length; + this.nodes = Arrays.copyOf(nodes, nodes.length + otherNodes.length); + System.arraycopy(otherNodes, 0, nodes, len, otherNodes.length); + } + + public String[] getNodes() { + return nodes; + } + + @Override + public PartialPath clone() { + return new PartialPath(nodes.clone()); + } + + public String toString() { + if (path != null) { + return path; + } else { + StringBuilder s = new StringBuilder(nodes[0]); + for (int i = 1; i < nodes.length; i++) { + s.append(TsFileConstant.PATH_SEPARATOR); + s.append(nodes[i]); + } + path = s.toString(); + return path; + } + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof PartialPath)) { + return false; + } + String[] otherNodes = ((PartialPath) obj).getNodes(); + if( this.nodes.length != otherNodes.length) { + return false; + } else { + for(int i = 0; i < this.nodes.length; i++) { + if(!nodes[i].equals(otherNodes[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + return this.toString().hashCode(); + } + + +} diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java index d614b7f..490f282 100644 --- a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java +++ b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java @@ -23,7 +23,9 @@ import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_SEPARATOR; import java.io.BufferedWriter; import java.io.IOException; import java.io.Serializable; +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.locks.Lock; @@ -32,6 +34,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.exception.metadata.DeleteFailedException; import org.apache.iotdb.db.metadata.MetadataConstant; +import org.apache.iotdb.db.metadata.PartialPath; /** * This class is the implementation of Metadata Node. One MNode instance represents one node in the @@ -164,6 +167,17 @@ public class MNode implements Serializable { return fullPath; } + public PartialPath getPartialPath() { + List<String> detachedPath = new ArrayList<>(); + MNode temp = this; + detachedPath.add(temp.getName()); + while (temp.getParent() != null) { + temp = temp.getParent(); + detachedPath.add(0, temp.getName()); + } + return new PartialPath(detachedPath.toArray(new String[0])); + } + String concatFullPath() { StringBuilder builder = new StringBuilder(name); MNode curr = this; diff --git a/server/src/main/java/org/apache/iotdb/db/monitor/StatMonitor.java b/server/src/main/java/org/apache/iotdb/db/monitor/StatMonitor.java index a602663..7116ac4 100644 --- a/server/src/main/java/org/apache/iotdb/db/monitor/StatMonitor.java +++ b/server/src/main/java/org/apache/iotdb/db/monitor/StatMonitor.java @@ -27,6 +27,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.engine.StorageEngine; import org.apache.iotdb.db.exception.StartupException; import org.apache.iotdb.db.exception.StorageEngineException; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.monitor.MonitorConstants.FileNodeManagerStatConstants; @@ -386,7 +387,7 @@ public class StatMonitor implements IService { numInsert.incrementAndGet(); pointNum = entry.getValue().dataPointList.size(); numPointsInsert.addAndGet(pointNum); - } catch (StorageEngineException e) { + } catch (StorageEngineException | IllegalPathException e) { numInsertError.incrementAndGet(); logger.error("Inserting stat points error.", e); } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java index 5fdb148..4b21890 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb.db.qp.constant; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.strategy.SqlBaseLexer; import org.apache.iotdb.tsfile.read.common.Path; @@ -34,6 +35,9 @@ public class SQLConstant { // forbidding instantiation } + public static final String[] SINGLE_ROOT_ARRAY = new String[1]; + public static final String[] SINGLE_TIME_ARRAY = new String[1]; + public static final PartialPath TIME_PATH = new PartialPath(SINGLE_TIME_ARRAY); public static final String ALIGNBY_DEVICE_COLUMN_NAME = "Device"; public static final String RESERVED_TIME = "time"; public static final String IS_AGGREGATION = "IS_AGGREGATION"; @@ -161,6 +165,8 @@ public class SQLConstant { public static final Map<Integer, Integer> reverseWords = new HashMap<>(); static { + SINGLE_ROOT_ARRAY[0] = ROOT; + SINGLE_TIME_ARRAY[0] = RESERVED_TIME; tokenSymbol.put(KW_AND, "&"); tokenSymbol.put(KW_OR, "|"); tokenSymbol.put(KW_NOT, "!"); diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/BasicFunctionOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/BasicFunctionOperator.java index a92755a..b0d0521 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/BasicFunctionOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/BasicFunctionOperator.java @@ -23,10 +23,10 @@ import java.util.Objects; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.LogicalOperatorException; import org.apache.iotdb.db.exception.runtime.SQLParserException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.read.common.Path; import org.apache.iotdb.tsfile.read.expression.IUnaryExpression; import org.apache.iotdb.tsfile.utils.Binary; import org.apache.iotdb.tsfile.utils.Pair; @@ -51,7 +51,7 @@ public class BasicFunctionOperator extends FunctionOperator { * @param value value * @throws LogicalOperatorException Logical Operator Exception */ - public BasicFunctionOperator(int tokenIntType, Path path, String value) + public BasicFunctionOperator(int tokenIntType, PartialPath path, String value) throws SQLParserException { super(tokenIntType); operatorType = Operator.OperatorType.BASIC_FUNC; @@ -75,12 +75,12 @@ public class BasicFunctionOperator extends FunctionOperator { @Override protected Pair<IUnaryExpression, String> transformToSingleQueryFilter( - Map<Path, TSDataType> pathTSDataTypeHashMap) + Map<PartialPath, TSDataType> pathTSDataTypeHashMap) throws LogicalOperatorException, MetadataException { TSDataType type = pathTSDataTypeHashMap.get(singlePath); if (type == null) { throw new MetadataException( - "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata"); + "given seriesPath:{" + singlePath.toString() + "} don't exist in metadata"); } IUnaryExpression ret; @@ -110,7 +110,7 @@ public class BasicFunctionOperator extends FunctionOperator { throw new LogicalOperatorException(type.toString(), ""); } - return new Pair<>(ret, singlePath.getFullPath()); + return new Pair<>(ret, singlePath.toString()); } @Override @@ -141,7 +141,7 @@ public class BasicFunctionOperator extends FunctionOperator { @Override public String toString() { - return "[" + singlePath.getFullPath() + tokenSymbol + value + "]"; + return "[" + singlePath.toString() + tokenSymbol + value + "]"; } @Override diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FilterOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FilterOperator.java index eebd40a..628d90e 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FilterOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FilterOperator.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.LogicalOperatorException; import org.apache.iotdb.db.exception.query.QueryProcessException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -56,9 +57,9 @@ public class FilterOperator extends Operator implements Comparable<FilterOperato // isSingle being true means all recursive children of this filter belong to one seriesPath. boolean isSingle = false; // if isSingle = false, singlePath must be null - Path singlePath = null; + PartialPath singlePath = null; // all paths involved in this filter - Set<Path> pathSet; + Set<PartialPath> pathSet; public FilterOperator(int tokenType) { super(tokenType); @@ -97,11 +98,11 @@ public class FilterOperator extends Operator implements Comparable<FilterOperato this.isSingle = b; } - public Path getSinglePath() { + public PartialPath getSinglePath() { return singlePath; } - public void setSinglePath(Path singlePath) { + public void setSinglePath(PartialPath singlePath) { this.singlePath = singlePath; } @@ -110,11 +111,11 @@ public class FilterOperator extends Operator implements Comparable<FilterOperato return true; } - public void setPathSet(Set<Path> pathSet) { + public void setPathSet(Set<PartialPath> pathSet) { this.pathSet = pathSet; } - public Set<Path> getPathSet() { + public Set<PartialPath> getPathSet() { return pathSet; } @@ -126,7 +127,7 @@ public class FilterOperator extends Operator implements Comparable<FilterOperato * @param pathTSDataTypeHashMap */ public IExpression transformToExpression( - Map<Path, TSDataType> pathTSDataTypeHashMap) throws QueryProcessException { + Map<PartialPath, TSDataType> pathTSDataTypeHashMap) throws QueryProcessException { if (isSingle) { Pair<IUnaryExpression, String> ret; try { @@ -169,7 +170,7 @@ public class FilterOperator extends Operator implements Comparable<FilterOperato * @param pathTSDataTypeHashMap */ protected Pair<IUnaryExpression, String> transformToSingleQueryFilter( - Map<Path, TSDataType> pathTSDataTypeHashMap) + Map<PartialPath, TSDataType> pathTSDataTypeHashMap) throws LogicalOperatorException, MetadataException { if (childOperators.isEmpty()) { throw new LogicalOperatorException(String.valueOf(tokenIntType), diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FromOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FromOperator.java index d86b71f..1fc44d5 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FromOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/FromOperator.java @@ -20,15 +20,15 @@ package org.apache.iotdb.db.qp.logical.crud; import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; -import org.apache.iotdb.tsfile.read.common.Path; /** * this class maintains information of {@code FROM} clause. */ public class FromOperator extends Operator { - private List<Path> prefixList; + private List<PartialPath> prefixList; public FromOperator(int tokenIntType) { super(tokenIntType); @@ -36,11 +36,11 @@ public class FromOperator extends Operator { prefixList = new ArrayList<>(); } - public void addPrefixTablePath(Path prefixPath) { + public void addPrefixTablePath(PartialPath prefixPath) { prefixList.add(prefixPath); } - public List<Path> getPrefixPaths() { + public List<PartialPath> getPrefixPaths() { return prefixList; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/InOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/InOperator.java index 6f9c303..a1a6e00 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/InOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/InOperator.java @@ -27,6 +27,8 @@ import java.util.Objects; import java.util.Set; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.LogicalOperatorException; +import org.apache.iotdb.db.metadata.MetaUtils; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.read.common.Path; @@ -55,7 +57,7 @@ public class InOperator extends FunctionOperator { * @param path path * @param values values */ - public InOperator(int tokenIntType, Path path, boolean not, Set<String> values) { + public InOperator(int tokenIntType, PartialPath path, boolean not, Set<String> values) { super(tokenIntType); operatorType = Operator.OperatorType.IN; this.singlePath = path; @@ -76,12 +78,12 @@ public class InOperator extends FunctionOperator { @Override protected Pair<IUnaryExpression, String> transformToSingleQueryFilter( - Map<Path, TSDataType> pathTSDataTypeHashMap) + Map<PartialPath, TSDataType> pathTSDataTypeHashMap) throws LogicalOperatorException, MetadataException { TSDataType type = pathTSDataTypeHashMap.get(singlePath); if (type == null) { throw new MetadataException( - "given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata"); + "given seriesPath:{" + singlePath.toString() + "} don't exist in metadata"); } IUnaryExpression ret; @@ -135,7 +137,7 @@ public class InOperator extends FunctionOperator { throw new LogicalOperatorException(type.toString(), ""); } - return new Pair<>(ret, singlePath.getFullPath()); + return new Pair<>(ret, singlePath.toString()); } @Override @@ -163,7 +165,7 @@ public class InOperator extends FunctionOperator { public String toString() { List<String> valuesList = new ArrayList<>(values); Collections.sort(valuesList); - return "[" + singlePath.getFullPath() + tokenSymbol + not + valuesList + "]"; + return "[" + singlePath.toString() + tokenSymbol + not + valuesList + "]"; } @Override diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SFWOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SFWOperator.java index a6c0c24..5b07005 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SFWOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SFWOperator.java @@ -19,8 +19,8 @@ package org.apache.iotdb.db.qp.logical.crud; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; /** * SFWOperator(select-from-where) includes four subclass: INSERT,DELETE,UPDATE,QUERY. All of these @@ -77,8 +77,8 @@ public abstract class SFWOperator extends RootOperator { * * @return - a list of seriesPath */ - public List<Path> getSelectedPaths() { - List<Path> suffixPaths = null; + public List<PartialPath> getSelectedPaths() { + List<PartialPath> suffixPaths = null; if (selectOperator != null) { suffixPaths = selectOperator.getSuffixPaths(); } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java index 961f112..430572e 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java @@ -18,18 +18,17 @@ */ package org.apache.iotdb.db.qp.logical.crud; -import org.apache.iotdb.db.qp.logical.Operator; -import org.apache.iotdb.tsfile.read.common.Path; - import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; +import org.apache.iotdb.db.qp.logical.Operator; /** * this class maintains information from select clause. */ public final class SelectOperator extends Operator { - private List<Path> suffixList; + private List<PartialPath> suffixList; private List<String> aggregations; private boolean lastQuery; @@ -44,11 +43,11 @@ public final class SelectOperator extends Operator { lastQuery = false; } - public void addSelectPath(Path suffixPath) { + public void addSelectPath(PartialPath suffixPath) { suffixList.add(suffixPath); } - public void addClusterPath(Path suffixPath, String aggregation) { + public void addClusterPath(PartialPath suffixPath, String aggregation) { suffixList.add(suffixPath); aggregations.add(aggregation); } @@ -65,11 +64,11 @@ public final class SelectOperator extends Operator { this.aggregations = aggregations; } - public void setSuffixPathList(List<Path> suffixPaths) { + public void setSuffixPathList(List<PartialPath> suffixPaths) { suffixList = suffixPaths; } - public List<Path> getSuffixPaths() { + public List<PartialPath> getSuffixPaths() { return suffixList; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AlterTimeSeriesOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AlterTimeSeriesOperator.java index 1c14588..771a088 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AlterTimeSeriesOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AlterTimeSeriesOperator.java @@ -19,14 +19,13 @@ package org.apache.iotdb.db.qp.logical.sys; -import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; - import java.util.Map; +import org.apache.iotdb.db.metadata.PartialPath; +import org.apache.iotdb.db.qp.logical.RootOperator; public class AlterTimeSeriesOperator extends RootOperator { - private Path path; + private PartialPath path; private AlterType alterType; @@ -47,11 +46,11 @@ public class AlterTimeSeriesOperator extends RootOperator { operatorType = OperatorType.ALTER_TIMESERIES; } - public Path getPath() { + public PartialPath getPath() { return path; } - public void setPath(Path path) { + public void setPath(PartialPath path) { this.path = path; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java index f60489a..3a8c9aa 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java @@ -18,8 +18,8 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; /** * this class maintains information in Author statement, including CREATE, DROP, GRANT and REVOKE. @@ -32,7 +32,7 @@ public class AuthorOperator extends RootOperator { private String password; private String newPassword; private String[] privilegeList; - private Path nodeName; + private PartialPath nodeName; /** * AuthorOperator Constructor with AuthorType. @@ -102,11 +102,11 @@ public class AuthorOperator extends RootOperator { this.privilegeList = authorizationList; } - public Path getNodeName() { + public PartialPath getNodeName() { return nodeName; } - public void setNodeNameList(Path nodePath) { + public void setNodeNameList(PartialPath nodePath) { this.nodeName = nodePath; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CountOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CountOperator.java index 6c9c339..1033851 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CountOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CountOperator.java @@ -18,27 +18,28 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; /** * CountOperator is used to count time-series and count nodes. */ public class CountOperator extends ShowOperator{ - private Path path; + private PartialPath path; private int level; - public CountOperator(int tokenIntType, Path path){ + public CountOperator(int tokenIntType, PartialPath path){ super(tokenIntType); this.path = path; } - public CountOperator(int tokenIntType, Path path, int level){ + public CountOperator(int tokenIntType, PartialPath path, int level){ super(tokenIntType); this.path = path; this.level = level; } - public Path getPath() { + public PartialPath getPath() { return this.path; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CreateTimeSeriesOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CreateTimeSeriesOperator.java index 2e4f648..4b5e9d3 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CreateTimeSeriesOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CreateTimeSeriesOperator.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -28,7 +29,7 @@ import java.util.Map; public class CreateTimeSeriesOperator extends RootOperator { - private Path path; + private PartialPath path; private String alias; private TSDataType dataType; private TSEncoding encoding; @@ -42,11 +43,11 @@ public class CreateTimeSeriesOperator extends RootOperator { operatorType = OperatorType.CREATE_TIMESERIES; } - public Path getPath() { + public PartialPath getPath() { return path; } - public void setPath(Path path) { + public void setPath(PartialPath path) { this.path = path; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteStorageGroupOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteStorageGroupOperator.java index b3014f1..c16889b 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteStorageGroupOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteStorageGroupOperator.java @@ -19,24 +19,23 @@ package org.apache.iotdb.db.qp.logical.sys; import java.util.List; - +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; public class DeleteStorageGroupOperator extends RootOperator { - private List<Path> deletePathList; + private List<PartialPath> deletePathList; public DeleteStorageGroupOperator(int tokenIntType) { super(tokenIntType); operatorType = OperatorType.DELETE_STORAGE_GROUP; } - public List<Path> getDeletePathList() { + public List<PartialPath> getDeletePathList() { return deletePathList; } - public void setDeletePathList(List<Path> deletePathList) { + public void setDeletePathList(List<PartialPath> deletePathList) { this.deletePathList = deletePathList; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteTimeSeriesOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteTimeSeriesOperator.java index 6065883..a58c756 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteTimeSeriesOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/DeleteTimeSeriesOperator.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.qp.logical.sys; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; import org.apache.iotdb.tsfile.read.common.Path; @@ -28,18 +29,18 @@ import org.apache.iotdb.tsfile.read.common.Path; */ public class DeleteTimeSeriesOperator extends RootOperator { - private List<Path> deletePathList; + private List<PartialPath> deletePathList; public DeleteTimeSeriesOperator(int tokenIntType) { super(tokenIntType); operatorType = OperatorType.DELETE_TIMESERIES; } - public List<Path> getDeletePathList() { + public List<PartialPath> getDeletePathList() { return deletePathList; } - public void setDeletePathList(List<Path> deletePathList) { + public void setDeletePathList(List<PartialPath> deletePathList) { this.deletePathList = deletePathList; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/FlushOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/FlushOperator.java index ef9c370..33c09f7 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/FlushOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/FlushOperator.java @@ -19,21 +19,21 @@ package org.apache.iotdb.db.qp.logical.sys; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; public class FlushOperator extends RootOperator { - public List<Path> getStorageGroupList() { + public List<PartialPath> getStorageGroupList() { return storageGroupList; } public void setStorageGroupList( - List<Path> storageGroupList) { + List<PartialPath> storageGroupList) { this.storageGroupList = storageGroupList; } - private List<Path> storageGroupList; + private List<PartialPath> storageGroupList; public Boolean isSeq() { return isSeq; diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetStorageGroupOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetStorageGroupOperator.java index aed877f..9955195 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetStorageGroupOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetStorageGroupOperator.java @@ -18,23 +18,23 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; -import org.apache.iotdb.tsfile.read.common.Path; public class SetStorageGroupOperator extends RootOperator { - private Path path; + private PartialPath path; public SetStorageGroupOperator(int tokenIntType) { super(tokenIntType); operatorType = OperatorType.SET_STORAGE_GROUP; } - public Path getPath() { + public PartialPath getPath() { return path; } - public void setPath(Path path) { + public void setPath(PartialPath path) { this.path = path; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetTTLOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetTTLOperator.java index d842165..e2ae3c2 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetTTLOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/SetTTLOperator.java @@ -20,11 +20,12 @@ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.RootOperator; public class SetTTLOperator extends RootOperator { - private String storageGroup; + private PartialPath storageGroup; private long dataTTL; public SetTTLOperator(int tokenIntType) { @@ -32,11 +33,11 @@ public class SetTTLOperator extends RootOperator { this.operatorType = OperatorType.TTL; } - public String getStorageGroup() { + public PartialPath getStorageGroup() { return storageGroup; } - public void setStorageGroup(String storageGroup) { + public void setStorageGroup(PartialPath storageGroup) { this.storageGroup = storageGroup; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowChildPathsOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowChildPathsOperator.java index a2c485b..5f10b09 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowChildPathsOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowChildPathsOperator.java @@ -19,18 +19,18 @@ */ package org.apache.iotdb.db.qp.logical.sys; -import org.apache.iotdb.tsfile.read.common.Path; +import org.apache.iotdb.db.metadata.PartialPath; public class ShowChildPathsOperator extends ShowOperator { - private Path path; + private PartialPath path; - public ShowChildPathsOperator(int tokenIntType, Path path) { + public ShowChildPathsOperator(int tokenIntType, PartialPath path) { super(tokenIntType); this.path = path; } - public Path getPath() { + public PartialPath getPath() { return path; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowDevicesOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowDevicesOperator.java index 6c5d98f..67f502c 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowDevicesOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowDevicesOperator.java @@ -19,18 +19,19 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; public class ShowDevicesOperator extends ShowOperator { - private Path path; + private PartialPath path; - public ShowDevicesOperator(int tokenIntType, Path path) { + public ShowDevicesOperator(int tokenIntType, PartialPath path) { super(tokenIntType); this.path = path; } - public Path getPath() { + public PartialPath getPath() { return path; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTTLOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTTLOperator.java index 3426883..3d381af 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTTLOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTTLOperator.java @@ -21,19 +21,19 @@ package org.apache.iotdb.db.qp.logical.sys; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.SQLConstant; -import org.apache.iotdb.db.qp.logical.RootOperator; public class ShowTTLOperator extends ShowOperator { - private List<String> storageGroups; + private List<PartialPath> storageGroups; - public ShowTTLOperator(List<String> storageGroups) { + public ShowTTLOperator(List<PartialPath> storageGroups) { super(SQLConstant.TOK_SHOW, OperatorType.TTL); this.storageGroups = storageGroups; } - public List<String> getStorageGroups() { + public List<PartialPath> getStorageGroups() { return storageGroups; } } \ No newline at end of file diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTimeSeriesOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTimeSeriesOperator.java index e8fcab2..19e8931 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTimeSeriesOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/ShowTimeSeriesOperator.java @@ -19,11 +19,12 @@ */ package org.apache.iotdb.db.qp.logical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; public class ShowTimeSeriesOperator extends ShowOperator { - private Path path; + private PartialPath path; private boolean isContains; private String key; private String value; @@ -32,13 +33,13 @@ public class ShowTimeSeriesOperator extends ShowOperator { // if is true, the result will be sorted according to the inserting frequency of the timeseries private final boolean orderByHeat; - public ShowTimeSeriesOperator(int tokeIntType, Path path, boolean orderByHeat) { + public ShowTimeSeriesOperator(int tokeIntType, PartialPath path, boolean orderByHeat) { super(tokeIntType); this.path = path; this.orderByHeat = orderByHeat; } - public Path getPath() { + public PartialPath getPath() { return path; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java index 9746b7b..d6cf9c9 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.qp.physical.crud.DeletePlan; @@ -37,7 +39,6 @@ import org.apache.iotdb.db.qp.physical.sys.LoadConfigurationPlan; import org.apache.iotdb.db.qp.physical.sys.SetStorageGroupPlan; import org.apache.iotdb.db.qp.physical.sys.SetTTLPlan; import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan; -import org.apache.iotdb.tsfile.read.common.Path; import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; /** @@ -74,7 +75,7 @@ public abstract class PhysicalPlan { return "abstract plan"; } - public abstract List<Path> getPaths(); + public abstract List<PartialPath> getPaths(); public boolean isQuery() { return isQuery; @@ -122,7 +123,7 @@ public abstract class PhysicalPlan { * * @param buffer */ - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { throw new UnsupportedOperationException(SERIALIZATION_UNIMPLEMENTED); } @@ -156,7 +157,7 @@ public abstract class PhysicalPlan { // hidden initializer } - public static PhysicalPlan create(ByteBuffer buffer) throws IOException { + public static PhysicalPlan create(ByteBuffer buffer) throws IOException, IllegalPathException { int typeNum = buffer.get(); if (typeNum >= PhysicalPlanType.values().length) { throw new IOException("unrecognized log type " + typeNum); diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java index 5c3dd07..fed929c 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java @@ -24,6 +24,8 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.tsfile.read.common.Path; @@ -32,7 +34,7 @@ public class DeletePlan extends PhysicalPlan { private long deleteStartTime; private long deleteEndTime; - private List<Path> paths = new ArrayList<>(); + private List<PartialPath> paths = new ArrayList<>(); public DeletePlan() { super(false, Operator.OperatorType.DELETE); @@ -45,7 +47,7 @@ public class DeletePlan extends PhysicalPlan { * @param endTime delete time range end * @param path time series path */ - public DeletePlan(long startTime, long endTime, Path path) { + public DeletePlan(long startTime, long endTime, PartialPath path) { super(false, Operator.OperatorType.DELETE); this.deleteStartTime = startTime; this.deleteEndTime = endTime; @@ -59,7 +61,7 @@ public class DeletePlan extends PhysicalPlan { * @param endTime delete time range end * @param paths time series paths in List structure */ - public DeletePlan(long startTime, long endTime, List<Path> paths) { + public DeletePlan(long startTime, long endTime, List<PartialPath> paths) { super(false, Operator.OperatorType.DELETE); this.deleteStartTime = startTime; this.deleteEndTime = endTime; @@ -82,20 +84,20 @@ public class DeletePlan extends PhysicalPlan { this.deleteEndTime = delTime; } - public void addPath(Path path) { + public void addPath(PartialPath path) { this.paths.add(path); } - public void addPaths(List<Path> paths) { + public void addPaths(List<PartialPath> paths) { this.paths.addAll(paths); } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return paths; } - public void setPaths(List<Path> paths) { + public void setPaths(List<PartialPath> paths) { this.paths = paths; } @@ -124,8 +126,8 @@ public class DeletePlan extends PhysicalPlan { stream.writeLong(deleteStartTime); stream.writeLong(deleteEndTime); stream.writeInt(paths.size()); - for (Path path : paths) { - putString(stream, path.getFullPath()); + for (PartialPath path : paths) { + putString(stream, path.toString()); } } @@ -136,19 +138,19 @@ public class DeletePlan extends PhysicalPlan { buffer.putLong(deleteStartTime); buffer.putLong(deleteEndTime); buffer.putInt(paths.size()); - for (Path path : paths) { - putString(buffer, path.getFullPath()); + for (PartialPath path : paths) { + putString(buffer, path.toString()); } } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { this.deleteStartTime = buffer.getLong(); this.deleteEndTime = buffer.getLong(); int pathSize = buffer.getInt(); this.paths = new ArrayList(); for (int i = 0; i < pathSize; i++) { - paths.add(new Path(readString(buffer))); + paths.add(new PartialPath(readString(buffer))); } } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java index 36a1174..1299294 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java @@ -21,6 +21,7 @@ package org.apache.iotdb.db.qp.physical.crud; import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.metadata.mnode.MNode; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; @@ -29,7 +30,7 @@ import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; abstract public class InsertPlan extends PhysicalPlan { - protected String deviceId; + protected PartialPath deviceId; protected String[] measurements; protected TSDataType[] dataTypes; protected MeasurementSchema[] schemas; @@ -45,11 +46,11 @@ abstract public class InsertPlan extends PhysicalPlan { super.canBeSplit = false; } - public String getDeviceId() { + public PartialPath getDeviceId() { return deviceId; } - public void setDeviceId(String deviceId) { + public void setDeviceId(PartialPath deviceId) { this.deviceId = deviceId; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java index 5c0f4d5..41044e3 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java @@ -27,8 +27,11 @@ import java.util.List; import java.util.Objects; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; import org.apache.iotdb.db.exception.metadata.PathNotExistException; import org.apache.iotdb.db.exception.query.QueryProcessException; +import org.apache.iotdb.db.metadata.MetaUtils; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.utils.CommonUtils; @@ -62,7 +65,7 @@ public class InsertRowPlan extends InsertPlan { } @TestOnly - public InsertRowPlan(String deviceId, long insertTime, String[] measurements, + public InsertRowPlan(PartialPath deviceId, long insertTime, String[] measurements, TSDataType[] dataTypes, String[] insertValues) { super(OperatorType.INSERT); this.time = insertTime; @@ -80,7 +83,7 @@ public class InsertRowPlan extends InsertPlan { } @TestOnly - public InsertRowPlan(String deviceId, long insertTime, String measurement, TSDataType type, + public InsertRowPlan(PartialPath deviceId, long insertTime, String measurement, TSDataType type, String insertValue) { super(OperatorType.INSERT); this.time = insertTime; @@ -95,9 +98,9 @@ public class InsertRowPlan extends InsertPlan { } } - public InsertRowPlan(TSRecord tsRecord) { + public InsertRowPlan(TSRecord tsRecord) throws IllegalPathException { super(OperatorType.INSERT); - this.deviceId = tsRecord.deviceId; + this.deviceId = new PartialPath(tsRecord.deviceId); this.time = tsRecord.time; this.measurements = new String[tsRecord.dataPointList.size()]; this.schemas = new MeasurementSchema[tsRecord.dataPointList.size()]; @@ -112,7 +115,7 @@ public class InsertRowPlan extends InsertPlan { } } - public InsertRowPlan(String deviceId, long insertTime, String[] measurementList, + public InsertRowPlan(PartialPath deviceId, long insertTime, String[] measurementList, TSDataType[] dataTypes, Object[] insertValues) { super(Operator.OperatorType.INSERT); this.time = insertTime; @@ -122,7 +125,7 @@ public class InsertRowPlan extends InsertPlan { this.values = insertValues; } - public InsertRowPlan(String deviceId, long insertTime, String[] measurementList, + public InsertRowPlan(PartialPath deviceId, long insertTime, String[] measurementList, String[] insertValues) { super(Operator.OperatorType.INSERT); this.time = insertTime; @@ -165,7 +168,7 @@ public class InsertRowPlan extends InsertPlan { markFailedMeasurementInsertion(i); } else { throw new QueryProcessException(new PathNotExistException( - deviceId + IoTDBConstant.PATH_SEPARATOR + measurements[i])); + deviceId.toString() + IoTDBConstant.PATH_SEPARATOR + measurements[i])); } continue; } @@ -193,11 +196,13 @@ public class InsertRowPlan extends InsertPlan { } @Override - public List<Path> getPaths() { - List<Path> ret = new ArrayList<>(); - + public List<PartialPath> getPaths() { + List<PartialPath> ret = new ArrayList<>(); for (String m : measurements) { - ret.add(new Path(deviceId, m)); + String[] temp = {m}; + PartialPath fullPath = deviceId.clone(); + fullPath.concatPath(temp); + ret.add(fullPath); } return ret; } @@ -235,7 +240,7 @@ public class InsertRowPlan extends InsertPlan { stream.writeByte((byte) type); stream.writeLong(time); - putString(stream, deviceId); + putString(stream, deviceId.toString()); stream.writeInt( measurements.length - (failedMeasurements == null ? 0 : failedMeasurements.size())); @@ -373,7 +378,7 @@ public class InsertRowPlan extends InsertPlan { buffer.put((byte) type); buffer.putLong(time); - putString(buffer, deviceId); + putString(buffer, deviceId.toString()); buffer .putInt(measurements.length - (failedMeasurements == null ? 0 : failedMeasurements.size())); @@ -395,9 +400,9 @@ public class InsertRowPlan extends InsertPlan { } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { this.time = buffer.getLong(); - this.deviceId = readString(buffer); + this.deviceId = new PartialPath(readString(buffer)); int measurementSize = buffer.getInt(); diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java index 58b4c13..d15af98 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb.db.qp.physical.crud; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -29,7 +30,7 @@ import java.util.Map; public abstract class QueryPlan extends PhysicalPlan { - protected List<Path> paths = null; + protected List<PartialPath> paths = null; private List<TSDataType> dataTypes = null; private boolean alignByTime = true; // for disable align sql @@ -48,11 +49,11 @@ public abstract class QueryPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return paths; } - public void setPaths(List<Path> paths) { + public void setPaths(List<PartialPath> paths) { this.paths = paths; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AlterTimeSeriesPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AlterTimeSeriesPlan.java index e8020e3..818fde4 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AlterTimeSeriesPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AlterTimeSeriesPlan.java @@ -22,6 +22,7 @@ package org.apache.iotdb.db.qp.physical.sys; import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.logical.sys.AlterTimeSeriesOperator; import org.apache.iotdb.db.qp.logical.sys.AlterTimeSeriesOperator.AlterType; @@ -30,7 +31,7 @@ import org.apache.iotdb.tsfile.read.common.Path; public class AlterTimeSeriesPlan extends PhysicalPlan { - private final Path path; + private final PartialPath path; private final AlterTimeSeriesOperator.AlterType alterType; @@ -46,7 +47,7 @@ public class AlterTimeSeriesPlan extends PhysicalPlan { private final Map<String, String> tagsMap; private final Map<String, String> attributesMap; - public AlterTimeSeriesPlan(Path path, AlterType alterType, Map<String, String> alterMap, + public AlterTimeSeriesPlan(PartialPath path, AlterType alterType, Map<String, String> alterMap, String alias, Map<String, String> tagsMap, Map<String, String> attributesMap) { super(false, Operator.OperatorType.ALTER_TIMESERIES); this.path = path; @@ -57,7 +58,7 @@ public class AlterTimeSeriesPlan extends PhysicalPlan { this.attributesMap = attributesMap; } - public Path getPath() { + public PartialPath getPath() { return path; } @@ -82,7 +83,7 @@ public class AlterTimeSeriesPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return Collections.singletonList(path); } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AuthorPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AuthorPlan.java index 845b600..7377a5d 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AuthorPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AuthorPlan.java @@ -28,6 +28,9 @@ import java.util.Objects; import java.util.Set; import org.apache.iotdb.db.auth.AuthException; import org.apache.iotdb.db.auth.entity.PrivilegeType; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.MetaUtils; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.qp.logical.sys.AuthorOperator; @@ -43,7 +46,7 @@ public class AuthorPlan extends PhysicalPlan { private String password; private String newPassword; private Set<Integer> permissions; - private Path nodeName; + private PartialPath nodeName; /** * AuthorPlan Constructor. @@ -59,7 +62,7 @@ public class AuthorPlan extends PhysicalPlan { */ public AuthorPlan(AuthorOperator.AuthorType authorType, String userName, String roleName, String password, - String newPassword, String[] authorizationList, Path nodeName) throws AuthException { + String newPassword, String[] authorizationList, PartialPath nodeName) throws AuthException { super(false, Operator.OperatorType.AUTHOR); this.authorType = authorType; this.userName = userName; @@ -210,7 +213,7 @@ public class AuthorPlan extends PhysicalPlan { this.permissions = permissions; } - public Path getNodeName() { + public PartialPath getNodeName() { return nodeName; } @@ -246,8 +249,8 @@ public class AuthorPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { - List<Path> ret = new ArrayList<>(); + public List<PartialPath> getPaths() { + List<PartialPath> ret = new ArrayList<>(); if (nodeName != null) { ret.add(nodeName); } @@ -300,7 +303,7 @@ public class AuthorPlan extends PhysicalPlan { if (nodeName == null) { putString(stream, null); } else { - putString(stream, nodeName.getFullPath()); + putString(stream, nodeName.toString()); } } @@ -326,12 +329,12 @@ public class AuthorPlan extends PhysicalPlan { if (nodeName == null) { putString(buffer, null); } else { - putString(buffer, nodeName.getFullPath()); + putString(buffer, nodeName.toString()); } } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { this.authorType = AuthorType.values()[buffer.getInt()]; this.userName = readString(buffer); this.roleName = readString(buffer); @@ -351,7 +354,7 @@ public class AuthorPlan extends PhysicalPlan { if (nodeNameStr == null) { this.nodeName = null; } else { - this.nodeName = new Path(nodeNameStr); + this.nodeName = new PartialPath(nodeNameStr); } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CountPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CountPlan.java index b1851ad..e1ef740 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CountPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CountPlan.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb.db.qp.physical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; /** @@ -28,15 +29,15 @@ import org.apache.iotdb.tsfile.read.common.Path; */ public class CountPlan extends ShowPlan { - private Path path; + private PartialPath path; private int level; - public CountPlan(ShowContentType showContentType, Path path) { + public CountPlan(ShowContentType showContentType, PartialPath path) { super(showContentType); this.path = path; } - public CountPlan(ShowContentType showContentType, Path path, int level) { + public CountPlan(ShowContentType showContentType, PartialPath path, int level) { super(showContentType); this.path = path; this.level = level; @@ -46,7 +47,7 @@ public class CountPlan extends ShowPlan { return level; } - public Path getPath() { + public PartialPath getPath() { return path; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTimeSeriesPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTimeSeriesPlan.java index 98b80dd..d5f99a1 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTimeSeriesPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTimeSeriesPlan.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; @@ -35,7 +37,7 @@ import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; public class CreateTimeSeriesPlan extends PhysicalPlan { - private Path path; + private PartialPath path; private TSDataType dataType; private TSEncoding encoding; private CompressionType compressor; @@ -49,7 +51,7 @@ public class CreateTimeSeriesPlan extends PhysicalPlan { canBeSplit = false; } - public CreateTimeSeriesPlan(Path path, TSDataType dataType, TSEncoding encoding, + public CreateTimeSeriesPlan(PartialPath path, TSDataType dataType, TSEncoding encoding, CompressionType compressor, Map<String, String> props, Map<String, String> tags, Map<String, String> attributes, String alias) { super(false, Operator.OperatorType.CREATE_TIMESERIES); @@ -64,11 +66,11 @@ public class CreateTimeSeriesPlan extends PhysicalPlan { canBeSplit = false; } - public Path getPath() { + public PartialPath getPath() { return path; } - public void setPath(Path path) { + public void setPath(PartialPath path) { this.path = path; } @@ -135,14 +137,14 @@ public class CreateTimeSeriesPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return Collections.singletonList(path); } @Override public void serialize(DataOutputStream stream) throws IOException { stream.writeByte((byte) PhysicalPlanType.CREATE_TIMESERIES.ordinal()); - byte[] bytes = path.getFullPath().getBytes(); + byte[] bytes = path.toString().getBytes(); stream.writeInt(bytes.length); stream.write(bytes); stream.write(dataType.ordinal()); @@ -183,11 +185,11 @@ public class CreateTimeSeriesPlan extends PhysicalPlan { } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { int length = buffer.getInt(); byte[] bytes = new byte[length]; buffer.get(bytes); - path = new Path(new String(bytes)); + path = new PartialPath(new String(bytes)); dataType = TSDataType.values()[buffer.get()]; encoding = TSEncoding.values()[buffer.get()]; compressor = CompressionType.values()[buffer.get()]; diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteStorageGroupPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteStorageGroupPlan.java index bb33050..11ad735 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteStorageGroupPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteStorageGroupPlan.java @@ -23,16 +23,16 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; - +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; -import org.apache.iotdb.tsfile.read.common.Path; public class DeleteStorageGroupPlan extends PhysicalPlan { - private List<Path> deletePathList; + private List<PartialPath> deletePathList; - public DeleteStorageGroupPlan (List<Path> deletePathList) { + public DeleteStorageGroupPlan (List<PartialPath> deletePathList) { super(false, Operator.OperatorType.DELETE_STORAGE_GROUP); this.deletePathList = deletePathList; } @@ -42,7 +42,7 @@ public class DeleteStorageGroupPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return deletePathList; } @@ -51,8 +51,8 @@ public class DeleteStorageGroupPlan extends PhysicalPlan { int type = PhysicalPlan.PhysicalPlanType.DELETE_STORAGE_GROUP.ordinal(); stream.writeByte((byte) type); stream.writeInt(this.getPaths().size()); - for (Path path : this.getPaths()) { - putString(stream, path.getFullPath()); + for (PartialPath path : this.getPaths()) { + putString(stream, path.toString()); } } @@ -61,17 +61,17 @@ public class DeleteStorageGroupPlan extends PhysicalPlan { int type = PhysicalPlanType.DELETE_STORAGE_GROUP.ordinal(); buffer.put((byte) type); buffer.putInt(this.getPaths().size()); - for (Path path : this.getPaths()) { - putString(buffer, path.getFullPath()); + for (PartialPath path : this.getPaths()) { + putString(buffer, path.toString()); } } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { int pathNum = buffer.getInt(); this.deletePathList = new ArrayList<>(); for (int i = 0; i < pathNum; i++) { - deletePathList.add(new Path(readString(buffer))); + deletePathList.add(new PartialPath(readString(buffer))); } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteTimeSeriesPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteTimeSeriesPlan.java index 80da6d5..511e0c9 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteTimeSeriesPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/DeleteTimeSeriesPlan.java @@ -23,15 +23,16 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; -import org.apache.iotdb.tsfile.read.common.Path; public class DeleteTimeSeriesPlan extends PhysicalPlan { - private List<Path> deletePathList; + private List<PartialPath> deletePathList; - public DeleteTimeSeriesPlan(List<Path> deletePathList) { + public DeleteTimeSeriesPlan(List<PartialPath> deletePathList) { super(false, Operator.OperatorType.DELETE_TIMESERIES); this.deletePathList = deletePathList; } @@ -41,7 +42,7 @@ public class DeleteTimeSeriesPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return deletePathList; } @@ -50,8 +51,8 @@ public class DeleteTimeSeriesPlan extends PhysicalPlan { int type = PhysicalPlanType.DELETE_TIMESERIES.ordinal(); stream.writeByte((byte) type); stream.writeInt(deletePathList.size()); - for (Path path : deletePathList) { - putString(stream, path.getFullPath()); + for (PartialPath path : deletePathList) { + putString(stream, path.toString()); } } @@ -60,17 +61,17 @@ public class DeleteTimeSeriesPlan extends PhysicalPlan { int type = PhysicalPlanType.DELETE_TIMESERIES.ordinal(); buffer.put((byte) type); buffer.putInt(deletePathList.size()); - for (Path path : deletePathList) { - putString(buffer, path.getFullPath()); + for (PartialPath path : deletePathList) { + putString(buffer, path.toString()); } } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { int pathNumber = buffer.getInt(); deletePathList = new ArrayList<>(); for (int i = 0; i < pathNumber; i++) { - deletePathList.add(new Path(readString(buffer))); + deletePathList.add(new PartialPath(readString(buffer))); } } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/FlushPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/FlushPlan.java index d21c26e..911d348 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/FlushPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/FlushPlan.java @@ -19,12 +19,12 @@ package org.apache.iotdb.db.qp.physical.sys; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.qp.physical.PhysicalPlan; -import org.apache.iotdb.tsfile.read.common.Path; public class FlushPlan extends PhysicalPlan { - private List<Path> storeGroups; + private List<PartialPath> storeGroups; public Boolean isSeq() { return isSeq; @@ -32,14 +32,14 @@ public class FlushPlan extends PhysicalPlan { private Boolean isSeq; - public FlushPlan(Boolean isSeq, List<Path> storeGroups) { + public FlushPlan(Boolean isSeq, List<PartialPath> storeGroups) { super(false, OperatorType.FLUSH); this.storeGroups = storeGroups; this.isSeq = isSeq; } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return storeGroups; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetStorageGroupPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetStorageGroupPlan.java index 42f06ea..437fd69 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetStorageGroupPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetStorageGroupPlan.java @@ -24,33 +24,36 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.MetaUtils; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.tsfile.read.common.Path; public class SetStorageGroupPlan extends PhysicalPlan { - private Path path; + private PartialPath path; public SetStorageGroupPlan() { super(false, Operator.OperatorType.SET_STORAGE_GROUP); } - public SetStorageGroupPlan(Path path) { + public SetStorageGroupPlan(PartialPath path) { super(false, Operator.OperatorType.SET_STORAGE_GROUP); this.path = path; } - public Path getPath() { + public PartialPath getPath() { return path; } - public void setPath(Path path) { + public void setPath(PartialPath path) { this.path = path; } @Override - public List<Path> getPaths() { - List<Path> ret = new ArrayList<>(); + public List<PartialPath> getPaths() { + List<PartialPath> ret = new ArrayList<>(); if (path != null) { ret.add(path); } @@ -60,17 +63,17 @@ public class SetStorageGroupPlan extends PhysicalPlan { @Override public void serialize(DataOutputStream stream) throws IOException { stream.write((byte) PhysicalPlanType.SET_STORAGE_GROUP.ordinal()); - byte[] fullPathBytes = path.getFullPath().getBytes(); + byte[] fullPathBytes = path.toString().getBytes(); stream.writeInt(fullPathBytes.length); stream.write(fullPathBytes); } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { int length = buffer.getInt(); byte[] fullPathBytes = new byte[length]; buffer.get(fullPathBytes); - path = new Path(new String(fullPathBytes)); + path = new PartialPath(new String(fullPathBytes)); } @Override diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetTTLPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetTTLPlan.java index 2600830..8d16e1d 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetTTLPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/SetTTLPlan.java @@ -24,33 +24,34 @@ import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.qp.physical.PhysicalPlan; -import org.apache.iotdb.tsfile.read.common.Path; public class SetTTLPlan extends PhysicalPlan { - private String storageGroup; + private PartialPath storageGroup; private long dataTTL; public SetTTLPlan() { super(false, OperatorType.TTL); } - public SetTTLPlan(String storageGroup, long dataTTL) { + public SetTTLPlan(PartialPath storageGroup, long dataTTL) { // set TTL super(false, OperatorType.TTL); this.storageGroup = storageGroup; this.dataTTL = dataTTL; } - public SetTTLPlan(String storageGroup) { + public SetTTLPlan(PartialPath storageGroup) { // unset TTL this(storageGroup, Long.MAX_VALUE); } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return null; } @@ -59,7 +60,7 @@ public class SetTTLPlan extends PhysicalPlan { int type = PhysicalPlanType.TTL.ordinal(); stream.writeByte((byte) type); stream.writeLong(dataTTL); - putString(stream, storageGroup); + putString(stream, storageGroup.toString()); } @Override @@ -67,20 +68,20 @@ public class SetTTLPlan extends PhysicalPlan { int type = PhysicalPlanType.TTL.ordinal(); buffer.put((byte) type); buffer.putLong(dataTTL); - putString(buffer, storageGroup); + putString(buffer, storageGroup.toString()); } @Override - public void deserialize(ByteBuffer buffer) { + public void deserialize(ByteBuffer buffer) throws IllegalPathException { this.dataTTL = buffer.getLong(); - this.storageGroup = readString(buffer); + this.storageGroup = new PartialPath(readString(buffer)); } - public String getStorageGroup() { + public PartialPath getStorageGroup() { return storageGroup; } - public void setStorageGroup(String storageGroup) { + public void setStorageGroup(PartialPath storageGroup) { this.storageGroup = storageGroup; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowChildPathsPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowChildPathsPlan.java index 60c41ec..fe1086d 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowChildPathsPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowChildPathsPlan.java @@ -19,20 +19,21 @@ */ package org.apache.iotdb.db.qp.physical.sys; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; public class ShowChildPathsPlan extends ShowPlan { // the path could be a prefix path with wildcard - private Path prefixPath; + private PartialPath prefixPath; - public ShowChildPathsPlan(ShowContentType showContentType, Path prefixPath) { + public ShowChildPathsPlan(ShowContentType showContentType, PartialPath prefixPath) { super(showContentType); this.prefixPath = prefixPath; canBeSplit = false; } - public Path getPath() { + public PartialPath getPath() { return this.prefixPath; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowDevicesPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowDevicesPlan.java index 2a0f4bc..8da6b96 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowDevicesPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowDevicesPlan.java @@ -18,17 +18,17 @@ */ package org.apache.iotdb.db.qp.physical.sys; -import org.apache.iotdb.tsfile.read.common.Path; +import org.apache.iotdb.db.metadata.PartialPath; public class ShowDevicesPlan extends ShowPlan{ - private Path path; + private PartialPath path; - public ShowDevicesPlan(ShowContentType showContentType, Path path) { + public ShowDevicesPlan(ShowContentType showContentType, PartialPath path) { super(showContentType); this.path = path; } - public Path getPath() { + public PartialPath getPath() { return this.path; } } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowPlan.java index bde812a..55df455 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowPlan.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.qp.physical.sys; import java.util.List; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.tsfile.read.common.Path; @@ -35,7 +36,7 @@ public class ShowPlan extends PhysicalPlan { } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return null; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTTLPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTTLPlan.java index f5ca8ab..1acfc7b 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTTLPlan.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/ShowTTLPlan.java @@ -19,23 +19,23 @@ package org.apache.iotdb.db.qp.physical.sys; import java.util.List; -import org.apache.iotdb.tsfile.read.common.Path; +import org.apache.iotdb.db.metadata.PartialPath; public class ShowTTLPlan extends ShowPlan { - private List<String> storageGroups; + private List<PartialPath> storageGroups; - public ShowTTLPlan(List<String> storageGroups) { + public ShowTTLPlan(List<PartialPath> storageGroups) { super(ShowContentType.TTL); this.storageGroups = storageGroups; } @Override - public List<Path> getPaths() { + public List<PartialPath> getPaths() { return null; } - public List<String> getStorageGroups() { + public List<PartialPath> getStorageGroups() { return storageGroups; } } \ No newline at end of file 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 78bf51c..5f98da9 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 @@ -21,13 +21,15 @@ package org.apache.iotdb.db.qp.physical.sys; import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.tsfile.read.common.Path; public class ShowTimeSeriesPlan extends ShowPlan { // path can be root, root.* root.*.*.a etc.. if the wildcard is not at the tail, then each // * wildcard can only match one level, otherwise it can match to the tail. - private Path path; + private PartialPath path; private boolean isContains; private String key; private String value; @@ -38,12 +40,12 @@ public class ShowTimeSeriesPlan extends ShowPlan { private boolean hasLimit; - public ShowTimeSeriesPlan(Path path) { + public ShowTimeSeriesPlan(PartialPath path) { super(ShowContentType.TIMESERIES); this.path = path; } - public ShowTimeSeriesPlan(Path path, boolean isContains, String key, String value, int limit, + public ShowTimeSeriesPlan(PartialPath path, boolean isContains, String key, String value, int limit, int offset, boolean orderByHeat) { super(ShowContentType.TIMESERIES); this.path = path; @@ -59,7 +61,7 @@ public class ShowTimeSeriesPlan extends ShowPlan { super(ShowContentType.TIMESERIES); } - public Path getPath() { + public PartialPath getPath() { return this.path; } @@ -111,7 +113,7 @@ public class ShowTimeSeriesPlan extends ShowPlan { public void serialize(DataOutputStream outputStream) throws IOException { outputStream.write(PhysicalPlanType.SHOW_TIMESERIES.ordinal()); - putString(outputStream, path.getFullPath()); + putString(outputStream, path.toString()); outputStream.writeBoolean(isContains); putString(outputStream, key); putString(outputStream, value); @@ -122,8 +124,8 @@ public class ShowTimeSeriesPlan extends ShowPlan { } @Override - public void deserialize(ByteBuffer buffer) { - path = new Path(readString(buffer)); + public void deserialize(ByteBuffer buffer) throws IllegalPathException { + path = new PartialPath(readString(buffer)); isContains = buffer.get() == 1; key = readString(buffer); value = readString(buffer); 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 6ad6202..96fb65b 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 @@ -18,6 +18,10 @@ */ package org.apache.iotdb.db.qp.strategy; +import static org.apache.iotdb.db.qp.constant.SQLConstant.SINGLE_ROOT_ARRAY; +import static org.apache.iotdb.db.qp.constant.SQLConstant.SINGLE_TIME_ARRAY; +import static org.apache.iotdb.db.qp.constant.SQLConstant.TIME_PATH; + import java.io.File; import java.time.ZoneId; import java.util.ArrayList; @@ -30,6 +34,7 @@ import java.util.Set; import org.antlr.v4.runtime.tree.TerminalNode; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.runtime.SQLParserException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.DatetimeUtils; import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.db.qp.logical.RootOperator; @@ -154,6 +159,7 @@ import org.apache.iotdb.db.qp.strategy.SqlBaseParser.ShowVersionContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.ShowWhereClauseContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SlimitClauseContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SoffsetClauseContext; +import org.apache.iotdb.db.qp.strategy.SqlBaseParser.StringLiteralContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SuffixPathContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.TagClauseContext; import org.apache.iotdb.db.qp.strategy.SqlBaseParser.TimeIntervalContext; @@ -171,7 +177,6 @@ import org.apache.iotdb.tsfile.common.constant.TsFileConstant; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; -import org.apache.iotdb.tsfile.read.common.Path; import org.apache.iotdb.tsfile.utils.Pair; import org.apache.iotdb.tsfile.utils.StringContainer; @@ -203,7 +208,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { public void enterCountTimeseries(CountTimeseriesContext ctx) { super.enterCountTimeseries(ctx); PrefixPathContext pathContext = ctx.prefixPath(); - Path path = (pathContext != null ? parsePrefixPath(pathContext) : new Path(SQLConstant.ROOT)); + PartialPath path = (pathContext != null ? parsePrefixPath(pathContext) : new PartialPath(SINGLE_ROOT_ARRAY)); if (ctx.INT() != null) { initializedOperator = new CountOperator(SQLConstant.TOK_COUNT_NODE_TIMESERIES, path, Integer.parseInt(ctx.INT().getText())); @@ -221,7 +226,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { flushOperator.setSeq(Boolean.parseBoolean(ctx.booleanClause().getText())); } if (ctx.prefixPath(0) != null) { - List<Path> storageGroups = new ArrayList<>(); + List<PartialPath> storageGroups = new ArrayList<>(); for (PrefixPathContext prefixPathContext : ctx.prefixPath()) { storageGroups.add(parsePrefixPath(prefixPathContext)); } @@ -276,7 +281,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { parsePrefixPath(ctx.prefixPath())); } else { initializedOperator = new ShowDevicesOperator(SQLConstant.TOK_DEVICES, - new Path(SQLConstant.ROOT)); + new PartialPath(SINGLE_ROOT_ARRAY)); } } @@ -288,7 +293,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { parsePrefixPath(ctx.prefixPath())); } else { initializedOperator = new ShowChildPathsOperator(SQLConstant.TOK_CHILD_PATHS, - new Path(SQLConstant.ROOT)); + new PartialPath(SINGLE_ROOT_ARRAY)); } } @@ -304,20 +309,20 @@ public class LogicalGenerator extends SqlBaseBaseListener { if (ctx.autoCreateSchema() != null) { if (ctx.autoCreateSchema().INT() != null) { initializedOperator = new LoadFilesOperator( - new File(removeStringQuote(ctx.STRING_LITERAL().getText())), + new File(removeStringQuote(ctx.stringLiteral().getText())), Boolean.parseBoolean(ctx.autoCreateSchema().booleanClause().getText()), Integer.parseInt(ctx.autoCreateSchema().INT().getText()) ); } else { initializedOperator = new LoadFilesOperator( - new File(removeStringQuote(ctx.STRING_LITERAL().getText())), + new File(removeStringQuote(ctx.stringLiteral().getText())), Boolean.parseBoolean(ctx.autoCreateSchema().booleanClause().getText()), IoTDBDescriptor.getInstance().getConfig().getDefaultStorageGroupLevel() ); } } else { initializedOperator = new LoadFilesOperator( - new File(removeStringQuote(ctx.STRING_LITERAL().getText())), + new File(removeStringQuote(ctx.stringLiteral().getText())), true, IoTDBDescriptor.getInstance().getConfig().getDefaultStorageGroupLevel() ); @@ -328,15 +333,15 @@ public class LogicalGenerator extends SqlBaseBaseListener { public void enterMoveFile(MoveFileContext ctx) { super.enterMoveFile(ctx); initializedOperator = new MoveFileOperator( - new File(removeStringQuote(ctx.STRING_LITERAL(0).getText())), - new File(removeStringQuote(ctx.STRING_LITERAL(1).getText()))); + new File(removeStringQuote(ctx.stringLiteral(0).getText())), + new File(removeStringQuote(ctx.stringLiteral(1).getText()))); } @Override public void enterRemoveFile(RemoveFileContext ctx) { super.enterRemoveFile(ctx); initializedOperator = new RemoveFileOperator( - new File(removeStringQuote(ctx.STRING_LITERAL().getText()))); + new File(removeStringQuote(ctx.stringLiteral().getText()))); } @Override @@ -376,7 +381,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { initializedOperator = new ShowTimeSeriesOperator(SQLConstant.TOK_TIMESERIES, parsePrefixPath(ctx.prefixPath()), orderByHeat); } else { - initializedOperator = new ShowTimeSeriesOperator(SQLConstant.TOK_TIMESERIES, new Path("root"), + initializedOperator = new ShowTimeSeriesOperator(SQLConstant.TOK_TIMESERIES, new PartialPath(SINGLE_ROOT_ARRAY), orderByHeat); } } @@ -436,7 +441,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { if (ctx.property(0) != null) { for (PropertyContext property : tagsList) { String value; - if (property.propertyValue().STRING_LITERAL() != null) { + if (property.propertyValue().stringLiteral() != null) { value = removeStringQuote(property.propertyValue().getText()); } else { value = property.propertyValue().getText(); @@ -585,7 +590,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { throw new SQLParserException("data load command: child count < 3\n"); } - String csvPath = ctx.STRING_LITERAL().getText(); + String csvPath = ctx.stringLiteral().getText(); StringContainer sc = new StringContainer(TsFileConstant.PATH_SEPARATOR); List<NodeNameContext> nodeNames = ctx.prefixPath().nodeName(); sc.addTail(ctx.prefixPath().ROOT().getText()); @@ -703,7 +708,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { public void enterSetTTLStatement(SetTTLStatementContext ctx) { super.enterSetTTLStatement(ctx); SetTTLOperator operator = new SetTTLOperator(SQLConstant.TOK_SET); - operator.setStorageGroup(parsePrefixPath(ctx.prefixPath()).getFullPath()); + operator.setStorageGroup(parsePrefixPath(ctx.prefixPath())); operator.setDataTTL(Long.parseLong(ctx.INT().getText())); initializedOperator = operator; operatorType = SQLConstant.TOK_SET; @@ -713,7 +718,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { public void enterUnsetTTLStatement(UnsetTTLStatementContext ctx) { super.enterUnsetTTLStatement(ctx); SetTTLOperator operator = new SetTTLOperator(SQLConstant.TOK_UNSET); - operator.setStorageGroup(parsePrefixPath(ctx.prefixPath()).getFullPath()); + operator.setStorageGroup(parsePrefixPath(ctx.prefixPath())); initializedOperator = operator; operatorType = SQLConstant.TOK_UNSET; } @@ -721,10 +726,10 @@ public class LogicalGenerator extends SqlBaseBaseListener { @Override public void enterShowTTLStatement(ShowTTLStatementContext ctx) { super.enterShowTTLStatement(ctx); - List<String> storageGroups = new ArrayList<>(); + List<PartialPath> storageGroups = new ArrayList<>(); List<PrefixPathContext> prefixPathList = ctx.prefixPath(); for (PrefixPathContext prefixPath : prefixPathList) { - storageGroups.add(parsePrefixPath(prefixPath).getFullPath()); + storageGroups.add(parsePrefixPath(prefixPath)); } initializedOperator = new ShowTTLOperator(storageGroups); } @@ -732,14 +737,14 @@ public class LogicalGenerator extends SqlBaseBaseListener { @Override public void enterShowAllTTLStatement(ShowAllTTLStatementContext ctx) { super.enterShowAllTTLStatement(ctx); - List<String> storageGroups = new ArrayList<>(); + List<PartialPath> storageGroups = new ArrayList<>(); initializedOperator = new ShowTTLOperator(storageGroups); } private String[] parsePrivilege(PrivilegesContext ctx) { - List<TerminalNode> privilegeList = ctx.STRING_LITERAL(); + List<StringLiteralContext> privilegeList = ctx.stringLiteral(); List<String> privileges = new ArrayList<>(); - for (TerminalNode privilege : privilegeList) { + for (StringLiteralContext privilege : privilegeList) { privileges.add(removeStringQuote(privilege.getText())); } return privileges.toArray(new String[0]); @@ -758,7 +763,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { @Override public void enterDeleteTimeseries(DeleteTimeseriesContext ctx) { super.enterDeleteTimeseries(ctx); - List<Path> deletePaths = new ArrayList<>(); + List<PartialPath> deletePaths = new ArrayList<>(); List<PrefixPathContext> prefixPaths = ctx.prefixPath(); for (PrefixPathContext prefixPath : prefixPaths) { deletePaths.add(parsePrefixPath(prefixPath)); @@ -775,7 +780,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { super.enterSetStorageGroup(ctx); SetStorageGroupOperator setStorageGroupOperator = new SetStorageGroupOperator( SQLConstant.TOK_METADATA_SET_FILE_LEVEL); - Path path = parseFullPath(ctx.fullPath()); + PartialPath path = parsePrefixPath(ctx.prefixPath()); setStorageGroupOperator.setPath(path); initializedOperator = setStorageGroupOperator; operatorType = SQLConstant.TOK_METADATA_SET_FILE_LEVEL; @@ -784,10 +789,10 @@ public class LogicalGenerator extends SqlBaseBaseListener { @Override public void enterDeleteStorageGroup(DeleteStorageGroupContext ctx) { super.enterDeleteStorageGroup(ctx); - List<Path> deletePaths = new ArrayList<>(); - List<FullPathContext> fullPaths = ctx.fullPath(); - for (FullPathContext fullPath : fullPaths) { - deletePaths.add(parseFullPath(fullPath)); + List<PartialPath> deletePaths = new ArrayList<>(); + List<PrefixPathContext> prefixPaths = ctx.prefixPath(); + for (PrefixPathContext prefixPath : prefixPaths) { + deletePaths.add(parsePrefixPath(prefixPath)); } DeleteStorageGroupOperator deleteStorageGroupOperator = new DeleteStorageGroupOperator( SQLConstant.TOK_METADATA_DELETE_FILE_LEVEL); @@ -804,7 +809,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { selectOp = new SelectOperator(SQLConstant.TOK_SELECT); List<PrefixPathContext> prefixPaths = ctx.prefixPath(); for (PrefixPathContext prefixPath : prefixPaths) { - Path path = parsePrefixPath(prefixPath); + PartialPath path = parsePrefixPath(prefixPath); selectOp.addSelectPath(path); } deleteDataOp.setSelectOperator(selectOp); @@ -1109,17 +1114,18 @@ public class LogicalGenerator extends SqlBaseBaseListener { initializedOperator = insertOp; } - private Path parseFullPath(FullPathContext ctx) { + private PartialPath parseFullPath(FullPathContext ctx) { List<NodeNameWithoutStarContext> nodeNamesWithoutStar = ctx.nodeNameWithoutStar(); - List<String> path = new ArrayList<>(); + String[] path = new String[nodeNamesWithoutStar.size() + 1]; + int i = 0; if (ctx.ROOT() != null) { - path.add(ctx.ROOT().getText()); + path[0] = ctx.ROOT().getText(); } for (NodeNameWithoutStarContext nodeNameWithoutStar : nodeNamesWithoutStar) { - path.add(nodeNameWithoutStar.getText()); + i++; + path[i] = nodeNameWithoutStar.getText(); } - return new Path( - new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR)); + return new PartialPath(path); } @Override @@ -1186,7 +1192,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { Map<String, String> tags = new HashMap<>(property2.size()); if (property3 != null) { for (PropertyContext property : property2) { - if (property.propertyValue().STRING_LITERAL() != null) { + if (property.propertyValue().stringLiteral() != null) { value = removeStringQuote(property.propertyValue().getText()); } else { value = property.propertyValue().getText(); @@ -1203,7 +1209,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { insertOp = new InsertOperator(SQLConstant.TOK_INSERT); selectOp = new SelectOperator(SQLConstant.TOK_SELECT); operatorType = SQLConstant.TOK_INSERT; - selectOp.addSelectPath(parseFullPath(ctx.fullPath())); + selectOp.addSelectPath(parsePrefixPath(ctx.prefixPath())); insertOp.setSelectOperator(selectOp); } @@ -1240,7 +1246,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { FromOperator fromOp = new FromOperator(SQLConstant.TOK_FROM); List<PrefixPathContext> prefixFromPaths = ctx.prefixPath(); for (PrefixPathContext prefixFromPath : prefixFromPaths) { - Path path = parsePrefixPath(prefixFromPath); + PartialPath path = parsePrefixPath(prefixFromPath); fromOp.addPrefixTablePath(path); } queryOp.setFromOperator(fromOp); @@ -1252,7 +1258,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { selectOp = new SelectOperator(SQLConstant.TOK_SELECT); List<FunctionCallContext> functionCallContextList = ctx.functionCall(); for (FunctionCallContext functionCallContext : functionCallContextList) { - Path path = parseSuffixPath(functionCallContext.suffixPath()); + PartialPath path = parseSuffixPath(functionCallContext.suffixPath()); selectOp.addClusterPath(path, functionCallContext.functionName().getText()); } queryOp.setSelectOperator(selectOp); @@ -1264,7 +1270,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { selectOp = new SelectOperator(SQLConstant.TOK_SELECT); List<SuffixPathContext> suffixPaths = ctx.suffixPath(); for (SuffixPathContext suffixPath : suffixPaths) { - Path path = parseSuffixPath(suffixPath); + PartialPath path = parseSuffixPath(suffixPath); selectOp.addSelectPath(path); } queryOp.setSelectOperator(selectOp); @@ -1278,7 +1284,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { LastClauseContext lastClauseContext = ctx.lastClause(); List<SuffixPathContext> suffixPaths = lastClauseContext.suffixPath(); for (SuffixPathContext suffixPath : suffixPaths) { - Path path = parseSuffixPath(suffixPath); + PartialPath path = parseSuffixPath(suffixPath); selectOp.addSelectPath(path); } queryOp.setSelectOperator(selectOp); @@ -1293,15 +1299,16 @@ public class LogicalGenerator extends SqlBaseBaseListener { } - private Path parsePrefixPath(PrefixPathContext ctx) { + private PartialPath parsePrefixPath(PrefixPathContext ctx) { List<NodeNameContext> nodeNames = ctx.nodeName(); - List<String> path = new ArrayList<>(); - path.add(ctx.ROOT().getText()); + String[] path = new String[nodeNames.size() + 1]; + int i = 0; + path[i] = ctx.ROOT().getText(); for (NodeNameContext nodeName : nodeNames) { - path.add(nodeName.getText()); + i++; + path[i] = nodeName.getText(); } - return new Path( - new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR)); + return new PartialPath(path); } /** @@ -1377,7 +1384,7 @@ public class LogicalGenerator extends SqlBaseBaseListener { operator.setKey(ctx.property().ID().getText()); } String value; - if (propertyValueContext.STRING_LITERAL() != null) { + if (propertyValueContext.stringLiteral() != null) { value = removeStringQuote(propertyValueContext.getText()); } else { value = propertyValueContext.getText(); @@ -1438,9 +1445,9 @@ public class LogicalGenerator extends SqlBaseBaseListener { } else if (ctx.LR_BRACKET() != null && ctx.OPERATOR_NOT() == null) { return parseOrExpression(ctx.orExpression()); } else { - Path path = null; + PartialPath path = null; if (ctx.TIME() != null || ctx.TIMESTAMP() != null) { - path = new Path(SQLConstant.RESERVED_TIME); + path = new PartialPath(SINGLE_TIME_ARRAY); } if (ctx.fullPath() != null) { path = parseFullPath(ctx.fullPath()); @@ -1459,12 +1466,12 @@ public class LogicalGenerator extends SqlBaseBaseListener { } } - private FilterOperator parseInOperator(InClauseContext ctx, Path path) { + private FilterOperator parseInOperator(InClauseContext ctx, PartialPath path) { Set<String> values = new HashSet<>(); boolean not = ctx.OPERATOR_NOT() != null; for (ConstantContext constant : ctx.constant()) { if (constant.dateExpression() != null) { - if (!path.equals(SQLConstant.RESERVED_TIME)) { + if (!path.equals(TIME_PATH)) { throw new SQLParserException(path.toString(), "Date can only be used to time"); } values.add(Long.toString(parseDateExpression(constant.dateExpression()))); @@ -1475,10 +1482,10 @@ public class LogicalGenerator extends SqlBaseBaseListener { return new InOperator(ctx.OPERATOR_IN().getSymbol().getType(), path, not, values); } - private FilterOperator parseBasicFunctionOperator(PredicateContext ctx, Path path) { + private FilterOperator parseBasicFunctionOperator(PredicateContext ctx, PartialPath path) { BasicFunctionOperator basic; if (ctx.constant().dateExpression() != null) { - if (!path.equals(SQLConstant.RESERVED_TIME)) { + if (!path.equals(TIME_PATH)) { throw new SQLParserException(path.toString(), "Date can only be used to time"); } basic = new BasicFunctionOperator(ctx.comparisonOperator().type.getType(), path, @@ -1490,14 +1497,15 @@ public class LogicalGenerator extends SqlBaseBaseListener { return basic; } - private Path parseSuffixPath(SuffixPathContext ctx) { + private PartialPath parseSuffixPath(SuffixPathContext ctx) { List<NodeNameContext> nodeNames = ctx.nodeName(); - List<String> path = new ArrayList<>(); + String[] path = new String[nodeNames.size()]; + int i = 0; for (NodeNameContext nodeName : nodeNames) { - path.add(nodeName.getText()); + path[i] = nodeName.getText(); + i++; } - return new Path( - new StringContainer(path.toArray(new String[0]), TsFileConstant.PATH_SEPARATOR)); + return new PartialPath(path); } /** diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java index 64990b7..0cc2bcb 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java @@ -31,7 +31,7 @@ import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.LogicalOperatorException; import org.apache.iotdb.db.exception.query.LogicalOptimizeException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.metadata.MManager; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.db.qp.logical.Operator; import org.apache.iotdb.db.qp.logical.Operator.OperatorType; @@ -100,12 +100,12 @@ import org.apache.iotdb.db.qp.physical.sys.ShowPlan.ShowContentType; import org.apache.iotdb.db.qp.physical.sys.ShowTTLPlan; import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan; import org.apache.iotdb.db.qp.physical.sys.TracingPlan; +import org.apache.iotdb.db.service.IoTDB; import org.apache.iotdb.db.utils.SchemaUtils; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.read.common.Path; import org.apache.iotdb.tsfile.read.expression.IExpression; import org.apache.iotdb.tsfile.utils.Pair; -import org.apache.iotdb.db.service.IoTDB; /** @@ -114,7 +114,7 @@ import org.apache.iotdb.db.service.IoTDB; public class PhysicalGenerator { public PhysicalPlan transformToPhysicalPlan(Operator operator) throws QueryProcessException { - List<Path> paths; + List<PartialPath> paths; switch (operator.getType()) { case AUTHOR: AuthorOperator author = (AuthorOperator) operator; @@ -177,7 +177,7 @@ public class PhysicalGenerator { "For Insert command, cannot specified more than one seriesPath: " + paths); } - return new InsertRowPlan(paths.get(0).getFullPath(), insert.getTime(), + return new InsertRowPlan(paths.get(0), insert.getTime(), insert.getMeasurementList(), insert.getValueList()); case MERGE: if (operator.getTokenIntType() == SQLConstant.TOK_FULL_MERGE) { @@ -298,7 +298,7 @@ public class PhysicalGenerator { * @return pair.left is the type of column in result set, pair.right is the real type of the * measurement */ - protected Pair<List<TSDataType>, List<TSDataType>> getSeriesTypes(List<String> paths, + protected Pair<List<TSDataType>, List<TSDataType>> getSeriesTypes(List<PartialPath> paths, String aggregation) throws MetadataException { List<TSDataType> measurementDataTypes = SchemaUtils.getSeriesTypesByString(paths, null); // if the aggregation function is null, the type of column in result set @@ -397,7 +397,7 @@ public class PhysicalGenerator { if (!queryOperator.isAlignByTime()) { throw new QueryProcessException("Disable align cannot be applied to LAST query."); } - List<Path> paths = queryOperator.getSelectedPaths(); + List<PartialPath> paths = queryOperator.getSelectedPaths(); queryPlan.setPaths(paths); } else if (queryOperator.isAlignByDevice()) { // below is the core realization of ALIGN_BY_DEVICE sql logic @@ -413,10 +413,10 @@ public class PhysicalGenerator { alignByDevicePlan.setAggregationPlan((AggregationPlan) queryPlan); } - List<Path> prefixPaths = queryOperator.getFromOperator().getPrefixPaths(); + List<PartialPath> prefixPaths = queryOperator.getFromOperator().getPrefixPaths(); // remove stars in fromPaths and get deviceId with deduplication - List<String> devices = this.removeStarsInDeviceWithUnique(prefixPaths); - List<Path> suffixPaths = queryOperator.getSelectOperator().getSuffixPaths(); + List<PartialPath> devices = this.removeStarsInDeviceWithUnique(prefixPaths); + List<PartialPath> suffixPaths = queryOperator.getSelectOperator().getSuffixPaths(); List<String> originAggregations = queryOperator.getSelectOperator().getAggregations(); // to record result measurement columns @@ -428,32 +428,35 @@ public class PhysicalGenerator { // to record the real type of the corresponding measurement Map<String, TSDataType> measurementDataTypeMap = new HashMap<>(); - List<Path> paths = new ArrayList<>(); + List<PartialPath> paths = new ArrayList<>(); for (int i = 0; i < suffixPaths.size(); i++) { // per suffix in SELECT - Path suffixPath = suffixPaths.get(i); + PartialPath suffixPath = suffixPaths.get(i); // to record measurements in the loop of a suffix path Set<String> measurementSetOfGivenSuffix = new LinkedHashSet<>(); // if const measurement - if (suffixPath.startWith("'") || suffixPath.startWith("\"")) { - measurements.add(suffixPath.getMeasurement()); - measurementTypeMap.put(suffixPath.getMeasurement(), MeasurementType.Constant); + String[] nodes = suffixPath.getNodes(); + if (nodes[0].startsWith("'") || nodes[0].startsWith("\"")) { + measurements.add(nodes[0]); + measurementTypeMap.put(nodes[0], MeasurementType.Constant); continue; } - for (String device : devices) { // per device in FROM after deduplication - Path fullPath = Path.addPrefixPath(suffixPath, device); + for (PartialPath device : devices) { // per device in FROM after deduplication + //device is full path now + device.concatPath(suffixPath); + String[] detachFullPath = device.getNodes(); try { // remove stars in SELECT to get actual paths - List<String> actualPaths = getMatchedTimeseries(fullPath.getFullPath()); + List<PartialPath> actualPaths = getMatchedTimeseries(device); // for actual non exist path if (actualPaths.isEmpty() && originAggregations.isEmpty()) { - String nonExistMeasurement = fullPath.getMeasurement(); + String nonExistMeasurement = detachFullPath[detachFullPath.length - 1]; if (measurementSetOfGivenSuffix.add(nonExistMeasurement) && measurementTypeMap.get(nonExistMeasurement) != MeasurementType.Exist) { - measurementTypeMap.put(fullPath.getMeasurement(), MeasurementType.NonExist); + measurementTypeMap.put(detachFullPath[detachFullPath.length - 1], MeasurementType.NonExist); } } @@ -471,7 +474,7 @@ public class PhysicalGenerator { List<TSDataType> columnDataTypes = pair.left; List<TSDataType> measurementDataTypes = pair.right; for (int pathIdx = 0; pathIdx < actualPaths.size(); pathIdx++) { - Path path = new Path(actualPaths.get(pathIdx)); + PartialPath path = new PartialPath(actualPaths.get(pathIdx).getNodes()); // check datatype consistency // a example of inconsistency: select s0 from root.sg1.d1, root.sg1.d2 align by device, @@ -509,7 +512,7 @@ public class PhysicalGenerator { } catch (MetadataException e) { throw new LogicalOptimizeException( String.format( - "Error when getting all paths of a full path: %s", fullPath.getFullPath()) + "Error when getting all paths of a full path: %s", device.toString()) + e.getMessage()); } } @@ -610,13 +613,13 @@ public class PhysicalGenerator { return deviceToFilterMap; } - private List<String> removeStarsInDeviceWithUnique(List<Path> paths) + private List<PartialPath> removeStarsInDeviceWithUnique(List<PartialPath> paths) throws LogicalOptimizeException { - List<String> retDevices; - Set<String> deviceSet = new LinkedHashSet<>(); + List<PartialPath> retDevices; + Set<PartialPath> deviceSet = new LinkedHashSet<>(); try { - for (Path path : paths) { - Set<String> tempDS = getMatchedDevices(path.getFullPath()); + for (PartialPath path : paths) { + Set<PartialPath> tempDS = getMatchedDevices(path); deviceSet.addAll(tempDS); } retDevices = new ArrayList<>(deviceSet); @@ -729,11 +732,11 @@ public class PhysicalGenerator { return new ArrayList<>(columnList.subList(seriesOffset, endPosition)); } - protected List<String> getMatchedTimeseries(String path) throws MetadataException { + protected List<PartialPath> getMatchedTimeseries(PartialPath path) throws MetadataException { return IoTDB.metaManager.getAllTimeseriesName(path); } - protected Set<String> getMatchedDevices(String path) throws MetadataException { + protected Set<PartialPath> getMatchedDevices(PartialPath path) throws MetadataException { return IoTDB.metaManager.getDevices(path); } } diff --git a/server/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java index 8a30c6d..1319706 100644 --- a/server/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java +++ b/server/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.metadata.PathAlreadyExistException; +import org.apache.iotdb.db.metadata.PartialPath; import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.db.service.IoTDB; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; @@ -104,14 +105,14 @@ public class SchemaUtils { * @param aggregation aggregation function, may be null * @return The data type of aggregation or (data type of paths if aggregation is null) */ - public static List<TSDataType> getSeriesTypesByString(Collection<String> paths, + public static List<TSDataType> getSeriesTypesByString(Collection<PartialPath> paths, String aggregation) throws MetadataException { TSDataType dataType = getAggregationType(aggregation); if (dataType != null) { return Collections.nCopies(paths.size(), dataType); } List<TSDataType> dataTypes = new ArrayList<>(); - for (String path : paths) { + for (PartialPath path : paths) { dataTypes.add(IoTDB.metaManager.getSeriesType(path)); } return dataTypes; diff --git a/server/src/main/java/org/apache/iotdb/db/writelog/io/BatchLogReader.java b/server/src/main/java/org/apache/iotdb/db/writelog/io/BatchLogReader.java index 5a2499a..e0bf503 100644 --- a/server/src/main/java/org/apache/iotdb/db/writelog/io/BatchLogReader.java +++ b/server/src/main/java/org/apache/iotdb/db/writelog/io/BatchLogReader.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.iotdb.db.exception.metadata.IllegalPathException; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,7 @@ public class BatchLogReader implements ILogReader{ while (buffer.position() != buffer.limit()) { try { plans.add(PhysicalPlan.Factory.create(buffer)); - } catch (IOException e) { + } catch (IOException | IllegalPathException e) { logger.error("Cannot deserialize PhysicalPlans from ByteBuffer, ignore remaining logs", e); fileCorrupted = true; break;
