-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a PinotLogicalSortExchange to replace usage of LogicalSortExchang…
…e as it will be sender and receiver aware (#10408) - MailboxSendOperator will be modified later to add sort support. - Modify SortOperator to avoid sorting if the input is already sorted. It should still apply offset + limit
- Loading branch information
Showing
22 changed files
with
1,124 additions
and
233 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...-query-planner/src/main/java/org/apache/calcite/rel/logical/PinotLogicalSortExchange.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,112 @@ | ||
/** | ||
* 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.calcite.rel.logical; | ||
|
||
import org.apache.calcite.plan.Convention; | ||
import org.apache.calcite.plan.RelOptCluster; | ||
import org.apache.calcite.plan.RelTraitSet; | ||
import org.apache.calcite.rel.RelCollation; | ||
import org.apache.calcite.rel.RelCollationTraitDef; | ||
import org.apache.calcite.rel.RelDistribution; | ||
import org.apache.calcite.rel.RelDistributionTraitDef; | ||
import org.apache.calcite.rel.RelInput; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.RelWriter; | ||
import org.apache.calcite.rel.core.SortExchange; | ||
|
||
|
||
/** | ||
* Pinot's implementation of {@code SortExchange} which needs information about whether to sort on the sender | ||
* and/or receiver side of the exchange. Every {@code Exchange} is broken into a send and a receive node and the | ||
* decision on where to sort is made by the planner and this information has to b passed onto the send and receive | ||
* nodes for the correct execution. | ||
* | ||
* Note: This class does not extend {@code LogicalSortExchange} because its constructor which takes the list of | ||
* parameters is private. | ||
*/ | ||
public class PinotLogicalSortExchange extends SortExchange { | ||
|
||
protected final boolean _isSortOnSender; | ||
protected final boolean _isSortOnReceiver; | ||
|
||
private PinotLogicalSortExchange(RelOptCluster cluster, RelTraitSet traitSet, | ||
RelNode input, RelDistribution distribution, RelCollation collation, | ||
boolean isSortOnSender, boolean isSortOnReceiver) { | ||
super(cluster, traitSet, input, distribution, collation); | ||
_isSortOnSender = isSortOnSender; | ||
_isSortOnReceiver = isSortOnReceiver; | ||
} | ||
|
||
/** | ||
* Creates a PinotLogicalSortExchange by parsing serialized output. | ||
*/ | ||
public PinotLogicalSortExchange(RelInput input) { | ||
super(input); | ||
_isSortOnSender = false; | ||
_isSortOnReceiver = true; | ||
} | ||
|
||
/** | ||
* Creates a PinotLogicalSortExchange. | ||
* | ||
* @param input Input relational expression | ||
* @param distribution Distribution specification | ||
* @param collation array of sort specifications | ||
* @param isSortOnSender whether to sort on the sender | ||
* @param isSortOnReceiver whether to sort on receiver | ||
*/ | ||
public static PinotLogicalSortExchange create( | ||
RelNode input, | ||
RelDistribution distribution, | ||
RelCollation collation, | ||
boolean isSortOnSender, | ||
boolean isSortOnReceiver) { | ||
RelOptCluster cluster = input.getCluster(); | ||
collation = RelCollationTraitDef.INSTANCE.canonize(collation); | ||
distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution); | ||
RelTraitSet traitSet = | ||
input.getTraitSet().replace(Convention.NONE).replace(distribution).replace(collation); | ||
return new PinotLogicalSortExchange(cluster, traitSet, input, distribution, | ||
collation, isSortOnSender, isSortOnReceiver); | ||
} | ||
|
||
//~ Methods ---------------------------------------------------------------- | ||
|
||
@Override | ||
public SortExchange copy(RelTraitSet traitSet, RelNode newInput, | ||
RelDistribution newDistribution, RelCollation newCollation) { | ||
return new PinotLogicalSortExchange(this.getCluster(), traitSet, newInput, | ||
newDistribution, newCollation, _isSortOnSender, _isSortOnReceiver); | ||
} | ||
|
||
@Override | ||
public RelWriter explainTerms(RelWriter pw) { | ||
return super.explainTerms(pw) | ||
.item("isSortOnSender", _isSortOnSender) | ||
.item("isSortOnReceiver", _isSortOnReceiver); | ||
} | ||
|
||
public boolean isSortOnSender() { | ||
return _isSortOnSender; | ||
} | ||
|
||
public boolean isSortOnReceiver() { | ||
return _isSortOnReceiver; | ||
} | ||
} |
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
Oops, something went wrong.