use of org.apache.calcite.rel.hint.Hintable in project calcite by apache.
the class SqlToRelConverter method convertSelectImpl.
/**
* Implementation of {@link #convertSelect(SqlSelect, boolean)};
* derived class may override.
*/
protected void convertSelectImpl(final Blackboard bb, SqlSelect select) {
convertFrom(bb, select.getFrom());
// semantics. It is not a 'pure order'.
if (RelOptUtil.isPureOrder(castNonNull(bb.root)) && config.isRemoveSortInSubQuery()) {
// sub-query.
if (!bb.top || validator().isAggregate(select) || select.isDistinct() || select.hasOrderBy() || select.getFetch() != null || select.getOffset() != null) {
bb.setRoot(castNonNull(bb.root).getInput(0), true);
}
}
convertWhere(bb, select.getWhere());
final List<SqlNode> orderExprList = new ArrayList<>();
final List<RelFieldCollation> collationList = new ArrayList<>();
gatherOrderExprs(bb, select, select.getOrderList(), orderExprList, collationList);
final RelCollation collation = cluster.traitSet().canonize(RelCollations.of(collationList));
if (validator().isAggregate(select)) {
convertAgg(bb, select, orderExprList);
} else {
convertSelectList(bb, select, orderExprList);
}
if (select.isDistinct()) {
distinctify(bb, true);
}
convertOrder(select, bb, collation, orderExprList, select.getOffset(), select.getFetch());
if (select.hasHints()) {
final List<RelHint> hints = SqlUtil.getRelHint(hintStrategies, select.getHints());
// Attach the hints to the first Hintable node we found from the root node.
bb.setRoot(bb.root().accept(new RelShuttleImpl() {
boolean attached = false;
@Override
public RelNode visitChild(RelNode parent, int i, RelNode child) {
if (parent instanceof Hintable && !attached) {
attached = true;
return ((Hintable) parent).attachHints(hints);
} else {
return super.visitChild(parent, i, child);
}
}
}), true);
} else {
bb.setRoot(bb.root(), true);
}
}
use of org.apache.calcite.rel.hint.Hintable in project calcite by apache.
the class RelBuilder method hints.
/**
* Attaches multiple hints to the stack top relational expression.
*
* <p>The redundant hints would be eliminated.
*
* @param hints Hints
*
* @throws AssertionError if the top relational expression does not implement
* {@link org.apache.calcite.rel.hint.Hintable}
*/
public RelBuilder hints(Iterable<RelHint> hints) {
requireNonNull(hints, "hints");
final List<RelHint> relHintList = hints instanceof List ? (List<RelHint>) hints : Lists.newArrayList(hints);
if (relHintList.isEmpty()) {
return this;
}
final Frame frame = peek_();
assert frame != null : "There is no relational expression to attach the hints";
assert frame.rel instanceof Hintable : "The top relational expression is not a Hintable";
Hintable hintable = (Hintable) frame.rel;
replaceTop(hintable.attachHints(relHintList));
return this;
}
Aggregations