forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
2,540 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/DistributePlanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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.plans.distribute; | ||
|
||
import org.apache.doris.nereids.worker.job.AssignedJob; | ||
import org.apache.doris.nereids.worker.job.AssignedJobBuilder; | ||
import org.apache.doris.nereids.worker.job.UnassignedJob; | ||
import org.apache.doris.nereids.worker.job.UnassignedJobBuilder; | ||
import org.apache.doris.planner.PlanFragment; | ||
import org.apache.doris.planner.PlanFragmentId; | ||
|
||
import com.google.common.collect.ListMultimap; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Objects; | ||
|
||
/** DistributePlanner */ | ||
public class DistributePlanner { | ||
private final List<PlanFragment> fragments; | ||
private final FragmentIdMapping<PlanFragment> idToFragments; | ||
|
||
public DistributePlanner(List<PlanFragment> fragments) { | ||
this.fragments = Objects.requireNonNull(fragments, "fragments can not be null"); | ||
this.idToFragments = FragmentIdMapping.buildFragmentMapping(fragments); | ||
} | ||
|
||
public FragmentIdMapping<DistributedPlan> plan() { | ||
FragmentIdMapping<UnassignedJob> fragmentJobs = UnassignedJobBuilder.buildJobs(idToFragments); | ||
ListMultimap<PlanFragmentId, AssignedJob> instanceJobs = AssignedJobBuilder.buildJobs(fragmentJobs); | ||
return buildDistributePlans(fragmentJobs, instanceJobs); | ||
} | ||
|
||
private FragmentIdMapping<DistributedPlan> buildDistributePlans( | ||
Map<PlanFragmentId, UnassignedJob> idToUnassignedJobs, | ||
ListMultimap<PlanFragmentId, AssignedJob> idToAssignedJobs) { | ||
FragmentIdMapping<DistributedPlan> idToDistributedPlans = new FragmentIdMapping<>(); | ||
for (Entry<PlanFragmentId, PlanFragment> kv : idToFragments.entrySet()) { | ||
PlanFragmentId fragmentId = kv.getKey(); | ||
PlanFragment fragment = kv.getValue(); | ||
|
||
UnassignedJob fragmentJob = idToUnassignedJobs.get(fragmentId); | ||
List<AssignedJob> instanceJobs = idToAssignedJobs.get(fragmentId); | ||
|
||
List<DistributedPlan> childrenPlans = idToDistributedPlans.getByChildrenFragments(fragment); | ||
idToDistributedPlans.put(fragmentId, new DistributedPlan(fragmentJob, instanceJobs, childrenPlans)); | ||
} | ||
return idToDistributedPlans; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...e-core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/DistributedPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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.plans.distribute; | ||
|
||
import org.apache.doris.nereids.trees.TreeNode; | ||
import org.apache.doris.nereids.util.Utils; | ||
import org.apache.doris.nereids.worker.job.AssignedJob; | ||
import org.apache.doris.nereids.worker.job.UnassignedJob; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** DistributedPlan */ | ||
@lombok.Getter | ||
public class DistributedPlan implements TreeNode<DistributedPlan> { | ||
private final UnassignedJob fragmentJob; | ||
private final List<AssignedJob> instanceJobs; | ||
private final List<DistributedPlan> inputs; | ||
|
||
public DistributedPlan( | ||
UnassignedJob fragmentJob, List<AssignedJob> instanceJobs, List<DistributedPlan> inputs) { | ||
this.fragmentJob = Objects.requireNonNull(fragmentJob, "fragmentJob can not be null"); | ||
this.instanceJobs = Utils.fastToImmutableList( | ||
Objects.requireNonNull(instanceJobs, "instanceJobs can not be null")); | ||
this.inputs = Utils.fastToImmutableList(Objects.requireNonNull(inputs, "inputs can not be null")); | ||
} | ||
|
||
@Override | ||
public List<DistributedPlan> children() { | ||
return inputs; | ||
} | ||
|
||
@Override | ||
public DistributedPlan child(int index) { | ||
return inputs.get(index); | ||
} | ||
|
||
@Override | ||
public int arity() { | ||
return inputs.size(); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> getMutableState(String key) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void setMutableState(String key, Object value) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public DistributedPlan withChildren(List<DistributedPlan> children) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String instancesStr = StringUtils.join(instanceJobs, ",\n"); | ||
String instancesStrWithIndent = Utils.addLinePrefix(instancesStr, " "); | ||
|
||
return "DistributedPlan(\n parallel: " + instanceJobs.size() + ",\n fragmentJob: " + fragmentJob | ||
+ "\n instanceJobs: [\n" + instancesStrWithIndent + "\n ]\n)"; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/FragmentIdMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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.plans.distribute; | ||
|
||
import org.apache.doris.planner.PlanFragment; | ||
import org.apache.doris.planner.PlanFragmentId; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* FragmentIdMapping: | ||
* key: PlanFragmentId | ||
* value: T | ||
* | ||
* NOTE: this map should order by PlanFragmentId asc | ||
*/ | ||
public class FragmentIdMapping<T> extends TreeMap<PlanFragmentId, T> { | ||
public FragmentIdMapping() { | ||
} | ||
|
||
public FragmentIdMapping(Comparator<? super PlanFragmentId> comparator) { | ||
super(comparator); | ||
} | ||
|
||
public FragmentIdMapping(Map<? extends PlanFragmentId, ? extends T> m) { | ||
super(m); | ||
} | ||
|
||
public FragmentIdMapping(SortedMap<PlanFragmentId, ? extends T> m) { | ||
super(m); | ||
} | ||
|
||
/** getByChildrenFragments */ | ||
public List<T> getByChildrenFragments(PlanFragment fragment) { | ||
List<PlanFragment> children = fragment.getChildren(); | ||
ImmutableList.Builder<T> values = ImmutableList.builderWithExpectedSize(children.size()); | ||
for (PlanFragment child : children) { | ||
values.add(get(child.getFragmentId())); | ||
} | ||
return values.build(); | ||
} | ||
|
||
public static FragmentIdMapping<PlanFragment> buildFragmentMapping(List<PlanFragment> fragments) { | ||
FragmentIdMapping<PlanFragment> idToFragments = new FragmentIdMapping<>(); | ||
for (PlanFragment fragment : fragments) { | ||
idToFragments.put(fragment.getFragmentId(), fragment); | ||
} | ||
return idToFragments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.