Skip to content
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

Fixed database names in "show regions" in table model #13621

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ protected IConfigTask visitShowRegions(
context.setQueryType(QueryType.READ);
// As the implementation is identical, we'll simply translate to the
// corresponding tree-model variant and execute that.
ShowRegionStatement treeStatement = new ShowRegionStatement();
final ShowRegionStatement treeStatement = new ShowRegionStatement();
treeStatement.setRegionType(showRegions.getRegionType());
treeStatement.setStorageGroups(showRegions.getDatabases());
treeStatement.setNodeIds(showRegions.getNodeIds());
return new ShowRegionTask(treeStatement);
return new ShowRegionTask(treeStatement, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public IConfigTask visitShowPipePlugins(
@Override
public IConfigTask visitShowRegion(
ShowRegionStatement showRegionStatement, MPPQueryContext context) {
return new ShowRegionTask(showRegionStatement);
return new ShowRegionTask(showRegionStatement, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
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.ShowDB;
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;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.CountTimeSlotListStatement;
Expand Down Expand Up @@ -1389,10 +1388,11 @@ public SettableFuture<ConfigTaskResult> showTTL(ShowTTLStatement showTTLStatemen
}

@Override
public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement showRegionStatement) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
public SettableFuture<ConfigTaskResult> showRegion(
final ShowRegionStatement showRegionStatement, final boolean isTableModel) {
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
TShowRegionResp showRegionResp = new TShowRegionResp();
TShowRegionReq showRegionReq = new TShowRegionReq();
final TShowRegionReq showRegionReq = new TShowRegionReq();
showRegionReq.setConsensusGroupType(showRegionStatement.getRegionType());
if (showRegionStatement.getStorageGroups() == null) {
showRegionReq.setDatabases(null);
Expand All @@ -1402,7 +1402,7 @@ public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement showRegio
.map(PartialPath::getFullPath)
.collect(Collectors.toList()));
}
try (ConfigNodeClient client =
try (final ConfigNodeClient client =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
showRegionResp = client.showRegion(showRegionReq);
if (showRegionResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
Expand All @@ -1411,7 +1411,7 @@ public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement showRegio
showRegionResp.getStatus().message, showRegionResp.getStatus().code));
return future;
}
} catch (ClientManagerException | TException e) {
} catch (final ClientManagerException | TException e) {
future.setException(e);
}

Expand All @@ -1428,7 +1428,7 @@ public SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement showRegio
}

// build TSBlock
ShowRegionTask.buildTSBlock(showRegionResp, future);
ShowRegionTask.buildTSBlock(showRegionResp, future, isTableModel);
return future;
}

Expand Down Expand Up @@ -2954,17 +2954,6 @@ public SettableFuture<ConfigTaskResult> showCluster(ShowCluster showCluster) {
return showCluster(treeStatement);
}

@Override
public SettableFuture<ConfigTaskResult> showRegions(ShowRegions showRegions) {
// As the implementation is identical, we'll simply translate to the
// corresponding tree-model variant and execute that.
ShowRegionStatement treeStatement = new ShowRegionStatement();
treeStatement.setRegionType(showRegions.getRegionType());
treeStatement.setStorageGroups(showRegions.getDatabases());
treeStatement.setNodeIds(showRegions.getNodeIds());
return showRegion(treeStatement);
}

@Override
public SettableFuture<ConfigTaskResult> useDatabase(Use useDB, IClientSession clientSession) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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.ShowDB;
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;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.CountTimeSlotListStatement;
Expand Down Expand Up @@ -154,7 +153,8 @@ public interface IConfigTaskExecutor {

SettableFuture<ConfigTaskResult> showTTL(ShowTTLStatement showTTLStatement);

SettableFuture<ConfigTaskResult> showRegion(ShowRegionStatement showRegionStatement);
SettableFuture<ConfigTaskResult> showRegion(
final ShowRegionStatement showRegionStatement, final boolean isTableModel);

SettableFuture<ConfigTaskResult> showDataNodes();

Expand Down Expand Up @@ -275,8 +275,6 @@ SettableFuture<ConfigTaskResult> createModel(

SettableFuture<ConfigTaskResult> showCluster(ShowCluster showCluster);

SettableFuture<ConfigTaskResult> showRegions(ShowRegions showRegions);

SettableFuture<ConfigTaskResult> useDatabase(final Use useDB, final IClientSession clientSession);

SettableFuture<ConfigTaskResult> dropDatabase(final DropDB dropDB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.iotdb.db.queryengine.plan.execution.config.metadata;

import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.confignode.rpc.thrift.TRegionInfo;
import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
import org.apache.iotdb.db.queryengine.common.header.ColumnHeader;
Expand Down Expand Up @@ -47,26 +48,30 @@
public class ShowRegionTask implements IConfigTask {

private final ShowRegionStatement showRegionStatement;
private final boolean isTableModel;

public ShowRegionTask(ShowRegionStatement showRegionStatement) {
public ShowRegionTask(final ShowRegionStatement showRegionStatement, final boolean isTableModel) {
this.showRegionStatement = showRegionStatement;
this.isTableModel = isTableModel;
}

@Override
public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor configTaskExecutor)
public ListenableFuture<ConfigTaskResult> execute(final IConfigTaskExecutor configTaskExecutor)
throws InterruptedException {
return configTaskExecutor.showRegion(showRegionStatement);
return configTaskExecutor.showRegion(showRegionStatement, isTableModel);
}

public static void buildTSBlock(
TShowRegionResp showRegionResp, SettableFuture<ConfigTaskResult> future) {
List<TSDataType> outputDataTypes =
final TShowRegionResp showRegionResp,
final SettableFuture<ConfigTaskResult> future,
final boolean isTableModel) {
final List<TSDataType> outputDataTypes =
ColumnHeaderConstant.showRegionColumnHeaders.stream()
.map(ColumnHeader::getColumnType)
.collect(Collectors.toList());
TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
final TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
if (showRegionResp.getRegionInfoList() != null) {
for (TRegionInfo regionInfo : showRegionResp.getRegionInfoList()) {
for (final TRegionInfo regionInfo : showRegionResp.getRegionInfoList()) {
builder.getTimeColumnBuilder().writeLong(0L);
builder.getColumnBuilder(0).writeInt(regionInfo.getConsensusGroupId().getId());
if (regionInfo.getConsensusGroupId().getType().ordinal()
Expand All @@ -84,7 +89,13 @@ public static void buildTSBlock(
.getColumnBuilder(2)
.writeBinary(
BytesUtils.valueOf(regionInfo.getStatus() == null ? "" : regionInfo.getStatus()));
builder.getColumnBuilder(3).writeBinary(BytesUtils.valueOf(regionInfo.getDatabase()));
builder
.getColumnBuilder(3)
.writeBinary(
BytesUtils.valueOf(
isTableModel
? PathUtils.unQualifyDatabaseName(regionInfo.getDatabase())
: regionInfo.getDatabase()));
builder.getColumnBuilder(4).writeInt(regionInfo.getSeriesSlots());
builder.getColumnBuilder(5).writeLong(regionInfo.getTimeSlots());
builder.getColumnBuilder(6).writeInt(regionInfo.getDataNodeId());
Expand All @@ -103,7 +114,7 @@ public static void buildTSBlock(
builder.declarePosition();
}
}
DatasetHeader datasetHeader = DatasetHeaderFactory.getShowRegionHeader();
final DatasetHeader datasetHeader = DatasetHeaderFactory.getShowRegionHeader();
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, builder.build(), datasetHeader));
}
}
Loading