-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implemented the count database in table model #17705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,6 +229,7 @@ | |
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.region.MigrateRegionTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.region.ReconstructRegionTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.region.RemoveRegionTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.CountDBTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DeleteDeviceTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DescribeTableDetailsTask; | ||
| import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.DescribeTableTask; | ||
|
|
@@ -255,6 +256,7 @@ | |
| import org.apache.iotdb.db.queryengine.plan.expression.Expression; | ||
| import org.apache.iotdb.db.queryengine.plan.expression.visitor.TransformToViewExpressionVisitor; | ||
| import org.apache.iotdb.db.queryengine.plan.planner.plan.node.metadata.write.view.AlterLogicalViewNode; | ||
| import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CountDB; | ||
| import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DeleteDevice; | ||
| import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DropDB; | ||
| import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ShowCluster; | ||
|
|
@@ -2335,7 +2337,7 @@ | |
| } | ||
|
|
||
| @Override | ||
| public SettableFuture<ConfigTaskResult> alterPipe(final AlterPipeStatement alterPipeStatement) { | ||
|
Check warning on line 2340 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
|
||
| final SettableFuture<ConfigTaskResult> future = SettableFuture.create(); | ||
|
|
||
| // Validate pipe name | ||
|
|
@@ -4140,6 +4142,24 @@ | |
| return future; | ||
| } | ||
|
|
||
| @Override | ||
| public SettableFuture<ConfigTaskResult> countDatabases( | ||
| final CountDB countDB, final Predicate<String> canSeenDB) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. canSeenDB -> canSeeDB |
||
| final SettableFuture<ConfigTaskResult> future = SettableFuture.create(); | ||
| final List<String> databasePathPattern = Arrays.asList(ALL_RESULT_NODES); | ||
| try (final ConfigNodeClient client = | ||
| CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { | ||
| final TGetDatabaseReq req = | ||
| new TGetDatabaseReq(databasePathPattern, ALL_MATCH_SCOPE.serialize()) | ||
| .setIsTableModel(true); | ||
| final TShowDatabaseResp resp = client.showDatabase(req); | ||
| CountDBTask.buildTSBlock(resp.getDatabaseInfoMap(), future, canSeenDB); | ||
| } catch (final IOException | ClientManagerException | TException e) { | ||
| future.setException(e); | ||
| } | ||
| return future; | ||
| } | ||
|
|
||
| @Override | ||
| public SettableFuture<ConfigTaskResult> showCluster(final ShowCluster showCluster) { | ||
| // As the implementation is identical, we'll simply translate to the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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.commons.conf.IoTDBConstant; | ||
| import org.apache.iotdb.commons.schema.column.ColumnHeader; | ||
| import org.apache.iotdb.db.queryengine.common.header.DatasetHeader; | ||
| 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.CountDB; | ||
| 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 java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import static org.apache.iotdb.commons.schema.table.InformationSchema.INFORMATION_DATABASE; | ||
|
|
||
| public class CountDBTask implements IConfigTask { | ||
|
Check warning on line 42 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/CountDBTask.java
|
||
|
|
||
| private final CountDB node; | ||
| private final Predicate<String> canSeenDB; | ||
|
|
||
| public CountDBTask(final CountDB node, final Predicate<String> canSeenDB) { | ||
| this.node = node; | ||
| this.canSeenDB = canSeenDB; | ||
| } | ||
|
|
||
| @Override | ||
| public ListenableFuture<ConfigTaskResult> execute(final IConfigTaskExecutor configTaskExecutor) | ||
| throws InterruptedException { | ||
| return configTaskExecutor.countDatabases(node, canSeenDB); | ||
| } | ||
|
|
||
| public static void buildTSBlock( | ||
|
Check warning on line 58 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/CountDBTask.java
|
||
| final Map<String, ?> databaseInfoMap, | ||
|
CRZbulabula marked this conversation as resolved.
|
||
| final SettableFuture<ConfigTaskResult> future, | ||
| final Predicate<String> canSeenDB) { | ||
| // information_schema is synthesized in table model rather than returned from ConfigNode. | ||
| final long databaseCount = | ||
| databaseInfoMap.keySet().stream() | ||
| .filter(databaseName -> !INFORMATION_DATABASE.equals(databaseName)) | ||
| .filter(canSeenDB::test) | ||
| .count() | ||
| + (canSeenDB.test(INFORMATION_DATABASE) ? 1 : 0); | ||
|
|
||
| final TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(TSDataType.INT32)); | ||
| builder.getTimeColumnBuilder().writeLong(0L); | ||
| builder.getColumnBuilder(0).writeInt((int) databaseCount); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Narrowing cast |
||
| builder.declarePosition(); | ||
|
|
||
| final DatasetHeader datasetHeader = | ||
| new DatasetHeader( | ||
| Collections.singletonList( | ||
| new ColumnHeader(IoTDBConstant.COLUMN_COUNT, TSDataType.INT32)), | ||
| true); | ||
| future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, builder.build(), datasetHeader)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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.commons.queryengine.plan.relational.sql.ast.AstMemoryEstimationHelper; | ||
| import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.IAstVisitor; | ||
| import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Node; | ||
| import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.NodeLocation; | ||
| import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import org.apache.tsfile.utils.RamUsageEstimator; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| import java.util.List; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class CountDB extends Statement { | ||
|
|
||
| private static final long INSTANCE_SIZE = RamUsageEstimator.shallowSizeOfInstance(CountDB.class); | ||
|
|
||
| public CountDB(final NodeLocation location) { | ||
| super(requireNonNull(location, "location is null")); | ||
| } | ||
|
|
||
| @Override | ||
| public <R, C> R accept(final IAstVisitor<R, C> visitor, final C context) { | ||
| return ((AstVisitor<R, C>) visitor).visitCountDB(this, context); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Node> getChildren() { | ||
| return ImmutableList.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return getClass().hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| return (obj != null) && (getClass() == obj.getClass()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "COUNT DATABASES"; | ||
| } | ||
|
|
||
| @Override | ||
| public long ramBytesUsed() { | ||
| long size = INSTANCE_SIZE; | ||
| size += AstMemoryEstimationHelper.getEstimatedSizeOfNodeLocation(getLocationInternal()); | ||
| return size; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.