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

com.hazelcast.org.apache.calcite.rel.logical.LogicalCalc 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 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 com.hazelcast.org.apache.calcite.rel.logical;

import com.hazelcast.org.apache.calcite.plan.Convention;
import com.hazelcast.org.apache.calcite.plan.RelOptCluster;
import com.hazelcast.org.apache.calcite.plan.RelOptUtil;
import com.hazelcast.org.apache.calcite.plan.RelTraitSet;
import com.hazelcast.org.apache.calcite.rel.RelCollation;
import com.hazelcast.org.apache.calcite.rel.RelCollationTraitDef;
import com.hazelcast.org.apache.calcite.rel.RelDistributionTraitDef;
import com.hazelcast.org.apache.calcite.rel.RelInput;
import com.hazelcast.org.apache.calcite.rel.RelNode;
import com.hazelcast.org.apache.calcite.rel.RelShuttle;
import com.hazelcast.org.apache.calcite.rel.core.Calc;
import com.hazelcast.org.apache.calcite.rel.core.CorrelationId;
import com.hazelcast.org.apache.calcite.rel.hint.RelHint;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMdCollation;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMdDistribution;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMetadataQuery;
import com.hazelcast.org.apache.calcite.rel.rules.FilterToCalcRule;
import com.hazelcast.org.apache.calcite.rel.rules.ProjectToCalcRule;
import com.hazelcast.org.apache.calcite.rex.RexProgram;
import com.hazelcast.org.apache.calcite.util.Util;

import com.hazelcast.com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Set;

/**
 * A relational expression which computes project expressions and also filters.
 *
 * 

This relational expression combines the functionality of * {@link LogicalProject} and {@link LogicalFilter}. * It should be created in the later * stages of optimization, by merging consecutive {@link LogicalProject} and * {@link LogicalFilter} nodes together. * *

The following rules relate to LogicalCalc:

* *
    *
  • {@link FilterToCalcRule} creates this from a {@link LogicalFilter} *
  • {@link ProjectToCalcRule} creates this from a {@link LogicalProject} *
  • {@link com.hazelcast.org.apache.calcite.rel.rules.FilterCalcMergeRule} * merges this with a {@link LogicalFilter} *
  • {@link com.hazelcast.org.apache.calcite.rel.rules.ProjectCalcMergeRule} * merges this with a {@link LogicalProject} *
  • {@link com.hazelcast.org.apache.calcite.rel.rules.CalcMergeRule} * merges two {@code LogicalCalc}s *
*/ public final class LogicalCalc extends Calc { //~ Static fields/initializers --------------------------------------------- //~ Constructors ----------------------------------------------------------- /** Creates a LogicalCalc. */ public LogicalCalc( RelOptCluster cluster, RelTraitSet traitSet, List hints, RelNode child, RexProgram program) { super(cluster, traitSet, hints, child, program); } @Deprecated // to be removed before 2.0 public LogicalCalc( RelOptCluster cluster, RelTraitSet traitSet, RelNode child, RexProgram program) { this(cluster, traitSet, ImmutableList.of(), child, program); } /** * Creates a LogicalCalc by parsing serialized output. */ public LogicalCalc(RelInput input) { this(input.getCluster(), input.getTraitSet(), ImmutableList.of(), input.getInput(), RexProgram.create(input)); } @Deprecated // to be removed before 2.0 public LogicalCalc( RelOptCluster cluster, RelTraitSet traitSet, RelNode child, RexProgram program, List collationList) { this(cluster, traitSet, ImmutableList.of(), child, program); Util.discard(collationList); } public static LogicalCalc create(final RelNode input, final RexProgram program) { final RelOptCluster cluster = input.getCluster(); final RelMetadataQuery mq = cluster.getMetadataQuery(); final RelTraitSet traitSet = cluster.traitSet() .replace(Convention.NONE) .replaceIfs(RelCollationTraitDef.INSTANCE, () -> RelMdCollation.calc(mq, input, program)) .replaceIf(RelDistributionTraitDef.INSTANCE, () -> RelMdDistribution.calc(mq, input, program)); return new LogicalCalc(cluster, traitSet, ImmutableList.of(), input, program); } //~ Methods ---------------------------------------------------------------- @Override public LogicalCalc copy(RelTraitSet traitSet, RelNode child, RexProgram program) { return new LogicalCalc(getCluster(), traitSet, hints, child, program); } @Override public void collectVariablesUsed(Set variableSet) { final RelOptUtil.VariableUsedVisitor vuv = new RelOptUtil.VariableUsedVisitor(null); vuv.visitEach(program.getExprList()); variableSet.addAll(vuv.variables); } @Override public RelNode withHints(List hintList) { return new LogicalCalc(getCluster(), traitSet, ImmutableList.copyOf(hintList), input, program); } @Override public RelNode accept(RelShuttle shuttle) { return shuttle.visit(this); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy