[Improvement](profile)Add tvf active_be_tasks() #31815

This commit is contained in:
wangbo
2024-03-06 13:53:57 +08:00
committed by yiguolei
parent 538032a75c
commit 28f0b7eb32
12 changed files with 227 additions and 6 deletions

View File

@ -17,6 +17,7 @@
package org.apache.doris.catalog;
import org.apache.doris.nereids.trees.expressions.functions.table.ActiveBeTasks;
import org.apache.doris.nereids.trees.expressions.functions.table.ActiveQueries;
import org.apache.doris.nereids.trees.expressions.functions.table.Backends;
import org.apache.doris.nereids.trees.expressions.functions.table.Catalogs;
@ -59,7 +60,8 @@ public class BuiltinTableValuedFunctions implements FunctionHelper {
tableValued(MvInfos.class, "mv_infos"),
tableValued(Jobs.class, "jobs"),
tableValued(Tasks.class, "tasks"),
tableValued(WorkloadGroups.class, "workload_groups")
tableValued(WorkloadGroups.class, "workload_groups"),
tableValued(ActiveBeTasks.class, "active_be_tasks")
);
public static final BuiltinTableValuedFunctions INSTANCE = new BuiltinTableValuedFunctions();

View File

@ -0,0 +1,58 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions.table;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Properties;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.coercion.AnyDataType;
import org.apache.doris.tablefunction.ActiveBeTasksTableValuedFunction;
import org.apache.doris.tablefunction.TableValuedFunctionIf;
import java.util.Map;
/**
* stands be running tasks status, currently main including select/streamload/broker load/insert select
*/
public class ActiveBeTasks extends TableValuedFunction {
public ActiveBeTasks(Properties properties) {
super("active_be_tasks", properties);
}
@Override
public FunctionSignature customSignature() {
return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, getArgumentsTypes());
}
@Override
protected TableValuedFunctionIf toCatalogFunction() {
try {
Map<String, String> arguments = getTVFProperties().getMap();
return new ActiveBeTasksTableValuedFunction(arguments);
} catch (Throwable t) {
throw new AnalysisException("Can not build ActiveBeTasksTableValuedFunction by "
+ this + ": " + t.getMessage(), t);
}
}
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitActiveBeTasks(this, context);
}
}

View File

@ -47,7 +47,7 @@ public class ActiveQueries extends TableValuedFunction {
Map<String, String> arguments = getTVFProperties().getMap();
return new ActiveQueriesTableValuedFunction(arguments);
} catch (Throwable t) {
throw new AnalysisException("Can not build FrontendsTableValuedFunction by "
throw new AnalysisException("Can not build ActiveQueriesTableValuedFunction by "
+ this + ": " + t.getMessage(), t);
}
}

View File

@ -17,6 +17,7 @@
package org.apache.doris.nereids.trees.expressions.visitor;
import org.apache.doris.nereids.trees.expressions.functions.table.ActiveBeTasks;
import org.apache.doris.nereids.trees.expressions.functions.table.ActiveQueries;
import org.apache.doris.nereids.trees.expressions.functions.table.Backends;
import org.apache.doris.nereids.trees.expressions.functions.table.Catalogs;
@ -102,4 +103,8 @@ public interface TableValuedFunctionVisitor<R, C> {
default R visitWorkloadGroups(WorkloadGroups workloadGroups, C context) {
return visitTableValuedFunction(workloadGroups, context);
}
default R visitActiveBeTasks(ActiveBeTasks beTasks, C context) {
return visitTableValuedFunction(beTasks, context);
}
}

View File

@ -0,0 +1,76 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.tablefunction;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.thrift.TMetaScanRange;
import org.apache.doris.thrift.TMetadataType;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Map;
public class ActiveBeTasksTableValuedFunction extends MetadataTableValuedFunction {
public static final String NAME = "active_be_tasks";
private static final ImmutableList<Column> SCHEMA = ImmutableList.of(
new Column("BeId", PrimitiveType.BIGINT),
new Column("FeHost", ScalarType.createStringType()),
new Column("QueryId", ScalarType.createStringType()),
new Column("TaskTimeMs", PrimitiveType.BIGINT),
new Column("TaskCpuTimeMs", PrimitiveType.BIGINT),
new Column("ScanRows", PrimitiveType.BIGINT),
new Column("ScanBytes", PrimitiveType.BIGINT),
new Column("BePeakMemoryBytes", PrimitiveType.BIGINT),
new Column("CurrentUsedMemoryBytes", PrimitiveType.BIGINT),
new Column("ShuffleSendBytes", PrimitiveType.BIGINT),
new Column("ShuffleSendRows", PrimitiveType.BIGINT));
public ActiveBeTasksTableValuedFunction(Map<String, String> params) throws AnalysisException {
if (params.size() != 0) {
throw new AnalysisException("ActiveBeTasks table-valued-function does not support any params");
}
}
@Override
public TMetadataType getMetadataType() {
return TMetadataType.ACTIVE_BE_TASKS;
}
@Override
public TMetaScanRange getMetaScanRange() {
TMetaScanRange metaScanRange = new TMetaScanRange();
metaScanRange.setMetadataType(TMetadataType.ACTIVE_BE_TASKS);
return metaScanRange;
}
@Override
public String getTableName() {
return "ActiveBeTasksTableValuedFunction";
}
@Override
public List<Column> getTableColumns() throws AnalysisException {
return SCHEMA;
}
}

View File

@ -68,7 +68,7 @@ public class ActiveQueriesTableValuedFunction extends MetadataTableValuedFunctio
public ActiveQueriesTableValuedFunction(Map<String, String> params) throws AnalysisException {
if (params.size() != 0) {
throw new AnalysisException("Queries table-valued-function does not support any params");
throw new AnalysisException("ActiveQueries table-valued-function does not support any params");
}
}
@ -90,7 +90,7 @@ public class ActiveQueriesTableValuedFunction extends MetadataTableValuedFunctio
@Override
public String getTableName() {
return "QueriesTableValuedFunction";
return "ActiveQueriesTableValuedFunction";
}
@Override

View File

@ -78,6 +78,8 @@ public abstract class TableValuedFunctionIf {
return new ActiveQueriesTableValuedFunction(params);
case WorkloadSchedPolicyTableValuedFunction.NAME:
return new WorkloadSchedPolicyTableValuedFunction(params);
case ActiveBeTasksTableValuedFunction.NAME:
return new ActiveBeTasksTableValuedFunction(params);
default:
throw new AnalysisException("Could not find table function " + funcName);
}