[fix](nereids) Fix the bugs of data distribution calculation on OlapScan (#15699)

when need to scan more than one olap table partition and it is not a colocate table or its colocate group is unstable, we need to make it as any distribution even if its distribution type is Hash
This commit is contained in:
AKIRA
2023-01-09 15:25:54 +08:00
committed by GitHub
parent e2492cf7fc
commit 7543d677fa
3 changed files with 69 additions and 3 deletions

View File

@ -17,9 +17,13 @@
package org.apache.doris.nereids.rules.implementation;
import org.apache.doris.catalog.ColocateTableIndex;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.DistributionInfo;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.HashDistributionInfo;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.nereids.properties.DistributionSpec;
import org.apache.doris.nereids.properties.DistributionSpecAny;
import org.apache.doris.nereids.properties.DistributionSpecHash;
@ -59,10 +63,17 @@ public class LogicalOlapScanToPhysicalOlapScan extends OneImplementationRuleFact
}
private DistributionSpec convertDistribution(LogicalOlapScan olapScan) {
DistributionInfo distributionInfo = olapScan.getTable().getDefaultDistributionInfo();
if (distributionInfo instanceof HashDistributionInfo) {
OlapTable olapTable = olapScan.getTable();
DistributionInfo distributionInfo = olapTable.getDefaultDistributionInfo();
ColocateTableIndex colocateTableIndex = Env.getCurrentColocateIndex();
if ((colocateTableIndex.isColocateTable(olapTable.getId())
&& !colocateTableIndex.isGroupUnstable(colocateTableIndex.getGroup(olapTable.getId())))
|| olapTable.getPartitionInfo().getType() == PartitionType.UNPARTITIONED
|| olapTable.getPartitions().size() == 1) {
if (!(distributionInfo instanceof HashDistributionInfo)) {
return DistributionSpecAny.INSTANCE;
}
HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) distributionInfo;
List<Slot> output = olapScan.getOutput();
List<ExprId> hashColumns = Lists.newArrayList();
List<Column> schemaColumns = olapScan.getTable().getFullSchema();