未验证 提交 df250c3d 编写于 作者: Y yhwang-hbl 提交者: GitHub

[IOTDB-813] Show storage group under given path prefix (#1694)

上级 1aa0c506
......@@ -72,7 +72,7 @@ statement
| SHOW DYNAMIC PARAMETER #showDynamicParameter
| SHOW VERSION #showVersion
| {hasSingleQuoteString = false;} SHOW LATEST? TIMESERIES prefixPath? showWhereClause? limitClause? #showTimeseries
| SHOW STORAGE GROUP #showStorageGroup
| {hasSingleQuoteString = false;} SHOW STORAGE GROUP prefixPath? #showStorageGroup
| {hasSingleQuoteString = false;} SHOW CHILD PATHS prefixPath? #showChildPaths
| {hasSingleQuoteString = false;} SHOW DEVICES prefixPath? #showDevices
| SHOW MERGE #showMergeStatus
......
......@@ -771,6 +771,22 @@ public class MManager {
}
}
/**
* Get all storage group under given prefixPath.
*
* @param prefixPath a prefix of 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.
* @return A ArrayList instance which stores storage group paths with given prefixPath.
*/
public List<PartialPath> getStorageGroupPaths(PartialPath prefixPath) throws MetadataException {
lock.readLock().lock();
try {
return mtree.getStorageGroupPaths(prefixPath);
} finally {
lock.readLock().unlock();
}
}
/**
* Get all storage group MNodes
*/
......
......@@ -502,6 +502,50 @@ public class MTree implements Serializable {
return res;
}
/**
* Get all storage group under give path
*
* @return a list contains all storage group names under give path
*/
List<PartialPath> getStorageGroupPaths(PartialPath prefixPath) throws MetadataException {
String[] nodes = prefixPath.getNodes();
if (nodes.length == 0 || !nodes[0].equals(root.getName())) {
throw new IllegalPathException(prefixPath.getFullPath());
}
List<PartialPath> storageGroupPaths = new ArrayList<>();
findStorageGroupPaths(root, nodes, 1, "", storageGroupPaths);
return storageGroupPaths;
}
/**
* Traverse the MTree to match all storage group with prefix path.
*
* @param node the current traversing node
* @param nodes split the prefix path with '.'
* @param idx the current index of array nodes
* @param parent current parent path
* @param storageGroupPaths store all matched storage group names
*/
private void findStorageGroupPaths(MNode node, String[] nodes, int idx, String parent,
List<PartialPath> storageGroupPaths) {
if (node instanceof StorageGroupMNode) {
storageGroupPaths.add(node.getPartialPath());
return;
}
String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);
if (!(PATH_WILDCARD).equals(nodeReg)) {
if (node.hasChild(nodeReg)) {
findStorageGroupPaths(node.getChild(nodeReg), nodes, idx + 1,
parent + node.getName() + PATH_SEPARATOR, storageGroupPaths);
}
} else {
for (MNode child : node.getChildren().values()) {
findStorageGroupPaths(
child, nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR, storageGroupPaths);
}
}
}
/**
* Get all storage group MNodes
*/
......
......@@ -113,6 +113,7 @@ import org.apache.iotdb.db.qp.physical.sys.SetTTLPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowChildPathsPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowDevicesPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowStorageGroupPlan;
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;
......@@ -362,7 +363,7 @@ public class PlanExecutor implements IPlanExecutor {
case TIMESERIES:
return processShowTimeseries((ShowTimeSeriesPlan) showPlan, context);
case STORAGE_GROUP:
return processShowStorageGroup();
return processShowStorageGroup((ShowStorageGroupPlan) showPlan);
case DEVICES:
return processShowDevices((ShowDevicesPlan) showPlan);
case CHILD_PATH:
......@@ -487,16 +488,17 @@ public class PlanExecutor implements IPlanExecutor {
return IoTDB.metaManager.getChildNodePathInNextLevel(path);
}
protected List<PartialPath> getAllStorageGroupNames() {
return IoTDB.metaManager.getAllStorageGroupPaths();
protected List<PartialPath> getStorageGroupNames(PartialPath path) throws MetadataException {
return IoTDB.metaManager.getStorageGroupPaths(path);
}
private QueryDataSet processShowStorageGroup() {
private QueryDataSet processShowStorageGroup(ShowStorageGroupPlan showStorageGroupPlan)
throws MetadataException {
ListDataSet listDataSet =
new ListDataSet(
Collections.singletonList(new PartialPath(COLUMN_STORAGE_GROUP, false)),
Collections.singletonList(TSDataType.TEXT));
List<PartialPath> storageGroupList = getAllStorageGroupNames();
List<PartialPath> storageGroupList = getStorageGroupNames(showStorageGroupPlan.getPath());
for (PartialPath s : storageGroupList) {
RowRecord record = new RowRecord(0);
Field field = new Field(TSDataType.TEXT);
......@@ -1057,7 +1059,7 @@ public class PlanExecutor implements IPlanExecutor {
}
return true;
}
protected QueryDataSet processAuthorQuery(AuthorPlan plan)
throws QueryProcessException {
AuthorType authorType = plan.getAuthorType();
......
/*
* 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.qp.logical.sys;
import org.apache.iotdb.db.metadata.PartialPath;
public class ShowStorageGroupOperator extends ShowOperator {
private PartialPath path;
public ShowStorageGroupOperator(int tokenIntType, PartialPath path) {
super(tokenIntType);
this.path = path;
}
public PartialPath getPath() {
return path;
}
}
/*
* 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.qp.physical.sys;
import org.apache.iotdb.db.metadata.PartialPath;
public class ShowStorageGroupPlan extends ShowPlan {
private PartialPath path;
public ShowStorageGroupPlan(ShowContentType showContentType, PartialPath path) {
super(showContentType);
this.path = path;
}
public PartialPath getPath() {
return this.path;
}
}
......@@ -71,6 +71,7 @@ import org.apache.iotdb.db.qp.logical.sys.ShowChildPathsOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowDevicesOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowMergeStatusOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowStorageGroupOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowTTLOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowTimeSeriesOperator;
import org.apache.iotdb.db.qp.logical.sys.TracingOperator;
......@@ -301,7 +302,13 @@ public class LogicalGenerator extends SqlBaseBaseListener {
@Override
public void enterShowStorageGroup(ShowStorageGroupContext ctx) {
super.enterShowStorageGroup(ctx);
initializedOperator = new ShowOperator(SQLConstant.TOK_STORAGE_GROUP);
if (ctx.prefixPath() != null) {
initializedOperator = new ShowStorageGroupOperator(SQLConstant.TOK_STORAGE_GROUP,
parsePrefixPath(ctx.prefixPath()));
} else {
initializedOperator = new ShowStorageGroupOperator(SQLConstant.TOK_STORAGE_GROUP,
new PartialPath(SQLConstant.getSingleRootArray()));
}
}
@Override
......
......@@ -60,6 +60,7 @@ import org.apache.iotdb.db.qp.logical.sys.SetStorageGroupOperator;
import org.apache.iotdb.db.qp.logical.sys.SetTTLOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowChildPathsOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowDevicesOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowStorageGroupOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowTTLOperator;
import org.apache.iotdb.db.qp.logical.sys.ShowTimeSeriesOperator;
import org.apache.iotdb.db.qp.logical.sys.TracingOperator;
......@@ -98,6 +99,7 @@ import org.apache.iotdb.db.qp.physical.sys.ShowDevicesPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowMergeStatusPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowPlan.ShowContentType;
import org.apache.iotdb.db.qp.physical.sys.ShowStorageGroupPlan;
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;
......@@ -232,7 +234,8 @@ public class PhysicalGenerator {
showTimeSeriesOperator.getValue(), showTimeSeriesOperator.getLimit(),
showTimeSeriesOperator.getOffset(), showTimeSeriesOperator.isOrderByHeat());
case SQLConstant.TOK_STORAGE_GROUP:
return new ShowPlan(ShowContentType.STORAGE_GROUP);
return new ShowStorageGroupPlan(
ShowContentType.STORAGE_GROUP, ((ShowStorageGroupOperator) operator).getPath());
case SQLConstant.TOK_DEVICES:
return new ShowDevicesPlan(
ShowContentType.DEVICES, ((ShowDevicesOperator) operator).getPath());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册