Skip to content

Commit 484c821

Browse files
committed
Add table type to table disk usage
1 parent 7af3438 commit 484c821

4 files changed

Lines changed: 26 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: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ private static class TableDiskUsageSupplier implements IInformationSchemaContent
12711271
private final Filter pushDownFilter;
12721272
private final PaginationController paginationController;
12731273
private final OperatorContext operatorContext;
1274+
private final Map<String, String> currentTableTypeMap = new HashMap<>();
12741275

12751276
private DataRegion currentDataRegion;
12761277
private boolean currentDatabaseOnlyHasOneTable;
@@ -1347,6 +1348,7 @@ private boolean hasNextInternal() {
13471348
try {
13481349
while (dataRegionIterator.nextDataRegion()) {
13491350
currentDataRegion = dataRegionIterator.currentDataRegion();
1351+
currentTableTypeMap.clear();
13501352
for (Long timePartition : currentDataRegion.getTsFileManager().getTimePartitions()) {
13511353
Map<String, Long> tablesToScan = getTablesToScan(currentDataRegion, timePartition);
13521354
if (!tablesToScan.isEmpty()) {
@@ -1420,12 +1422,13 @@ private Map<String, Long> getTablesToScan(DataRegion dataRegion, long timePartit
14201422
}
14211423
totalValidTableCount++;
14221424
if (pushDownFilter != null) {
1423-
Object[] row = new Object[5];
1425+
Object[] row = new Object[6];
14241426
row[0] = new Binary(dataRegion.getDatabaseName(), TSFileConfig.STRING_CHARSET);
14251427
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;
1428+
row[2] = new Binary(getTableTypeName(tTableInfo), TSFileConfig.STRING_CHARSET);
1429+
row[3] = IoTDBDescriptor.getInstance().getConfig().getDataNodeId();
1430+
row[4] = dataRegion.getDataRegionId();
1431+
row[5] = timePartition;
14291432
if (!pushDownFilter.satisfyRow(0, row)) {
14301433
continue;
14311434
}
@@ -1439,11 +1442,19 @@ private Map<String, Long> getTablesToScan(DataRegion dataRegion, long timePartit
14391442
}
14401443
paginationController.consumeLimit();
14411444
tablesToScan.put(tTableInfo.getTableName(), 0L);
1445+
currentTableTypeMap.put(tTableInfo.getTableName(), getTableTypeName(tTableInfo));
14421446
}
14431447
currentDatabaseOnlyHasOneTable = totalValidTableCount == 1;
14441448
return tablesToScan;
14451449
}
14461450

1451+
private String getTableTypeName(final TTableInfo tableInfo) {
1452+
if (tableInfo.isSetType()) {
1453+
return TableType.values()[tableInfo.getType()].getName();
1454+
}
1455+
return TableType.BASE_TABLE.getName();
1456+
}
1457+
14471458
@Override
14481459
public TsBlock next() {
14491460
if (!hasNext()) {
@@ -1531,10 +1542,12 @@ private TsBlock buildTsBlock() {
15311542
columns[0].writeBinary(
15321543
new Binary(currentDataRegion.getDatabaseName(), TSFileConfig.STRING_CHARSET));
15331544
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);
1545+
columns[2].writeBinary(
1546+
new Binary(currentTableTypeMap.get(tableName), TSFileConfig.STRING_CHARSET));
1547+
columns[3].writeInt(IoTDBDescriptor.getInstance().getConfig().getDataNodeId());
1548+
columns[4].writeInt(currentDataRegion.getDataRegionId());
1549+
columns[5].writeLong(timePartition);
1550+
columns[6].writeLong(size);
15381551
builder.declarePosition();
15391552
}
15401553
}

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)