OneSizeFitsQuorum commented on code in PR #12852: URL: https://github.com/apache/iotdb/pull/12852#discussion_r1668293305
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowRegions.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.queryengine.plan.relational.sql.ast; + +import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType; +import org.apache.iotdb.commons.path.PartialPath; + +import com.google.common.collect.ImmutableList; + +import java.util.List; +import java.util.Objects; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static java.util.Objects.requireNonNull; + +public class ShowRegions extends Statement { + + private final TConsensusGroupType regionType; + private final List<PartialPath> storageGroups; + private final List<Integer> nodeIds; + + public ShowRegions( + TConsensusGroupType regionType, List<PartialPath> storageGroups, List<Integer> nodeIds) { + super(null); + this.regionType = regionType; + this.storageGroups = requireNonNull(storageGroups, "storageGroups is null"); Review Comment: maybe we should rename it to database ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java: ########## @@ -2790,6 +2795,119 @@ public SettableFuture<ConfigTaskResult> showDatabases(ShowDB showDB) { return future; } + @Override + public SettableFuture<ConfigTaskResult> showCluster(ShowCluster showCluster) { + SettableFuture<ConfigTaskResult> future = SettableFuture.create(); + TShowClusterResp showClusterResp = new TShowClusterResp(); + try (ConfigNodeClient client = + CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { + showClusterResp = client.showCluster(); + } catch (ClientManagerException | TException e) { + if (showClusterResp.getConfigNodeList() == null) { + future.setException(new TException(MSG_RECONNECTION_FAIL)); + } else { + future.setException(e); + } + return future; + } + // build TSBlock + if (showCluster.getDetails().orElse(false)) { + ShowClusterDetailsTask.buildTSBlock(showClusterResp, future); + } else { + org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowClusterTask Review Comment: can we just use ShowClusterTask? ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java: ########## @@ -409,23 +416,43 @@ public Node visitCountDevicesStatement(RelationalSqlParser.CountDevicesStatement @Override public Node visitShowClusterStatement(RelationalSqlParser.ShowClusterStatementContext ctx) { - return super.visitShowClusterStatement(ctx); + boolean details = ctx.DETAILS() != null; + return new ShowCluster(details); } @Override public Node visitShowRegionsStatement(RelationalSqlParser.ShowRegionsStatementContext ctx) { - return super.visitShowRegionsStatement(ctx); + TConsensusGroupType regionType = null; + if (ctx.DATA() != null) { + regionType = TConsensusGroupType.DataRegion; + } else if (ctx.SCHEMA() != null) { + regionType = TConsensusGroupType.SchemaRegion; + } + List<PartialPath> storageGroups = new ArrayList<>(); Review Comment: database ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowRegions.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.queryengine.plan.relational.sql.ast; + +import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType; +import org.apache.iotdb.commons.path.PartialPath; + +import com.google.common.collect.ImmutableList; + +import java.util.List; +import java.util.Objects; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static java.util.Objects.requireNonNull; + +public class ShowRegions extends Statement { + + private final TConsensusGroupType regionType; + private final List<PartialPath> storageGroups; Review Comment: can we just use string as database now? ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java: ########## @@ -2790,6 +2795,119 @@ public SettableFuture<ConfigTaskResult> showDatabases(ShowDB showDB) { return future; } + @Override + public SettableFuture<ConfigTaskResult> showCluster(ShowCluster showCluster) { + SettableFuture<ConfigTaskResult> future = SettableFuture.create(); + TShowClusterResp showClusterResp = new TShowClusterResp(); + try (ConfigNodeClient client = + CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { + showClusterResp = client.showCluster(); + } catch (ClientManagerException | TException e) { + if (showClusterResp.getConfigNodeList() == null) { + future.setException(new TException(MSG_RECONNECTION_FAIL)); + } else { + future.setException(e); + } + return future; + } + // build TSBlock + if (showCluster.getDetails().orElse(false)) { + ShowClusterDetailsTask.buildTSBlock(showClusterResp, future); + } else { + org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowClusterTask + .buildTsBlock(showClusterResp, future); + } + + return future; + } + + @Override + public SettableFuture<ConfigTaskResult> showRegions(ShowRegions showRegions) { + SettableFuture<ConfigTaskResult> future = SettableFuture.create(); + TShowRegionResp showRegionResp = new TShowRegionResp(); + TShowRegionReq showRegionReq = new TShowRegionReq(); + showRegionReq.setConsensusGroupType(showRegions.getRegionType()); + if ((showRegions.getStorageGroups() == null) || showRegions.getStorageGroups().isEmpty()) { Review Comment: maybe we can rename storageGroup to database ########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java: ########## @@ -2790,6 +2795,119 @@ public SettableFuture<ConfigTaskResult> showDatabases(ShowDB showDB) { return future; } + @Override + public SettableFuture<ConfigTaskResult> showCluster(ShowCluster showCluster) { + SettableFuture<ConfigTaskResult> future = SettableFuture.create(); + TShowClusterResp showClusterResp = new TShowClusterResp(); + try (ConfigNodeClient client = + CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { + showClusterResp = client.showCluster(); + } catch (ClientManagerException | TException e) { + if (showClusterResp.getConfigNodeList() == null) { + future.setException(new TException(MSG_RECONNECTION_FAIL)); + } else { + future.setException(e); + } + return future; + } + // build TSBlock + if (showCluster.getDetails().orElse(false)) { + ShowClusterDetailsTask.buildTSBlock(showClusterResp, future); + } else { + org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowClusterTask + .buildTsBlock(showClusterResp, future); + } + + return future; + } + + @Override + public SettableFuture<ConfigTaskResult> showRegions(ShowRegions showRegions) { + SettableFuture<ConfigTaskResult> future = SettableFuture.create(); + TShowRegionResp showRegionResp = new TShowRegionResp(); + TShowRegionReq showRegionReq = new TShowRegionReq(); + showRegionReq.setConsensusGroupType(showRegions.getRegionType()); + if ((showRegions.getStorageGroups() == null) || showRegions.getStorageGroups().isEmpty()) { + showRegionReq.setDatabases(null); + } else { + showRegionReq.setDatabases( + showRegions.getStorageGroups().stream() + .map(PartialPath::getFullPath) + .collect(Collectors.toList())); + } + try (ConfigNodeClient client = + CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { + showRegionResp = client.showRegion(showRegionReq); + if (showRegionResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + future.setException( + new IoTDBException( + showRegionResp.getStatus().message, showRegionResp.getStatus().code)); + return future; + } + } catch (ClientManagerException | TException e) { + future.setException(e); + } + + // filter the regions by nodeId + // TODO: This part currently will remain empty as we're ot implementing any other filtering + // methods right now. + if ((showRegions.getNodeIds() != null) && !showRegions.getNodeIds().isEmpty()) { Review Comment: redundant ()? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
