This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 198ba78 [Feature] Add update time to show table status (#6117) 198ba78 is described below commit 198ba785958871a3faa013a04a25031714732b74 Author: Zhengguo Yang <yangz...@gmail.com> AuthorDate: Wed Jul 7 10:27:14 2021 +0800 [Feature] Add update time to show table status (#6117) Add update time to show table status ``` MySQL [test_query_qa]> show table status; +----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-----------+----------+----------------+---------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | +----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-----------+----------+----------------+---------+ | bigtable | Doris | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2021-06-29 17:09:28 | 2021-06-29 17:17:28 | 1970-01-01 07:59:59 | utf-8 | NULL | NULL | OLAP | | test | Doris | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2021-06-29 17:09:26 | 2021-06-29 17:17:28 | 1970-01-01 07:59:59 | utf-8 | NULL | NULL | OLAP | | baseall | Doris | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2021-06-29 17:09:26 | 2021-06-29 17:17:26 | 1970-01-01 07:59:59 | utf-8 | NULL | NULL | OLAP | +----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-----------+----------+----------------+---------+ 3 rows in set (0.002 sec) ``` --- .../exec/schema_scanner/schema_tables_scanner.cpp | 48 +++++++++++++++++++--- .../java/org/apache/doris/catalog/OlapTable.java | 36 ++++++++++++++++ .../main/java/org/apache/doris/catalog/Table.java | 17 ++++++++ .../org/apache/doris/catalog/TempPartitions.java | 9 ++++ .../java/org/apache/doris/qe/ShowExecutor.java | 41 ++++++++++++++++-- .../apache/doris/service/FrontendServiceImpl.java | 6 +++ gensrc/thrift/FrontendService.thrift | 6 +++ 7 files changed, 154 insertions(+), 9 deletions(-) diff --git a/be/src/exec/schema_scanner/schema_tables_scanner.cpp b/be/src/exec/schema_scanner/schema_tables_scanner.cpp index 178424e..96e95a5 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<int64_t*>(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<int64_t*>(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<int64_t*>(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<DateTimeValue*>(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<StringValue*>(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 72b0d9c..478e076 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 class OlapTable extends Table { 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 class OlapTable extends Table { return tTableDescriptor; } + @Override public long getRowCount() { long rowCount = 0; for (Map.Entry<Long, Partition> entry : idToPartition.entrySet()) { @@ -931,6 +943,30 @@ public class OlapTable extends Table { } @Override + public long getAvgRowLength() { + long rowCount = 0; + long dataSize = 0; + for (Map.Entry<Long, Partition> 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<Long, Partition> 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 ec7e281..152b085 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 class Table extends MetaObject implements Writable { 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 b5fb03c..fc52513 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 class TempPartitions implements Writable, GsonPostProcessable { 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 bc2e8d4..e526b00 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 @@ -125,6 +125,7 @@ import org.apache.doris.common.util.LogKey; 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; @@ -631,16 +632,50 @@ public class ShowExecutor { PrivPredicate.SHOW)) { continue; } - List<String> 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 260a641..1bc16e7 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 class FrontendServiceImpl implements FrontendService.Iface { 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 8c1328a..9246392 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 { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org