Skip to content

Commit 28812a1

Browse files
committed
describe table would list the column with pre-delete status
1 parent 46f21d2 commit 28812a1

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ public DescTableResp descTable(final DescTablePlan plan) {
14491449
}
14501450
return new DescTableResp(
14511451
StatusUtils.OK,
1452-
tableModelMTree.getUsingTableSchema(databasePath, plan.getTableName()),
1452+
tableModelMTree.getTableSchemaForDesc(databasePath, plan.getTableName()),
14531453
null,
14541454
null);
14551455
} catch (final MetadataException e) {

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,36 @@ public TsTable getUsingTableSchema(final PartialPath database, final String tabl
10881088
return newTable;
10891089
}
10901090

1091+
/**
1092+
* The schema to report in DESC. Unlike {@link #getUsingTableSchema}, a column whose deletion is
1093+
* still pending is kept, so that the user can see which columns exist and are only waiting for
1094+
* the pending procedure. A pending data type change is applied on top.
1095+
*/
1096+
public TsTable getTableSchemaForDesc(final PartialPath database, final String tableName)
1097+
throws MetadataException {
1098+
final ConfigTableNode node = getTableNode(database, tableName);
1099+
if (node.getPreAlteredColumns().isEmpty()) {
1100+
return node.getTable();
1101+
}
1102+
final TsTable table = new TsTable(node.getTable());
1103+
node.getPreAlteredColumns()
1104+
.forEach(
1105+
(columnName, dataType) -> {
1106+
final TsTableColumnSchema columnSchema = table.getColumnSchema(columnName);
1107+
if (columnSchema == null) {
1108+
return;
1109+
}
1110+
columnSchema.setDataType(dataType);
1111+
if (columnSchema instanceof FieldColumnSchema) {
1112+
final FieldColumnSchema fieldColumnSchema = (FieldColumnSchema) columnSchema;
1113+
fieldColumnSchema.setEncoding(
1114+
SchemaUtils.getDataTypeCompatibleEncoding(
1115+
dataType, fieldColumnSchema.getEncoding()));
1116+
}
1117+
});
1118+
return table;
1119+
}
1120+
10911121
public TableSchemaDetails getTableSchemaDetails(
10921122
final PartialPath database, final String tableName) throws MetadataException {
10931123
final ConfigTableNode node = getTableNode(database, tableName);

‎iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTreeTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,37 @@ public void testAlterColumnTypeUpdatesCompatibleEncoding() throws Exception {
453453
root.getTableSchemaDetails(database, table.getTableName()).preAlteredColumns.isEmpty());
454454
}
455455

456+
@Test
457+
public void testDescKeepsPreDeletedColumns() throws Exception {
458+
root = new ConfigMTree(true);
459+
460+
final PartialPath database = new PartialPath("root.sg");
461+
root.setStorageGroup(database);
462+
final IDatabaseMNode<IConfigMNode> databaseNode = root.getDatabaseNodeByDatabasePath(database);
463+
databaseNode
464+
.getAsMNode()
465+
.getDatabaseSchema()
466+
.setName(PathUtils.unQualifyDatabaseName(database.getFullPath()));
467+
databaseNode.getAsMNode().getDatabaseSchema().setIsTableModel(true);
468+
469+
final TsTable table = new TsTable("table1");
470+
table.addColumnSchema(new TagColumnSchema("id", TSDataType.STRING));
471+
table.addColumnSchema(
472+
new FieldColumnSchema(
473+
"measurement", TSDataType.DOUBLE, TSEncoding.GORILLA, CompressionType.SNAPPY));
474+
root.preCreateTable(database, table);
475+
root.commitCreateTable(database, table.getTableName());
476+
477+
root.preDeleteColumn(database, table.getTableName(), "measurement", false);
478+
479+
// DESC keeps a column whose deletion is still pending, so that the user can see it.
480+
Assert.assertNotNull(
481+
root.getTableSchemaForDesc(database, table.getTableName()).getColumnSchema("measurement"));
482+
// A DataNode must not see that column any more.
483+
Assert.assertNull(
484+
root.getUsingTableSchema(database, table.getTableName()).getColumnSchema("measurement"));
485+
}
486+
456487
@Test
457488
public void testSetTemplate() throws MetadataException {
458489
root.setStorageGroup(new PartialPath("root.a"));

0 commit comments

Comments
 (0)