diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java index 5b326d2048..a95ca99388 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java @@ -910,7 +910,7 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor BEACKEND_ID_COLUMN_SET = new HashSet<>(); + private final TableIf tableIf; static { BACKEND_TABLE.add("rowsets"); @@ -90,9 +91,10 @@ public class BackendPartitionedSchemaScanNode extends SchemaScanNode { private Map partitionIDToBackendID; private Collection selectedPartitionIds = Lists.newArrayList(); - public BackendPartitionedSchemaScanNode(PlanNodeId id, TupleDescriptor desc, + public BackendPartitionedSchemaScanNode(PlanNodeId id, TableIf table, TupleDescriptor desc, String schemaCatalog, String schemaDatabase, String schemaTable) { super(id, desc, schemaCatalog, schemaDatabase, schemaTable); + this.tableIf = table; } @Override @@ -141,9 +143,9 @@ public class BackendPartitionedSchemaScanNode extends SchemaScanNode { private void computePartitionInfo() throws AnalysisException { List partitionColumns = new ArrayList<>(); - for (SlotDescriptor slotDesc : desc.getSlots()) { - if (BEACKEND_ID_COLUMN_SET.contains(slotDesc.getColumn().getName().toLowerCase())) { - partitionColumns.add(slotDesc.getColumn()); + for (Column column : tableIf.getColumns()) { + if (BEACKEND_ID_COLUMN_SET.contains(column.getName().toLowerCase())) { + partitionColumns.add(column); break; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index 368ec66125..cee32e8dc6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -1939,8 +1939,8 @@ public class SingleNodePlanner { case SCHEMA: if (BackendPartitionedSchemaScanNode.isBackendPartitionedSchemaTable( tblRef.getDesc().getTable().getName())) { - scanNode = new BackendPartitionedSchemaScanNode(ctx.getNextNodeId(), tblRef.getDesc(), - null, null, null); + scanNode = new BackendPartitionedSchemaScanNode(ctx.getNextNodeId(), tblRef.getTable(), + tblRef.getDesc(), null, null, null); } else { scanNode = new SchemaScanNode(ctx.getNextNodeId(), tblRef.getDesc(), null, null, null); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/MetadataTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/MetadataTableTest.java new file mode 100644 index 0000000000..4087810243 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/MetadataTableTest.java @@ -0,0 +1,61 @@ +// 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.catalog; + +import org.apache.doris.nereids.NereidsPlanner; +import org.apache.doris.nereids.StatementContext; +import org.apache.doris.nereids.glue.LogicalPlanAdapter; +import org.apache.doris.nereids.parser.NereidsParser; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.planner.BackendPartitionedSchemaScanNode; +import org.apache.doris.planner.PlanFragment; +import org.apache.doris.planner.PlanNode; +import org.apache.doris.thrift.TScanRangeLocations; +import org.apache.doris.utframe.TestWithFeService; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class MetadataTableTest extends TestWithFeService { + + @Override + protected int backendNum() { + return 2; + } + + @Test + public void testScanBackendActiveTasks() throws Exception { + useDatabase("information_schema"); + + LogicalPlan parsed = new NereidsParser().parseSingle( + "select sum(SCAN_ROWS), sum(SCAN_BYTES) from backend_active_tasks where QUERY_ID = 'd299cb2156ef4870-aea578938f703503'"); + StatementContext statementContext = new StatementContext(); + NereidsPlanner nereidsPlanner = new NereidsPlanner(statementContext); + nereidsPlanner.plan(new LogicalPlanAdapter(parsed, statementContext)); + List fragments = nereidsPlanner.getFragments(); + PlanNode planRoot = fragments.get(fragments.size() - 1).getPlanRoot(); + List scanNodes = new ArrayList<>(); + planRoot.collect(BackendPartitionedSchemaScanNode.class, scanNodes); + BackendPartitionedSchemaScanNode scanNode = scanNodes.get(0); + List scanRangeLocations = scanNode.getScanRangeLocations(0); + Assertions.assertEquals(backendNum(), scanRangeLocations.size()); + } +}