ProjectRelBase bottomProject = call.rel(1);
RexBuilder rexBuilder = topProject.getCluster().getRexBuilder();
// If one or both projects are permutations, short-circuit the complex logic
// of building a RexProgram.
final Permutation topPermutation = topProject.getPermutation();
if (topPermutation != null) {
if (topPermutation.isIdentity()) {
// Let RemoveTrivialProjectRule handle this.
return;
}
final Permutation bottomPermutation = bottomProject.getPermutation();
if (bottomPermutation != null) {
if (bottomPermutation.isIdentity()) {
// Let RemoveTrivialProjectRule handle this.
return;
}
final Permutation product = topPermutation.product(bottomPermutation);
call.transformTo(
RelOptUtil.projectMapping(bottomProject.getChild(),
product.inverse(), topProject.getRowType().getFieldNames(),
projectFactory));
return;
}
}