Skip to content

Commit

Permalink
partial
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi committed Jan 21, 2025
1 parent 619e1f6 commit cad5062
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RollbackCreateTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
Expand Down Expand Up @@ -374,6 +375,9 @@ public static ConfigPhysicalPlan create(final ByteBuffer buffer) throws IOExcept
case CommitDeleteColumn:
plan = new CommitDeleteColumnPlan();
break;
case SetTableComment:
plan = new SetTableCommentPlan();
break;
case SetTableColumnComment:
plan = new SetTableColumnCommentPlan();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public enum ConfigPhysicalPlanType {
ShowTable4InformationSchema((short) 863),
DescTable4InformationSchema((short) 864),
SetTableColumnComment((short) 865),
SetTableComment((short) 866),

/** Deprecated types for sync, restored them for upgrade. */
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.CommitDeleteTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
Expand Down Expand Up @@ -105,6 +106,8 @@ public R process(final ConfigPhysicalPlan plan, final C context) {
return visitCommitDeleteTable((CommitDeleteTablePlan) plan, context);
case PipeDeleteDevices:
return visitPipeDeleteDevices((PipeDeleteDevicesPlan) plan, context);
case SetTableComment:
return visitSetTableComment((SetTableCommentPlan) plan, context);
case SetTableColumnComment:
return visitSetTableColumnComment((SetTableColumnCommentPlan) plan, context);
default:
Expand Down Expand Up @@ -252,6 +255,10 @@ public R visitPipeDeleteDevices(
return visitPlan(pipeDeleteDevicesPlan, context);
}

public R visitSetTableComment(final SetTableCommentPlan setTableCommentPlan, final C context) {
return visitPlan(setTableCommentPlan, context);
}

public R visitSetTableColumnComment(
final SetTableColumnCommentPlan setTableColumnCommentPlan, final C context) {
return visitPlan(setTableColumnCommentPlan, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.confignode.consensus.request.write.table;

import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;

import org.apache.tsfile.utils.ReadWriteIOUtils;

import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

public class SetTableCommentPlan extends AbstractTablePlan {
private String comment;

public SetTableCommentPlan() {
super(ConfigPhysicalPlanType.SetTableComment);
}

public SetTableCommentPlan(final String database, final String tableName, final String comment) {
super(ConfigPhysicalPlanType.SetTableComment, database, tableName);
this.comment = comment;
}

public String getComment() {
return comment;
}

@Override
protected void serializeImpl(final DataOutputStream stream) throws IOException {
super.serializeImpl(stream);
ReadWriteIOUtils.write(comment, stream);
}

@Override
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
super.deserializeImpl(buffer);
this.comment = ReadWriteIOUtils.readString(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,12 @@ public TSStatus alterOrDropTable(final TAlterOrDropTableReq req) {
return procedureManager.alterTableDropColumn(req);
case DROP_TABLE:
return procedureManager.dropTable(req);
case COMMENT_TABLE:
return clusterSchemaManager.setTableComment(
req.getDatabase(),
req.getTableName(),
ReadWriteIOUtils.readString(req.updateInfo),
false);
case COMMENT_COLUMN:
return clusterSchemaManager.setTableColumnComment(
req.getDatabase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class ConfigRegionListeningFilter {
Collections.unmodifiableList(
Arrays.asList(
ConfigPhysicalPlanType.SetTableProperties,
ConfigPhysicalPlanType.SetTableComment,
ConfigPhysicalPlanType.SetTableColumnComment)));
OPTION_PLAN_MAP.put(
new PartialPath("schema.table.drop"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.CommitDeleteTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
Expand Down Expand Up @@ -376,6 +377,12 @@ public TSStatus visitPipeDeleteDevices(
return visitCommonTablePlan(pipeDeleteDevicesPlan, context);
}

@Override
public TSStatus visitSetTableComment(
final SetTableCommentPlan setTableCommentPlan, final TSStatus context) {
return visitCommonTablePlan(setTableCommentPlan, context);
}

@Override
public TSStatus visitSetTableColumnComment(
final SetTableColumnCommentPlan setTableColumnCommentPlan, final TSStatus context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.AddTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.DropSchemaTemplatePlan;
Expand Down Expand Up @@ -1344,6 +1345,23 @@ public synchronized TSStatus setTableProperties(
}
}

public synchronized TSStatus setTableComment(
final String database,
final String tableName,
final String comment,
final boolean isGeneratedByPipe) {
final SetTableCommentPlan setTableCommentPlan =
new SetTableCommentPlan(database, tableName, comment);
try {
return getConsensusManager()
.write(
isGeneratedByPipe ? new PipeEnrichedPlan(setTableCommentPlan) : setTableCommentPlan);
} catch (final ConsensusException e) {
LOGGER.warn(e.getMessage(), e);
return RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage());
}
}

public synchronized TSStatus setTableColumnComment(
final String database,
final String tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RollbackCreateTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
Expand Down Expand Up @@ -546,6 +547,8 @@ public TSStatus executeNonQueryPlan(ConfigPhysicalPlan physicalPlan)
return clusterSchemaInfo.preDeleteTable((PreDeleteTablePlan) physicalPlan);
case CommitDeleteTable:
return clusterSchemaInfo.dropTable((CommitDeleteTablePlan) physicalPlan);
case SetTableComment:
return clusterSchemaInfo.setTableComment((SetTableCommentPlan) physicalPlan);
case SetTableColumnComment:
return clusterSchemaInfo.setTableColumnComment((SetTableColumnCommentPlan) physicalPlan);
case CreatePipeV2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.RollbackCreateTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
Expand Down Expand Up @@ -1167,6 +1168,21 @@ public TSStatus dropTable(final CommitDeleteTablePlan plan) {
}
}

public TSStatus setTableComment(final SetTableCommentPlan plan) {
databaseReadWriteLock.writeLock().lock();
try {
tableModelMTree.setTableComment(
getQualifiedDatabasePartialPath(plan.getDatabase()),
plan.getTableName(),
plan.getComment());
return RpcUtils.SUCCESS_STATUS;
} catch (final MetadataException e) {
return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
} finally {
databaseReadWriteLock.writeLock().unlock();
}
}

public TSStatus setTableColumnComment(final SetTableColumnCommentPlan plan) {
databaseReadWriteLock.writeLock().lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,17 @@ public void dropTable(final PartialPath database, final String tableName)
store.deleteChild(databaseNode, tableName);
}

public void setTableComment(
final PartialPath database, final String tableName, final String comment)
throws MetadataException {
final TsTable table = getTable(database, tableName);
if (Objects.nonNull(comment)) {
table.addProp(TsTable.COMMENT_KEY, comment);
} else {
table.removeProp(TsTable.COMMENT_KEY);
}
}

public void setTableColumnComment(
final PartialPath database,
final String tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetColumnComment;
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.SetTableComment;
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.ShowClusterId;
Expand Down Expand Up @@ -396,6 +397,7 @@ private IQueryExecution createQueryExecutionForTableModel(
|| statement instanceof SetProperties
|| statement instanceof DropColumn
|| statement instanceof DropTable
|| statement instanceof SetTableComment
|| statement instanceof SetColumnComment
|| statement instanceof DeleteDevice
|| statement instanceof ShowCluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterDBTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableAddColumnTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableCommentColumnTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableCommentTableTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableDropColumnTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableRenameColumnTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.relational.AlterTableRenameTableTask;
Expand Down Expand Up @@ -127,6 +128,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SetColumnComment;
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.SetTableComment;
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.ShowClusterId;
Expand Down Expand Up @@ -568,6 +570,22 @@ protected IConfigTask visitSetProperties(
node.ifExists());
}

@Override
protected IConfigTask visitSetTableComment(
final SetTableComment node, final MPPQueryContext context) {
context.setQueryType(QueryType.WRITE);
final Pair<String, String> databaseTablePair = splitQualifiedName(node.getTableName(), true);
final String database = databaseTablePair.getLeft();
final String tableName = databaseTablePair.getRight();

accessControl.checkCanAlterTable(
context.getSession().getUserName(), new QualifiedObjectName(database, tableName));

return new AlterTableCommentTableTask(
database, tableName, context.getQueryId().getId(), node.ifExists(), node.getComment());
}

@Override
protected IConfigTask visitSetColumnComment(
final SetColumnComment node, final MPPQueryContext context) {
context.setQueryType(QueryType.WRITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,46 @@ public SettableFuture<ConfigTaskResult> alterTableSetProperties(
return future;
}

@Override
public SettableFuture<ConfigTaskResult> alterTableCommentTable(
final String database,
final String tableName,
final String queryId,
final boolean ifExists,
final String comment) {
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
try (final ConfigNodeClient client =
CLUSTER_DELETION_CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {

final ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
ReadWriteIOUtils.write(comment, stream);
} catch (final IOException ignored) {
// ByteArrayOutputStream won't throw IOException
}

final TSStatus tsStatus =
sendAlterReq2ConfigNode(
database,
tableName,
queryId,
AlterOrDropTableOperationType.COMMENT_TABLE,
stream.toByteArray(),
client);

if (TSStatusCode.SUCCESS_STATUS.getStatusCode() == tsStatus.getCode()
|| TSStatusCode.TABLE_NOT_EXISTS.getStatusCode() == tsStatus.getCode() && ifExists) {
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
} else {
future.setException(
new IoTDBException(getTableErrorMessage(tsStatus, database), tsStatus.getCode()));
}
} catch (final ClientManagerException | TException e) {
future.setException(e);
}
return future;
}

@Override
public SettableFuture<ConfigTaskResult> alterTableCommentColumn(
final String database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ SettableFuture<ConfigTaskResult> alterTableSetProperties(
final String queryId,
final boolean ifExists);

SettableFuture<ConfigTaskResult> alterTableCommentTable(
final String database,
final String tableName,
final String queryId,
final boolean ifExists,
final String comment);

SettableFuture<ConfigTaskResult> alterTableCommentColumn(
final String database,
final String tableName,
Expand Down
Loading

0 comments on commit cad5062

Please sign in to comment.