This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new aecc93c002c [fix](information_schema) fix backend_active_tasks table only return one backend's data (#50721) (#50723) aecc93c002c is described below commit aecc93c002ca9adb2f6d140a8c14973c32079ce6 Author: 924060929 <lanhuaj...@selectdb.com> AuthorDate: Tue May 13 22:32:29 2025 +0800 [fix](information_schema) fix backend_active_tasks table only return one backend's data (#50721) (#50723) cherry pick from #50721 --- .../glue/translator/PhysicalPlanTranslator.java | 2 +- .../planner/BackendPartitionedSchemaScanNode.java | 12 +++-- .../apache/doris/planner/SingleNodePlanner.java | 4 +- .../apache/doris/catalog/MetadataTableTest.java | 61 ++++++++++++++++++++++ 4 files changed, 71 insertions(+), 8 deletions(-) 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 9237e7104c8..da1c22f492b 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 @@ -888,7 +888,7 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla SchemaScanNode scanNode = null; if (BackendPartitionedSchemaScanNode.isBackendPartitionedSchemaTable( table.getName())) { - scanNode = new BackendPartitionedSchemaScanNode(context.nextPlanNodeId(), tupleDescriptor, + scanNode = new BackendPartitionedSchemaScanNode(context.nextPlanNodeId(), table, tupleDescriptor, schemaScan.getSchemaCatalog().orElse(null), schemaScan.getSchemaDatabase().orElse(null), schemaScan.getSchemaTable().orElse(null)); } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/BackendPartitionedSchemaScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/BackendPartitionedSchemaScanNode.java index 41af0671f11..74030bd2190 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/BackendPartitionedSchemaScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/BackendPartitionedSchemaScanNode.java @@ -19,7 +19,6 @@ package org.apache.doris.planner; import org.apache.doris.analysis.Analyzer; import org.apache.doris.analysis.LiteralExpr; -import org.apache.doris.analysis.SlotDescriptor; import org.apache.doris.analysis.TupleDescriptor; import org.apache.doris.catalog.Column; import org.apache.doris.catalog.Env; @@ -28,6 +27,7 @@ import org.apache.doris.catalog.PartitionInfo; import org.apache.doris.catalog.PartitionItem; import org.apache.doris.catalog.PartitionKey; import org.apache.doris.catalog.PartitionType; +import org.apache.doris.catalog.TableIf; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.UserException; import org.apache.doris.system.Backend; @@ -59,6 +59,7 @@ public class BackendPartitionedSchemaScanNode extends SchemaScanNode { // you need to the table's backend column id name to BACKEND_ID_COLUMN_SET // it's used to backend pruner, see computePartitionInfo; public static final Set<String> BEACKEND_ID_COLUMN_SET = new HashSet<>(); + private final TableIf tableIf; static { BACKEND_TABLE.add("rowsets"); @@ -89,9 +90,10 @@ public class BackendPartitionedSchemaScanNode extends SchemaScanNode { private Map<Long, Long> partitionIDToBackendID; private Collection<Long> 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 @@ -140,9 +142,9 @@ public class BackendPartitionedSchemaScanNode extends SchemaScanNode { private void computePartitionInfo() throws UserException { List<Column> 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 0a5de932243..693d9ede950 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 @@ -1937,8 +1937,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 00000000000..4087810243a --- /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<PlanFragment> fragments = nereidsPlanner.getFragments(); + PlanNode planRoot = fragments.get(fragments.size() - 1).getPlanRoot(); + List<BackendPartitionedSchemaScanNode> scanNodes = new ArrayList<>(); + planRoot.collect(BackendPartitionedSchemaScanNode.class, scanNodes); + BackendPartitionedSchemaScanNode scanNode = scanNodes.get(0); + List<TScanRangeLocations> scanRangeLocations = scanNode.getScanRangeLocations(0); + Assertions.assertEquals(backendNum(), scanRangeLocations.size()); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org