Skip to content

Commit dcb630f

Browse files
authored
Add table type to table disk usage (#17768)
1 parent 7af3438 commit dcb630f

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/IoTDBShowDiskUsageTableIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void test1() {
8080
Map<String, Long> tableSizes = new HashMap<>();
8181
while (iterator.next()) {
8282
String table = iterator.getString("table_name");
83+
Assert.assertEquals("BASE TABLE", iterator.getString("table_type"));
8384
long timePartition = iterator.getLong("time_partition");
8485
long size = iterator.getLong("size_in_bytes");
8586
timePartitionSizes.compute(timePartition, (k, v) -> v == null ? size : v + size);

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ public void testInformationSchema() throws SQLException {
578578
Arrays.asList(
579579
"database,STRING,FIELD,",
580580
"table_name,STRING,FIELD,",
581+
"table_type,STRING,FIELD,",
581582
"datanode_id,INT32,FIELD,",
582583
"region_id,INT32,FIELD,",
583584
"time_partition,INT64,FIELD,",

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/InformationSchemaContentSupplierFactory.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,12 +1420,13 @@ private Map<String, Long> getTablesToScan(DataRegion dataRegion, long timePartit
14201420
}
14211421
totalValidTableCount++;
14221422
if (pushDownFilter != null) {
1423-
Object[] row = new Object[5];
1423+
Object[] row = new Object[6];
14241424
row[0] = new Binary(dataRegion.getDatabaseName(), TSFileConfig.STRING_CHARSET);
14251425
row[1] = new Binary(tTableInfo.getTableName(), TSFileConfig.STRING_CHARSET);
1426-
row[2] = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
1427-
row[3] = dataRegion.getDataRegionId();
1428-
row[4] = timePartition;
1426+
row[2] = new Binary(getTableTypeName(tTableInfo), TSFileConfig.STRING_CHARSET);
1427+
row[3] = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
1428+
row[4] = dataRegion.getDataRegionId();
1429+
row[5] = timePartition;
14291430
if (!pushDownFilter.satisfyRow(0, row)) {
14301431
continue;
14311432
}
@@ -1444,6 +1445,25 @@ private Map<String, Long> getTablesToScan(DataRegion dataRegion, long timePartit
14441445
return tablesToScan;
14451446
}
14461447

1448+
private String getTableTypeName(final TTableInfo tableInfo) {
1449+
if (tableInfo.isSetType()) {
1450+
return TableType.values()[tableInfo.getType()].getName();
1451+
}
1452+
return TableType.BASE_TABLE.getName();
1453+
}
1454+
1455+
private String getTableTypeName(final String databaseName, final String tableName) {
1456+
final List<TTableInfo> tableInfos = databaseTableInfoMap.get(databaseName);
1457+
if (tableInfos != null) {
1458+
for (TTableInfo tableInfo : tableInfos) {
1459+
if (tableName.equals(tableInfo.getTableName())) {
1460+
return getTableTypeName(tableInfo);
1461+
}
1462+
}
1463+
}
1464+
return TableType.BASE_TABLE.getName();
1465+
}
1466+
14471467
@Override
14481468
public TsBlock next() {
14491469
if (!hasNext()) {
@@ -1531,10 +1551,14 @@ private TsBlock buildTsBlock() {
15311551
columns[0].writeBinary(
15321552
new Binary(currentDataRegion.getDatabaseName(), TSFileConfig.STRING_CHARSET));
15331553
columns[1].writeBinary(new Binary(tableName, TSFileConfig.STRING_CHARSET));
1534-
columns[2].writeInt(IoTDBDescriptor.getInstance().getConfig().getDataNodeId());
1535-
columns[3].writeInt(currentDataRegion.getDataRegionId());
1536-
columns[4].writeLong(timePartition);
1537-
columns[5].writeLong(size);
1554+
columns[2].writeBinary(
1555+
new Binary(
1556+
getTableTypeName(currentDataRegion.getDatabaseName(), tableName),
1557+
TSFileConfig.STRING_CHARSET));
1558+
columns[3].writeInt(IoTDBDescriptor.getInstance().getConfig().getDataNodeId());
1559+
columns[4].writeInt(currentDataRegion.getDataRegionId());
1560+
columns[5].writeLong(timePartition);
1561+
columns[6].writeLong(size);
15381562
builder.declarePosition();
15391563
}
15401564
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/InformationSchema.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ public class InformationSchema {
356356
ColumnHeaderConstant.DATABASE.toLowerCase(Locale.ENGLISH), TSDataType.STRING));
357357
tableDiskUsageTable.addColumnSchema(
358358
new FieldColumnSchema(ColumnHeaderConstant.TABLE_NAME_TABLE_MODEL, TSDataType.STRING));
359+
tableDiskUsageTable.addColumnSchema(
360+
new FieldColumnSchema(ColumnHeaderConstant.TABLE_TYPE_TABLE_MODEL, TSDataType.STRING));
359361
tableDiskUsageTable.addColumnSchema(
360362
new FieldColumnSchema(ColumnHeaderConstant.DATA_NODE_ID_TABLE_MODEL, TSDataType.INT32));
361363
tableDiskUsageTable.addColumnSchema(
@@ -430,6 +432,7 @@ public class InformationSchema {
430432
ImmutableSet.of(
431433
ColumnHeaderConstant.DATABASE.toLowerCase(),
432434
ColumnHeaderConstant.TABLE_NAME_TABLE_MODEL,
435+
ColumnHeaderConstant.TABLE_TYPE_TABLE_MODEL,
433436
ColumnHeaderConstant.DATA_NODE_ID_TABLE_MODEL,
434437
ColumnHeaderConstant.REGION_ID_TABLE_MODEL,
435438
ColumnHeaderConstant.TIME_PARTITION_TABLE_MODEL));

0 commit comments

Comments
 (0)