Skip to content

Commit

Permalink
Refactor alter table framework & Support Drop table schema & Support …
Browse files Browse the repository at this point in the history
…show tables details
  • Loading branch information
Caideyipi authored Oct 18, 2024
1 parent a613422 commit 7400e1b
Show file tree
Hide file tree
Showing 108 changed files with 3,286 additions and 890 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.relational.it.schema;

import org.apache.iotdb.db.it.utils.TestUtils;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
Expand All @@ -36,6 +37,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;

import static org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant.describeTableColumnHeaders;
import static org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant.showTablesColumnHeaders;
Expand Down Expand Up @@ -368,6 +370,22 @@ public void testManageTable() {
assertEquals(columnNames.length, cnt);
}

statement.execute(
"insert into table2(region_id, plant_id, color, temperature, speed) values(1, 1, 1, 1, 1)");
statement.execute("drop table table2");
try {
statement.executeQuery("describe table2");
fail();
} catch (final SQLException e) {
assertEquals("550: Table 'test2.table2' does not exist.", e.getMessage());
}
statement.execute(
"create table table2(region_id STRING ID, plant_id STRING ID, color STRING ATTRIBUTE, temperature FLOAT MEASUREMENT, speed DOUBLE MEASUREMENT)");
TestUtils.assertResultSetEqual(
statement.executeQuery("count devices from table2"),
"count(devices),",
Collections.singleton("0,"));

try {
statement.executeQuery("describe test3.table3");
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ public enum CnToDnAsyncRequestType {

// Table
UPDATE_TABLE,
INVALIDATE_TABLE_CACHE,
DELETE_DATA_FOR_DROP_TABLE,
DELETE_DEVICES_FOR_DROP_TABLE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.iotdb.mpp.rpc.thrift.TCreateTriggerInstanceReq;
import org.apache.iotdb.mpp.rpc.thrift.TDeactivateTemplateReq;
import org.apache.iotdb.mpp.rpc.thrift.TDeleteDataForDeleteSchemaReq;
import org.apache.iotdb.mpp.rpc.thrift.TDeleteDataOrDevicesForDropTableReq;
import org.apache.iotdb.mpp.rpc.thrift.TDeleteTimeSeriesReq;
import org.apache.iotdb.mpp.rpc.thrift.TDeleteViewSchemaReq;
import org.apache.iotdb.mpp.rpc.thrift.TDropFunctionInstanceReq;
Expand All @@ -71,6 +72,7 @@
import org.apache.iotdb.mpp.rpc.thrift.TInactiveTriggerInstanceReq;
import org.apache.iotdb.mpp.rpc.thrift.TInvalidateCacheReq;
import org.apache.iotdb.mpp.rpc.thrift.TInvalidateMatchedSchemaCacheReq;
import org.apache.iotdb.mpp.rpc.thrift.TInvalidateTableCacheReq;
import org.apache.iotdb.mpp.rpc.thrift.TPipeHeartbeatReq;
import org.apache.iotdb.mpp.rpc.thrift.TPushConsumerGroupMetaReq;
import org.apache.iotdb.mpp.rpc.thrift.TPushMultiPipeMetaReq;
Expand Down Expand Up @@ -375,6 +377,21 @@ protected void initActionMapBuilder() {
CnToDnAsyncRequestType.UPDATE_TABLE,
(req, client, handler) ->
client.updateTable((TUpdateTableReq) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.INVALIDATE_TABLE_CACHE,
(req, client, handler) ->
client.invalidateTableCache(
(TInvalidateTableCacheReq) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.DELETE_DATA_FOR_DROP_TABLE,
(req, client, handler) ->
client.deleteDataForDropTable(
(TDeleteDataOrDevicesForDropTableReq) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.DELETE_DEVICES_FOR_DROP_TABLE,
(req, client, handler) ->
client.deleteDevicesForDropTable(
(TDeleteDataOrDevicesForDropTableReq) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.CLEAN_DATA_NODE_CACHE,
(req, client, handler) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
import org.apache.iotdb.confignode.consensus.request.write.sync.SetPipeStatusPlanV1;
import org.apache.iotdb.confignode.consensus.request.write.table.AddTableColumnPlan;
import org.apache.iotdb.confignode.consensus.request.write.table.CommitCreateTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.DropTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.PreCreateTablePlan;
import org.apache.iotdb.confignode.consensus.request.write.table.PreDeleteTablePlan;
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.SetTablePropertiesPlan;
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
Expand Down Expand Up @@ -343,6 +346,15 @@ public static ConfigPhysicalPlan create(final ByteBuffer buffer) throws IOExcept
case SetTableProperties:
plan = new SetTablePropertiesPlan();
break;
case RenameTableColumn:
plan = new RenameTableColumnPlan();
break;
case PreDeleteTable:
plan = new PreDeleteTablePlan();
break;
case DropTable:
plan = new DropTablePlan();
break;
case CreatePipeSinkV1:
plan = new CreatePipeSinkPlanV1();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public enum ConfigPhysicalPlanType {
SetTableProperties((short) 854),
ShowTable((short) 855),
FetchTable((short) 856),
RenameTableColumn((short) 857),
PreDeleteTable((short) 858),
DropTable((short) 859),

/** Deprecated types for sync, restored them for upgrade. */
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ public class ShowTablePlan extends ConfigPhysicalReadPlan {

private final String database;

public ShowTablePlan(final String database) {
private final boolean isDetails;

public ShowTablePlan(final String database, final boolean isDetails) {
super(ConfigPhysicalPlanType.ShowTable);
this.database = database;
this.isDetails = isDetails;
}

public String getDatabase() {
return database;
}

public boolean isDetails() {
return isDetails;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.ConfigPhysicalPlan;
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;

abstract class AbstractTablePlan extends ConfigPhysicalPlan {

private String database;

private String tableName;

protected AbstractTablePlan(final ConfigPhysicalPlanType type) {
super(type);
}

protected AbstractTablePlan(
final ConfigPhysicalPlanType type, final String database, final String tableName) {
super(type);
this.database = database;
this.tableName = tableName;
}

public String getDatabase() {
return database;
}

public String getTableName() {
return tableName;
}

@Override
protected void serializeImpl(final DataOutputStream stream) throws IOException {
stream.writeShort(getType().getPlanType());

ReadWriteIOUtils.write(database, stream);
ReadWriteIOUtils.write(tableName, stream);
}

@Override
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
this.database = ReadWriteIOUtils.readString(buffer);
this.tableName = ReadWriteIOUtils.readString(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchemaUtil;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;

import org.apache.tsfile.utils.ReadWriteIOUtils;
Expand All @@ -31,11 +30,7 @@
import java.nio.ByteBuffer;
import java.util.List;

public class AddTableColumnPlan extends ConfigPhysicalPlan {

private String database;

private String tableName;
public class AddTableColumnPlan extends AbstractTablePlan {

private List<TsTableColumnSchema> columnSchemaList;

Expand All @@ -46,25 +41,15 @@ public AddTableColumnPlan() {
}

public AddTableColumnPlan(
String database,
String tableName,
List<TsTableColumnSchema> columnSchemaList,
boolean isRollback) {
super(ConfigPhysicalPlanType.AddTableColumn);
this.database = database;
this.tableName = tableName;
final String database,
final String tableName,
final List<TsTableColumnSchema> columnSchemaList,
final boolean isRollback) {
super(ConfigPhysicalPlanType.AddTableColumn, database, tableName);
this.columnSchemaList = columnSchemaList;
this.isRollback = isRollback;
}

public String getDatabase() {
return database;
}

public String getTableName() {
return tableName;
}

public List<TsTableColumnSchema> getColumnSchemaList() {
return columnSchemaList;
}
Expand All @@ -74,19 +59,15 @@ public boolean isRollback() {
}

@Override
protected void serializeImpl(DataOutputStream stream) throws IOException {
stream.writeShort(getType().getPlanType());

ReadWriteIOUtils.write(database, stream);
ReadWriteIOUtils.write(tableName, stream);
protected void serializeImpl(final DataOutputStream stream) throws IOException {
super.serializeImpl(stream);
TsTableColumnSchemaUtil.serialize(columnSchemaList, stream);
ReadWriteIOUtils.write(isRollback, stream);
}

@Override
protected void deserializeImpl(ByteBuffer buffer) throws IOException {
this.database = ReadWriteIOUtils.readString(buffer);
this.tableName = ReadWriteIOUtils.readString(buffer);
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
super.deserializeImpl(buffer);
this.columnSchemaList = TsTableColumnSchemaUtil.deserializeColumnSchemaList(buffer);
this.isRollback = ReadWriteIOUtils.readBool(buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,15 @@

package org.apache.iotdb.confignode.consensus.request.write.table;

import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
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 CommitCreateTablePlan extends ConfigPhysicalPlan {

private String database;

private String tableName;
public class CommitCreateTablePlan extends AbstractTablePlan {

public CommitCreateTablePlan() {
super(ConfigPhysicalPlanType.CommitCreateTable);
}

public CommitCreateTablePlan(String database, String tableName) {
super(ConfigPhysicalPlanType.CommitCreateTable);
this.database = database;
this.tableName = tableName;
}

public String getDatabase() {
return database;
}

public String getTableName() {
return tableName;
}

@Override
protected void serializeImpl(DataOutputStream stream) throws IOException {
stream.writeShort(getType().getPlanType());
ReadWriteIOUtils.write(database, stream);
ReadWriteIOUtils.write(tableName, stream);
}

@Override
protected void deserializeImpl(ByteBuffer buffer) throws IOException {
this.database = ReadWriteIOUtils.readString(buffer);
this.tableName = ReadWriteIOUtils.readString(buffer);
public CommitCreateTablePlan(final String database, final String tableName) {
super(ConfigPhysicalPlanType.CommitCreateTable, database, tableName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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;

public class DropTablePlan extends AbstractTablePlan {
public DropTablePlan() {
super(ConfigPhysicalPlanType.DropTable);
}

public DropTablePlan(final String database, final String tableName) {
super(ConfigPhysicalPlanType.DropTable, database, tableName);
}
}
Loading

0 comments on commit 7400e1b

Please sign in to comment.