Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions be/src/exec/schema_scanner/schema_tables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()); }
Expand All @@ -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;
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -922,6 +933,7 @@ public TTableDescriptor toThrift() {
return tTableDescriptor;
}

@Override
public long getRowCount() {
long rowCount = 0;
for (Map.Entry<Long, Partition> entry : idToPartition.entrySet()) {
Expand All @@ -930,6 +942,30 @@ public long getRowCount() {
return rowCount;
}

@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");
Expand Down
17 changes: 17 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 38 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -628,16 +629,50 @@ private void handleShowTableStatus() throws AnalysisException {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down