Skip to content

Commit

Permalink
fe schema
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
  • Loading branch information
murphyatwork committed Nov 22, 2024
1 parent dcf8ac9 commit f12d4f5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.starrocks.catalog.system.SystemId;
import com.starrocks.catalog.system.SystemTable;
import com.starrocks.common.Pair;
import com.starrocks.common.util.DateUtils;
import com.starrocks.sql.optimizer.Utils;
import com.starrocks.sql.optimizer.operator.scalar.BinaryPredicateOperator;
import com.starrocks.sql.optimizer.operator.scalar.ColumnRefOperator;
Expand All @@ -30,6 +31,9 @@
import com.starrocks.statistic.columns.ColumnFullId;
import com.starrocks.statistic.columns.ColumnUsage;
import com.starrocks.statistic.columns.PredicateColumnsMgr;
import com.starrocks.thrift.TColumnStatsUsage;
import com.starrocks.thrift.TColumnStatsUsageReq;
import com.starrocks.thrift.TColumnStatsUsageRes;
import com.starrocks.thrift.TSchemaTableType;
import org.apache.commons.lang3.NotImplementedException;

Expand Down Expand Up @@ -99,6 +103,16 @@ public List<List<ScalarOperator>> evaluate(ScalarOperator predicate) {
.collect(Collectors.toList());
}

public static TColumnStatsUsageRes query(TColumnStatsUsageReq req) {
TableName tableName = new TableName(req.getTable_catalog(), req.getTable_database(), req.getTable_name());
List<ColumnUsage> columnStatsUsages = PredicateColumnsMgr.getInstance().query(tableName);
TColumnStatsUsageRes res = new TColumnStatsUsageRes();
res.setItems(columnStatsUsages.stream()
.map(ColumnStatsUsageSystemTable::columnUsageToThrift)
.collect(Collectors.toList()));
return null;
}

private static List<ScalarOperator> columnUsageToScalar(ColumnUsage columnUsage) {
ColumnFullId columnFullId = columnUsage.getColumnFullId();
Optional<Pair<TableName, ColumnId>> names = columnFullId.toNames();
Expand All @@ -112,4 +126,20 @@ private static List<ScalarOperator> columnUsageToScalar(ColumnUsage columnUsage)
result.add(ConstantOperator.createDatetime(columnUsage.getCreated()));
return result;
}

private static TColumnStatsUsage columnUsageToThrift(ColumnUsage columnUsage) {
TColumnStatsUsage thriftUsage = new TColumnStatsUsage();
ColumnFullId columnFullId = columnUsage.getColumnFullId();
Optional<Pair<TableName, ColumnId>> names = columnFullId.toNames();
thriftUsage.setTable_catalog(names.map(x -> x.first.getCatalog()).orElse(null));
thriftUsage.setTable_database(names.map(x -> x.first.getDb()).orElse(null));
thriftUsage.setTable_name(names.map(x -> x.first.getTbl()).orElse(null));
thriftUsage.setColumn_name(names.map(x -> x.second.getId()).orElse(null));
thriftUsage.setUsage(columnUsage.getUseCaseString());
thriftUsage.setLast_used(DateUtils.formatDateTimeUnix(columnUsage.getLastUsed()));
thriftUsage.setCreated(DateUtils.formatDateTimeUnix(columnUsage.getCreated()));
return thriftUsage;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Tablet;
import com.starrocks.catalog.View;
import com.starrocks.catalog.system.information.ColumnStatsUsageSystemTable;
import com.starrocks.catalog.system.information.TaskRunsSystemTable;
import com.starrocks.catalog.system.information.TasksSystemTable;
import com.starrocks.catalog.system.sys.GrantsTo;
Expand Down Expand Up @@ -173,13 +174,16 @@
import com.starrocks.thrift.TAbortRemoteTxnResponse;
import com.starrocks.thrift.TAllocateAutoIncrementIdParam;
import com.starrocks.thrift.TAllocateAutoIncrementIdResult;
import com.starrocks.thrift.TAuthInfo;
import com.starrocks.thrift.TAuthenticateParams;
import com.starrocks.thrift.TBatchReportExecStatusParams;
import com.starrocks.thrift.TBatchReportExecStatusResult;
import com.starrocks.thrift.TBeginRemoteTxnRequest;
import com.starrocks.thrift.TBeginRemoteTxnResponse;
import com.starrocks.thrift.TColumnDef;
import com.starrocks.thrift.TColumnDesc;
import com.starrocks.thrift.TColumnStatsUsageReq;
import com.starrocks.thrift.TColumnStatsUsageRes;
import com.starrocks.thrift.TCommitRemoteTxnRequest;
import com.starrocks.thrift.TCommitRemoteTxnResponse;
import com.starrocks.thrift.TCreatePartitionRequest;
Expand Down Expand Up @@ -707,6 +711,23 @@ public TFeMemoryRes listFeMemoryUsage(TFeMemoryReq request) throws TException {
return SysFeMemoryUsage.listFeMemoryUsage(request);
}

@Override
public TColumnStatsUsageRes getColumnStatsUsage(TColumnStatsUsageReq request) throws TException {
authRpc(request.getAuth_info(), PrivilegeType.OPERATE);

return ColumnStatsUsageSystemTable.query(request);
}

private static void authRpc(TAuthInfo auth, PrivilegeType expectPrivilege) throws TException {
UserIdentity currentUser = UserIdentity.fromThrift(auth.getCurrent_user_ident());

try {
Authorizer.checkSystemAction(currentUser, null, expectPrivilege);
} catch (AccessDeniedException e) {
throw new TException(e.getMessage(), e);
}
}

// list MaterializedView table match pattern
private TListMaterializedViewStatusResult listMaterializedViewStatus(long limit, PatternMatcher matcher,
UserIdentity currentUser, TGetTablesParams params) {
Expand Down

0 comments on commit f12d4f5

Please sign in to comment.