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

com.hazelcast.org.apache.calcite.adapter.enumerable.EnumerableProjectToCalcRule Maven / Gradle / Ivy

There is a newer version: 5.5.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.adapter.enumerable;

import com.hazelcast.org.apache.calcite.plan.RelOptRuleCall;
import com.hazelcast.org.apache.calcite.rel.RelNode;
import com.hazelcast.org.apache.calcite.rel.rules.ProjectToCalcRule;
import com.hazelcast.org.apache.calcite.rex.RexProgram;
import com.hazelcast.org.apache.calcite.tools.RelBuilderFactory;

import org.immutables.value.Value;

/** Variant of {@link com.hazelcast.org.apache.calcite.rel.rules.ProjectToCalcRule} for
 * {@link com.hazelcast.org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}.
 *
 * @see EnumerableRules#ENUMERABLE_PROJECT_TO_CALC_RULE */
@Value.Enclosing
public class EnumerableProjectToCalcRule extends ProjectToCalcRule {
  /** Creates an EnumerableProjectToCalcRule. */
  protected EnumerableProjectToCalcRule(Config config) {
    super(config);
  }

  @Deprecated // to be removed before 2.0
  public EnumerableProjectToCalcRule(RelBuilderFactory relBuilderFactory) {
    this(Config.DEFAULT.withRelBuilderFactory(relBuilderFactory)
        .as(Config.class));
  }

  @Override public void onMatch(RelOptRuleCall call) {
    final EnumerableProject project = call.rel(0);
    final RelNode input = project.getInput();
    final RexProgram program =
        RexProgram.create(input.getRowType(),
            project.getProjects(),
            null,
            project.getRowType(),
            project.getCluster().getRexBuilder());
    final EnumerableCalc calc = EnumerableCalc.create(input, program);
    call.transformTo(calc);
  }

  /** Rule configuration. */
  @Value.Immutable
  @SuppressWarnings("immutables")
  public interface Config extends ProjectToCalcRule.Config {
    Config DEFAULT = ImmutableEnumerableProjectToCalcRule.Config.of()
        .withOperandSupplier(b ->
            b.operand(EnumerableProject.class).anyInputs());

    @Override default EnumerableProjectToCalcRule toRule() {
      return new EnumerableProjectToCalcRule(this);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy