From 0137093279915f59a83fd46354b1b44de27c74cf Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Wed, 25 Sep 2024 11:30:29 +0200 Subject: [PATCH] Feature/show ainodes command (#13592) --- iotdb-core/ainode/pyproject.toml | 2 +- .../db/queryengine/plan/Coordinator.java | 2 + .../config/TableConfigTaskVisitor.java | 14 ++- .../config/TreeConfigTaskVisitor.java | 14 +-- .../executor/ClusterConfigTaskExecutor.java | 88 +++++-------------- .../config/executor/IConfigTaskExecutor.java | 14 +-- .../metadata/{model => }/ShowAINodesTask.java | 11 +-- .../config/metadata/ShowDataNodesTask.java | 2 +- .../metadata/relational/ShowAINodesTask.java | 78 ++++++++++++++++ .../relational/ShowConfigNodesTask.java | 9 +- .../relational/ShowDataNodesTask.java | 9 +- .../plan/relational/sql/ast/AstVisitor.java | 4 + .../plan/relational/sql/ast/ShowAINodes.java | 66 ++++++++++++++ .../relational/sql/parser/AstBuilder.java | 6 ++ .../relational/grammar/sql/RelationalSql.g4 | 6 ++ 15 files changed, 212 insertions(+), 113 deletions(-) rename iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/{model => }/ShowAINodesTask.java (90%) create mode 100644 iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowAINodesTask.java create mode 100644 iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowAINodes.java diff --git a/iotdb-core/ainode/pyproject.toml b/iotdb-core/ainode/pyproject.toml index 6211d2301365..c7f773b05908 100644 --- a/iotdb-core/ainode/pyproject.toml +++ b/iotdb-core/ainode/pyproject.toml @@ -21,7 +21,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "apache-iotdb-ainode" -version = "1.4.0.dev" +version = "2.0.0.dev" description = "Apache IoTDB AINode" readme = "README.md" authors = ["Apache Software Foundation "] diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java index c8358b4f7409..3ac30f633a7d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java @@ -57,6 +57,7 @@ import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.PipeStatement; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetConfiguration; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetProperties; +import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowAINodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDB; @@ -330,6 +331,7 @@ private IQueryExecution createQueryExecutionForTableModel( || statement instanceof ShowRegions || statement instanceof ShowDataNodes || statement instanceof ShowConfigNodes + || statement instanceof ShowAINodes || statement instanceof Flush || statement instanceof SetConfiguration || statement instanceof PipeStatement) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java index 39911fab1910..7d20c47d74b9 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java @@ -39,6 +39,7 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.CreateTableTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DescribeTableTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DropDBTask; +import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowAINodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowConfigNodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowDBTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowDataNodesTask; @@ -78,6 +79,7 @@ import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.QualifiedName; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetConfiguration; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetProperties; +import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowAINodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDB; @@ -253,13 +255,21 @@ protected IConfigTask visitShowRegions( protected IConfigTask visitShowDataNodes( final ShowDataNodes showDataNodesStatement, final MPPQueryContext context) { context.setQueryType(QueryType.READ); - return new ShowDataNodesTask(showDataNodesStatement); + return new ShowDataNodesTask(); } + @Override protected IConfigTask visitShowConfigNodes( final ShowConfigNodes showConfigNodesStatement, final MPPQueryContext context) { context.setQueryType(QueryType.READ); - return new ShowConfigNodesTask(showConfigNodesStatement); + return new ShowConfigNodesTask(); + } + + @Override + protected IConfigTask visitShowAINodes( + final ShowAINodes showAINodesStatement, final MPPQueryContext context) { + context.setQueryType(QueryType.READ); + return new ShowAINodesTask(); } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java index c39f6277fd31..9caf9da708e2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java @@ -38,6 +38,7 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetTimeSlotListTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.MigrateRegionTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.SetTTLTask; +import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowAINodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterDetailsTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterIdTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterTask; @@ -54,7 +55,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.UnSetTTLTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.CreateModelTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.DropModelTask; -import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.ShowAINodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.ShowModelsTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.template.AlterSchemaTemplateTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.template.CreateSchemaTemplateTask; @@ -441,6 +441,12 @@ public IConfigTask visitShowConfigNodes( return new ShowConfigNodesTask(); } + @Override + public IConfigTask visitShowAINodes( + ShowAINodesStatement showAINodesStatement, MPPQueryContext context) { + return new ShowAINodesTask(); + } + @Override public IConfigTask visitShowPipes( ShowPipesStatement showPipesStatement, MPPQueryContext context) { @@ -612,10 +618,4 @@ public IConfigTask visitShowModels( ShowModelsStatement showModelsStatement, MPPQueryContext context) { return new ShowModelsTask(showModelsStatement.getModelName()); } - - @Override - public IConfigTask visitShowAINodes( - ShowAINodesStatement showAINodesStatement, MPPQueryContext context) { - return new ShowAINodesTask(showAINodesStatement); - } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java index e8919b7fb583..1cf129f46eb2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java @@ -153,6 +153,7 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetRegionIdTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetSeriesSlotListTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetTimeSlotListTask; +import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowAINodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterDetailsTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterIdTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterTask; @@ -165,7 +166,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowTTLTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowTriggersTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowVariablesTask; -import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.ShowAINodesTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model.ShowModelsTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DescribeTableTask; import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.ShowDBTask; @@ -184,9 +184,7 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.view.AlterLogicalViewNode; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DropDB; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDB; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDataNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowRegions; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Use; import org.apache.iotdb.db.queryengine.plan.statement.metadata.CountDatabaseStatement; @@ -203,12 +201,10 @@ import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterStatement; -import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDataNodesStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowRegionStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowTTLStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.CreateModelStatement; -import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowAINodesStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.AlterPipeStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.CreatePipePluginStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.CreatePipeStatement; @@ -1437,8 +1433,7 @@ public SettableFuture showRegion(ShowRegionStatement showRegio } @Override - public SettableFuture showDataNodes( - final ShowDataNodesStatement showDataNodesStatement) { + public SettableFuture showDataNodes() { final SettableFuture future = SettableFuture.create(); TShowDataNodesResp showDataNodesResp = new TShowDataNodesResp(); try (final ConfigNodeClient client = @@ -1480,6 +1475,24 @@ public SettableFuture showConfigNodes() { return future; } + @Override + public SettableFuture showAINodes() { + SettableFuture future = SettableFuture.create(); + TShowAINodesResp resp = new TShowAINodesResp(); + try (ConfigNodeClient client = + CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { + resp = client.showAINodes(); + if (resp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + future.setException(new IoTDBException(resp.getStatus().message, resp.getStatus().code)); + return future; + } + } catch (ClientManagerException | TException e) { + future.setException(e); + } + ShowAINodesTask.buildTsBlock(resp, future); + return future; + } + @Override public SettableFuture createSchemaTemplate( final CreateSchemaTemplateStatement createSchemaTemplateStatement) { @@ -2765,24 +2778,6 @@ public SettableFuture showModels(String modelName) { return future; } - @Override - public SettableFuture showAINodes(ShowAINodesStatement showAINodesStatement) { - SettableFuture future = SettableFuture.create(); - TShowAINodesResp resp = new TShowAINodesResp(); - try (ConfigNodeClient client = - CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { - resp = client.showAINodes(); - if (resp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - future.setException(new IoTDBException(resp.getStatus().message, resp.getStatus().code)); - return future; - } - } catch (ClientManagerException | TException e) { - future.setException(e); - } - ShowAINodesTask.buildTsBlock(resp, future); - return future; - } - @Override public SettableFuture setSpaceQuota( SetSpaceQuotaStatement setSpaceQuotaStatement) { @@ -2970,49 +2965,6 @@ public SettableFuture showRegions(ShowRegions showRegions) { return showRegion(treeStatement); } - @Override - public SettableFuture showDataNodes(ShowDataNodes showDataNodes) { - SettableFuture future = SettableFuture.create(); - TShowDataNodesResp showDataNodesResp = new TShowDataNodesResp(); - try (ConfigNodeClient client = - CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { - showDataNodesResp = client.showDataNodes(); - if (showDataNodesResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - future.setException( - new IoTDBException( - showDataNodesResp.getStatus().message, showDataNodesResp.getStatus().code)); - return future; - } - } catch (ClientManagerException | TException e) { - future.setException(e); - } - // build TSBlock - ShowDataNodesTask.buildTSBlock(showDataNodesResp, future); - return future; - } - - @Override - public SettableFuture showConfigNodes(ShowConfigNodes showConfigNodes) { - SettableFuture future = SettableFuture.create(); - TShowConfigNodesResp showConfigNodesResp = new TShowConfigNodesResp(); - try (ConfigNodeClient client = - CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { - showConfigNodesResp = client.showConfigNodes(); - if (showConfigNodesResp.getStatus().getCode() - != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - future.setException( - new IoTDBException( - showConfigNodesResp.getStatus().message, showConfigNodesResp.getStatus().code)); - return future; - } - } catch (ClientManagerException | TException e) { - future.setException(e); - } - // build TSBlock - ShowConfigNodesTask.buildTSBlock(showConfigNodesResp, future); - return future; - } - @Override public SettableFuture useDatabase(Use useDB, IClientSession clientSession) { SettableFuture future = SettableFuture.create(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java index 9db45b66da25..8fbc546aa358 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java @@ -35,9 +35,7 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.view.AlterLogicalViewNode; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DropDB; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDB; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDataNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowRegions; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Use; import org.apache.iotdb.db.queryengine.plan.statement.metadata.CountDatabaseStatement; @@ -54,12 +52,10 @@ import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterStatement; -import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDataNodesStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowRegionStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowTTLStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.CreateModelStatement; -import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowAINodesStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.AlterPipeStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.CreatePipePluginStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.pipe.CreatePipeStatement; @@ -160,10 +156,12 @@ public interface IConfigTaskExecutor { SettableFuture showRegion(ShowRegionStatement showRegionStatement); - SettableFuture showDataNodes(ShowDataNodesStatement showDataNodesStatement); + SettableFuture showDataNodes(); SettableFuture showConfigNodes(); + SettableFuture showAINodes(); + SettableFuture createSchemaTemplate( CreateSchemaTemplateStatement createSchemaTemplateStatement); @@ -267,8 +265,6 @@ SettableFuture createModel( SettableFuture showModels(String modelName); - SettableFuture showAINodes(ShowAINodesStatement showAINodesStatement); - TPipeTransferResp handleTransferConfigPlan(String clientId, TPipeTransferReq req); void handlePipeConfigClientExit(String clientId); @@ -281,10 +277,6 @@ SettableFuture createModel( SettableFuture showRegions(ShowRegions showRegions); - SettableFuture showDataNodes(ShowDataNodes showDataNodes); - - SettableFuture showConfigNodes(ShowConfigNodes showConfigNodes); - SettableFuture useDatabase(final Use useDB, final IClientSession clientSession); SettableFuture dropDatabase(final DropDB dropDB); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/model/ShowAINodesTask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowAINodesTask.java similarity index 90% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/model/ShowAINodesTask.java rename to iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowAINodesTask.java index f63a43aa1a36..e0bdffff149d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/model/ShowAINodesTask.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowAINodesTask.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.iotdb.db.queryengine.plan.execution.config.metadata.model; +package org.apache.iotdb.db.queryengine.plan.execution.config.metadata; import org.apache.iotdb.confignode.rpc.thrift.TAINodeInfo; import org.apache.iotdb.confignode.rpc.thrift.TShowAINodesResp; @@ -28,7 +28,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult; import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask; import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor; -import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowAINodesStatement; import org.apache.iotdb.rpc.TSStatusCode; import com.google.common.util.concurrent.ListenableFuture; @@ -42,16 +41,14 @@ public class ShowAINodesTask implements IConfigTask { - private final ShowAINodesStatement showAINodesStatement; - - public ShowAINodesTask(ShowAINodesStatement showAINodesStatement) { - this.showAINodesStatement = showAINodesStatement; + public ShowAINodesTask() { + // do nothing } @Override public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) throws InterruptedException { - return configTaskExecutor.showAINodes(showAINodesStatement); + return configTaskExecutor.showAINodes(); } public static void buildTsBlock( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowDataNodesTask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowDataNodesTask.java index 2fb899a88535..0c6b19238ca2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowDataNodesTask.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowDataNodesTask.java @@ -53,7 +53,7 @@ public ShowDataNodesTask(ShowDataNodesStatement showDataNodesStatement) { @Override public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) throws InterruptedException { - return configTaskExecutor.showDataNodes(showDataNodesStatement); + return configTaskExecutor.showDataNodes(); } public static void buildTSBlock( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowAINodesTask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowAINodesTask.java new file mode 100644 index 000000000000..20b88f8d1de7 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowAINodesTask.java @@ -0,0 +1,78 @@ +/* + * 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.execution.config.metadata.relational; + +import org.apache.iotdb.confignode.rpc.thrift.TDataNodeInfo; +import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp; +import org.apache.iotdb.db.queryengine.common.header.ColumnHeader; +import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant; +import org.apache.iotdb.db.queryengine.common.header.DatasetHeader; +import org.apache.iotdb.db.queryengine.common.header.DatasetHeaderFactory; +import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult; +import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask; +import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor; +import org.apache.iotdb.rpc.TSStatusCode; + +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.SettableFuture; +import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.read.common.block.TsBlockBuilder; +import org.apache.tsfile.utils.BytesUtils; + +import java.util.List; +import java.util.stream.Collectors; + +public class ShowAINodesTask implements IConfigTask { + + @Override + public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) + throws InterruptedException { + return configTaskExecutor.showAINodes(); + } + + public static void buildTSBlock( + TShowDataNodesResp showDataNodesResp, SettableFuture future) { + List outputDataTypes = + ColumnHeaderConstant.showDataNodesColumnHeaders.stream() + .map(ColumnHeader::getColumnType) + .collect(Collectors.toList()); + TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes); + if (showDataNodesResp.getDataNodesInfoList() != null) { + for (TDataNodeInfo dataNodeInfo : showDataNodesResp.getDataNodesInfoList()) { + builder.getTimeColumnBuilder().writeLong(0L); + builder.getColumnBuilder(0).writeInt(dataNodeInfo.getDataNodeId()); + builder + .getColumnBuilder(1) + .writeBinary( + BytesUtils.valueOf( + dataNodeInfo.getStatus() == null ? "" : dataNodeInfo.getStatus())); + + builder.getColumnBuilder(2).writeBinary(BytesUtils.valueOf(dataNodeInfo.getRpcAddresss())); + builder.getColumnBuilder(3).writeInt(dataNodeInfo.getRpcPort()); + builder.getColumnBuilder(4).writeInt(dataNodeInfo.getDataRegionNum()); + + builder.getColumnBuilder(5).writeInt(dataNodeInfo.getSchemaRegionNum()); + builder.declarePosition(); + } + } + DatasetHeader datasetHeader = DatasetHeaderFactory.getShowDataNodesHeader(); + future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, builder.build(), datasetHeader)); + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowConfigNodesTask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowConfigNodesTask.java index 5b0ac00068d6..dfd2180daa2f 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowConfigNodesTask.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowConfigNodesTask.java @@ -28,7 +28,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult; import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask; import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.rpc.TSStatusCode; import com.google.common.util.concurrent.ListenableFuture; @@ -42,16 +41,10 @@ public class ShowConfigNodesTask implements IConfigTask { - private final ShowConfigNodes showConfigNodes; - - public ShowConfigNodesTask(ShowConfigNodes showConfigNodes) { - this.showConfigNodes = showConfigNodes; - } - @Override public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) throws InterruptedException { - return configTaskExecutor.showConfigNodes(showConfigNodes); + return configTaskExecutor.showConfigNodes(); } public static void buildTSBlock( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowDataNodesTask.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowDataNodesTask.java index 1ea2533296f7..744fe2018dff 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowDataNodesTask.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowDataNodesTask.java @@ -28,7 +28,6 @@ import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult; import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask; import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor; -import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDataNodes; import org.apache.iotdb.rpc.TSStatusCode; import com.google.common.util.concurrent.ListenableFuture; @@ -42,16 +41,10 @@ public class ShowDataNodesTask implements IConfigTask { - private final ShowDataNodes showDataNodes; - - public ShowDataNodesTask(ShowDataNodes showDataNodes) { - this.showDataNodes = showDataNodes; - } - @Override public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) throws InterruptedException { - return configTaskExecutor.showDataNodes(showDataNodes); + return configTaskExecutor.showDataNodes(); } public static void buildTSBlock( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java index e8d94ccc6a23..a2cd774e26b8 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java @@ -347,6 +347,10 @@ protected R visitShowConfigNodes(ShowConfigNodes node, C context) { return visitStatement(node, context); } + protected R visitShowAINodes(ShowAINodes node, C context) { + return visitStatement(node, context); + } + protected R visitRenameTable(RenameTable node, C context) { return visitStatement(node, context); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowAINodes.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowAINodes.java new file mode 100644 index 000000000000..baaaa5eea5e2 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ShowAINodes.java @@ -0,0 +1,66 @@ +/* + * 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 com.google.common.collect.ImmutableList; + +import java.util.List; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static java.util.Objects.requireNonNull; + +public class ShowAINodes extends Statement { + + public ShowAINodes() { + super(null); + } + + public ShowAINodes(NodeLocation location) { + super(requireNonNull(location, "location is null")); + } + + @Override + public R accept(AstVisitor visitor, C context) { + return visitor.visitShowAINodes(this, context); + } + + @Override + public List getChildren() { + return ImmutableList.of(); + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + return (obj != null) && (getClass() == obj.getClass()); + } + + @Override + public String toString() { + return toStringHelper(this).toString(); + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java index 7f84f6c696fd..c2262423b4a3 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java @@ -115,6 +115,7 @@ import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SelectItem; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetConfiguration; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetProperties; +import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowAINodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowConfigNodes; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowDB; @@ -802,6 +803,11 @@ public Node visitShowConfigNodesStatement( return new ShowConfigNodes(); } + @Override + public Node visitShowAINodesStatement(RelationalSqlParser.ShowAINodesStatementContext ctx) { + return new ShowAINodes(); + } + @Override public Node visitShowClusterIdStatement(RelationalSqlParser.ShowClusterIdStatementContext ctx) { return super.visitShowClusterIdStatement(ctx); diff --git a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 index 3ee122837379..804037da3d5a 100644 --- a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 +++ b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 @@ -93,6 +93,7 @@ statement | showRegionsStatement | showDataNodesStatement | showConfigNodesStatement + | showAINodesStatement | showClusterIdStatement | showRegionIdStatement | showTimeSlotListStatement @@ -380,6 +381,10 @@ showConfigNodesStatement : SHOW CONFIGNODES ; +showAINodesStatement + : SHOW AINODES + ; + showClusterIdStatement : SHOW CLUSTERID ; @@ -857,6 +862,7 @@ ABSENT: 'ABSENT'; ADD: 'ADD'; ADMIN: 'ADMIN'; AFTER: 'AFTER'; +AINODES: 'AINODES'; ALL: 'ALL'; ALTER: 'ALTER'; ANALYZE: 'ANALYZE';