diff --git a/be/src/exec/schema_scanner/schema_tables_scanner.cpp b/be/src/exec/schema_scanner/schema_tables_scanner.cpp index 178424e86fe1b3..96e95a5b8ff765 100644 --- a/be/src/exec/schema_scanner/schema_tables_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_tables_scanner.cpp @@ -143,12 +143,26 @@ Status SchemaTablesScanner::fill_one_row(Tuple* tuple, MemPool* pool) { // row_format { tuple->set_null(_tuple_desc->slots()[6]->null_indicator_offset()); } // rows - { tuple->set_null(_tuple_desc->slots()[7]->null_indicator_offset()); } + if (tbl_status.__isset.rows) { + void* slot = tuple->get_slot(_tuple_desc->slots()[7]->tuple_offset()); + *(reinterpret_cast(slot)) = tbl_status.rows; + } else { + tuple->set_null(_tuple_desc->slots()[7]->null_indicator_offset()); + } // avg_row_length - { tuple->set_null(_tuple_desc->slots()[8]->null_indicator_offset()); } + if (tbl_status.__isset.avg_row_length) { + void* slot = tuple->get_slot(_tuple_desc->slots()[8]->tuple_offset()); + *(reinterpret_cast(slot)) = tbl_status.avg_row_length; + } else { + tuple->set_null(_tuple_desc->slots()[8]->null_indicator_offset()); + } // data_length - { tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset()); } - // max_data_length + if (tbl_status.__isset.avg_row_length) { + void* slot = tuple->get_slot(_tuple_desc->slots()[9]->tuple_offset()); + *(reinterpret_cast(slot)) = tbl_status.data_length; + } else { + tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset()); + } // max_data_length { tuple->set_null(_tuple_desc->slots()[10]->null_indicator_offset()); } // index_length { tuple->set_null(_tuple_desc->slots()[11]->null_indicator_offset()); } @@ -169,7 +183,17 @@ Status SchemaTablesScanner::fill_one_row(Tuple* tuple, MemPool* pool) { } } // update_time - { tuple->set_null(_tuple_desc->slots()[15]->null_indicator_offset()); } + if (tbl_status.__isset.update_time) { + int64_t update_time = tbl_status.update_time; + if (update_time <= 0) { + tuple->set_null(_tuple_desc->slots()[15]->null_indicator_offset()); + } else { + tuple->set_not_null(_tuple_desc->slots()[15]->null_indicator_offset()); + void* slot = tuple->get_slot(_tuple_desc->slots()[15]->tuple_offset()); + DateTimeValue* time_slot = reinterpret_cast(slot); + time_slot->from_unixtime(update_time, TimezoneUtils::default_time_zone); + } + } // check_time if (tbl_status.__isset.last_check_time) { int64_t check_time = tbl_status.last_check_time; @@ -183,7 +207,19 @@ Status SchemaTablesScanner::fill_one_row(Tuple* tuple, MemPool* pool) { } } // collation - { tuple->set_null(_tuple_desc->slots()[17]->null_indicator_offset()); } + if (tbl_status.__isset.collation) { + void* slot = tuple->get_slot(_tuple_desc->slots()[17]->tuple_offset()); + StringValue* str_slot = reinterpret_cast(slot); + const std::string* src = &tbl_status.collation; + str_slot->len = src->length(); + str_slot->ptr = (char*)pool->allocate(str_slot->len); + if (NULL == str_slot->ptr) { + return Status::InternalError("Allocate memcpy failed."); + } + memcpy(str_slot->ptr, src->c_str(), str_slot->len); + } else { + tuple->set_null(_tuple_desc->slots()[17]->null_indicator_offset()); + } // checksum { tuple->set_null(_tuple_desc->slots()[18]->null_indicator_offset()); } // create_options diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index 72b0d9cb0ae8fe..478e07622586ef 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -387,6 +387,17 @@ public Column getVisibleColumn(String columnName) { return null; } + @Override + public long getUpdateTime() { + long updateTime = tempPartitions.getUpdateTime(); + for (Partition p : idToPartition.values()) { + if (p.getVisibleVersionTime() > updateTime) { + updateTime = p.getVisibleVersionTime(); + } + } + return updateTime; + } + // this is only for schema change. public void renameIndexForSchemaChange(String name, String newName) { long idxId = indexNameToId.remove(name); @@ -922,6 +933,7 @@ public TTableDescriptor toThrift() { return tTableDescriptor; } + @Override public long getRowCount() { long rowCount = 0; for (Map.Entry entry : idToPartition.entrySet()) { @@ -930,6 +942,30 @@ public long getRowCount() { return rowCount; } + @Override + public long getAvgRowLength() { + long rowCount = 0; + long dataSize = 0; + for (Map.Entry entry : idToPartition.entrySet()) { + rowCount += entry.getValue().getBaseIndex().getRowCount(); + dataSize += entry.getValue().getBaseIndex().getDataSize(); + } + if (rowCount > 0) { + return dataSize / rowCount; + } else { + return 0; + } + } + + @Override + public long getDataLength() { + long dataSize = 0; + for (Map.Entry entry : idToPartition.entrySet()) { + dataSize += entry.getValue().getBaseIndex().getDataSize(); + } + return dataSize; + } + @Override public CreateTableStmt toCreateTableStmt(String dbName) { throw new RuntimeException("Don't support anymore"); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java index ec7e2813418ba4..152b0859d38e4c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java @@ -232,6 +232,23 @@ public long getCreateTime() { return createTime; } + public long getUpdateTime() { + return -1L; + } + + public long getRowCount() { + return 0; + } + + public long getAvgRowLength() { + return 0; + } + + public long getDataLength() { + return 0; + } + + public TTableDescriptor toThrift() { return null; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TempPartitions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TempPartitions.java index b5fb03c87454d9..fc5251336a41ea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TempPartitions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TempPartitions.java @@ -57,6 +57,15 @@ public void addPartition(Partition partition) { idToPartition.put(partition.getId(), partition); nameToPartition.put(partition.getName(), partition); } + public long getUpdateTime() { + long updateTime = -1l; + for (Partition p : idToPartition.values()) { + if (p.getVisibleVersionTime() > updateTime) { + updateTime = p.getVisibleVersionTime(); + } + } + return updateTime; + } /* * Drop temp partitions. diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java index 42e035c800b6f7..cf3090b0656698 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java @@ -124,6 +124,7 @@ import org.apache.doris.common.util.OrderByPair; import org.apache.doris.common.util.ProfileManager; import org.apache.doris.common.util.RuntimeProfile; +import org.apache.doris.common.util.TimeUtils; import org.apache.doris.load.DeleteHandler; import org.apache.doris.load.ExportJob; import org.apache.doris.load.ExportMgr; @@ -628,16 +629,50 @@ private void handleShowTableStatus() throws AnalysisException { PrivPredicate.SHOW)) { continue; } - List row = Lists.newArrayList(); // Name row.add(table.getName()); // Engine row.add(table.getEngine()); - // version, ra - for (int i = 0; i < 15; ++i) { + // version + row.add(null); + // Row_format + row.add(null); + // Rows + row.add(String.valueOf(table.getRowCount())); + // Avg_row_length + row.add(String.valueOf(table.getAvgRowLength())); + // Data_length + row.add(String.valueOf(table.getDataLength())); + // Max_data_length + row.add(null); + // Index_length + row.add(null); + // Data_free + row.add(null); + // Auto_increment + row.add(null); + // Create_time + row.add(TimeUtils.longToTimeString(table.getCreateTime() * 1000)); + // Update_time + if (table.getUpdateTime() > 0) { + row.add(TimeUtils.longToTimeString(table.getUpdateTime())); + } else { + row.add(null); + } + // Check_time + if (table.getLastCheckTime() > 0) { + row.add(TimeUtils.longToTimeString(table.getLastCheckTime() * 1000)); + } else { row.add(null); } + // Collation + row.add("utf-8"); + // Checksum + row.add(null); + // Create_options + row.add(null); + row.add(table.getComment()); rows.add(row); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java index 260a64108a1139..1bc16e71402b28 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java +++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java @@ -285,6 +285,12 @@ public TListTableStatusResult listTableStatus(TGetTablesParams params) throws TE status.setComment(table.getComment()); status.setCreateTime(table.getCreateTime()); status.setLastCheckTime(table.getLastCheckTime()); + status.setUpdateTime(table.getUpdateTime()/1000); + status.setCheckTime(table.getLastCheckTime()); + status.setCollation("utf-8"); + status.setRows(table.getRowCount()); + status.setDataLength(table.getDataLength()); + status.setAvgRowLength(table.getAvgRowLength()); tablesResult.add(status); } finally { table.readUnlock(); diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index 8c1328a1f22c4b..92463922740842 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -314,6 +314,12 @@ struct TTableStatus { 5: optional i64 last_check_time 6: optional i64 create_time 7: optional string ddl_sql + 8: optional i64 update_time + 9: optional i64 check_time + 10: optional string collation + 11: optional i64 rows; + 12: optional i64 avg_row_length + 13: optional i64 data_length; } struct TListTableStatusResult {