All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.apache.calcite.rel.rules.MultiJoinProjectTransposeRule Maven / Gradle / Ivy

There is a newer version: 5.4.0
Show newest version
/*
 * 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 com.hazelcast.com.liance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.com.hazelcast.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 com.hazelcast.org.apache.calcite.rel.rules;

import com.hazelcast.org.apache.calcite.plan.RelOptRuleCall;
import com.hazelcast.org.apache.calcite.plan.RelOptRuleOperand;
import com.hazelcast.org.apache.calcite.plan.RelOptUtil;
import com.hazelcast.org.apache.calcite.rel.RelNode;
import com.hazelcast.org.apache.calcite.rel.core.Project;
import com.hazelcast.org.apache.calcite.rel.core.RelFactories;
import com.hazelcast.org.apache.calcite.rel.logical.LogicalJoin;
import com.hazelcast.org.apache.calcite.rel.logical.LogicalProject;
import com.hazelcast.org.apache.calcite.tools.RelBuilderFactory;

/**
 * MultiJoinProjectTransposeRule implements the rule for pulling
 * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalProject}s that are on top of a
 * {@link MultiJoin} and beneath a
 * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalJoin} so the
 * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalProject} appears above the
 * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalJoin}.
 *
 * 

In the process of doing * so, also save away information about the respective fields that are * referenced in the expressions in the * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalProject} we're pulling up, as * well as the join condition, in the resultant {@link MultiJoin}s * *

For example, if we have the following sub-query: * *

 * (select X.x1, Y.y1 from X, Y
 *  where X.x2 = Y.y2 and X.x3 = 1 and Y.y3 = 2)
* *

The {@link MultiJoin} associated with (X, Y) associates x1 with X and * y1 with Y. Although x3 and y3 need to be read due to the filters, they are * not required after the row scan has com.hazelcast.com.leted and therefore are not saved. * The join fields, x2 and y2, are also tracked separately. * *

Note that by only pulling up projects that are on top of * {@link MultiJoin}s, we preserve projections on top of row scans. * *

See the superclass for details on restrictions regarding which * {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalProject}s cannot be pulled. */ public class MultiJoinProjectTransposeRule extends JoinProjectTransposeRule { //~ Static fields/initializers --------------------------------------------- public static final MultiJoinProjectTransposeRule MULTI_BOTH_PROJECT = new MultiJoinProjectTransposeRule( operand(LogicalJoin.class, operand(LogicalProject.class, operand(MultiJoin.class, any())), operand(LogicalProject.class, operand(MultiJoin.class, any()))), RelFactories.LOGICAL_BUILDER, "MultiJoinProjectTransposeRule: with two LogicalProject children"); public static final MultiJoinProjectTransposeRule MULTI_LEFT_PROJECT = new MultiJoinProjectTransposeRule( operand(LogicalJoin.class, some( operand(LogicalProject.class, operand(MultiJoin.class, any())))), RelFactories.LOGICAL_BUILDER, "MultiJoinProjectTransposeRule: with LogicalProject on left"); public static final MultiJoinProjectTransposeRule MULTI_RIGHT_PROJECT = new MultiJoinProjectTransposeRule( operand(LogicalJoin.class, operand(RelNode.class, any()), operand(LogicalProject.class, operand(MultiJoin.class, any()))), RelFactories.LOGICAL_BUILDER, "MultiJoinProjectTransposeRule: with LogicalProject on right"); //~ Constructors ----------------------------------------------------------- @Deprecated // to be removed before 2.0 public MultiJoinProjectTransposeRule( RelOptRuleOperand operand, String description) { this(operand, RelFactories.LOGICAL_BUILDER, description); } /** Creates a MultiJoinProjectTransposeRule. */ public MultiJoinProjectTransposeRule( RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description) { super(operand, description, false, relBuilderFactory); } //~ Methods ---------------------------------------------------------------- @Override protected boolean hasLeftChild(RelOptRuleCall call) { return call.rels.length != 4; } @Override protected boolean hasRightChild(RelOptRuleCall call) { return call.rels.length > 3; } @Override protected Project getRightChild(RelOptRuleCall call) { if (call.rels.length == 4) { return call.rel(2); } else { return call.rel(3); } } @Override protected RelNode getProjectChild( RelOptRuleCall call, Project project, boolean leftChild) { // locate the appropriate MultiJoin based on which rule was fired // and which projection we're dealing with MultiJoin multiJoin; if (leftChild) { multiJoin = call.rel(2); } else if (call.rels.length == 4) { multiJoin = call.rel(3); } else { multiJoin = call.rel(4); } // create a new MultiJoin that reflects the columns in the projection // above the MultiJoin return RelOptUtil.projectMultiJoin(multiJoin, project); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy