Skip to content

Commit

Permalink
[CALCITE-4825] Move remaining core/main off of ImmutableBeans
Browse files Browse the repository at this point in the history
This is a follow up to CALCITE-4787 to move the rest of the core/main off ImmutableBeans
  • Loading branch information
jacques-n committed Oct 5, 2021
1 parent 07b68bc commit 5824c54
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;

import org.immutables.value.Value;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -44,6 +46,7 @@
*
* @see EnumerableRules#ENUMERABLE_BATCH_NESTED_LOOP_JOIN_RULE
*/
@Value.Enclosing
public class EnumerableBatchNestedLoopJoinRule
extends RelRule<EnumerableBatchNestedLoopJoinRule.Config> {
/** Creates an EnumerableBatchNestedLoopJoinRule. */
Expand Down Expand Up @@ -149,11 +152,11 @@ public EnumerableBatchNestedLoopJoinRule(RelBuilderFactory relBuilderFactory,
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
Config DEFAULT = ImmutableEnumerableBatchNestedLoopJoinRule.Config.of()
.withOperandSupplier(b -> b.operand(LogicalJoin.class).anyInputs())
.withDescription("EnumerableBatchNestedLoopJoinRule")
.as(Config.class);
.withDescription("EnumerableBatchNestedLoopJoinRule");

@Override default EnumerableBatchNestedLoopJoinRule toRule() {
return new EnumerableBatchNestedLoopJoinRule(this);
Expand All @@ -165,7 +168,9 @@ public interface Config extends RelRule.Config {
* can be an error because the generated code exceeds the size limit. */
@ImmutableBeans.Property
@ImmutableBeans.IntDefault(100)
int batchSize();
@Value.Default default int batchSize() {
return 100;
}

/** Sets {@link #batchSize()}. */
Config withBatchSize(int batchSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
import org.apache.calcite.rel.core.Calc;
import org.apache.calcite.rel.logical.LogicalCalc;

import org.immutables.value.Value;

/**
* Rule to convert a {@link LogicalCalc} to an {@link EnumerableCalc}.
* You may provide a custom config to convert other nodes that extend {@link Calc}.
*
* @see EnumerableRules#ENUMERABLE_CALC_RULE
*/
@Value.Enclosing
class EnumerableCalcRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.EMPTY
.as(Config.class)
public static final Config DEFAULT_CONFIG = Config.INSTANCE
// The predicate ensures that if there's a multiset,
// FarragoMultisetSplitter will work on it first.
.withConversion(LogicalCalc.class, RelOptUtil::notContainsWindowedAgg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
import org.apache.calcite.rel.core.Correlate;
import org.apache.calcite.rel.logical.LogicalCorrelate;

import org.immutables.value.Value;

/**
* Implementation of nested loops over enumerable inputs.
*
* @see EnumerableRules#ENUMERABLE_CORRELATE_RULE
*/
@Value.Enclosing
public class EnumerableCorrelateRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.EMPTY
.as(Config.class)
public static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalCorrelate.class, r -> true, Convention.NONE,
EnumerableConvention.INSTANCE, "EnumerableCorrelateRule")
.withRuleFactory(EnumerableCorrelateRule::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*/
class EnumerableFilterRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.EMPTY
.as(Config.class)
public static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalFilter.class, f -> !f.containsOver(),
Convention.NONE, EnumerableConvention.INSTANCE,
"EnumerableFilterRule")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import org.apache.calcite.rex.RexProgramBuilder;
import org.apache.calcite.tools.RelBuilderFactory;

import org.immutables.value.Value;

/** Variant of {@link org.apache.calcite.rel.rules.FilterToCalcRule} for
* {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}.
*
* @see EnumerableRules#ENUMERABLE_FILTER_TO_CALC_RULE */
@Value.Enclosing
public class EnumerableFilterToCalcRule
extends RelRule<EnumerableFilterToCalcRule.Config> {
/** Creates an EnumerableFilterToCalcRule. */
Expand Down Expand Up @@ -60,11 +63,11 @@ public EnumerableFilterToCalcRule(RelBuilderFactory relBuilderFactory) {
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
Config DEFAULT = ImmutableEnumerableFilterToCalcRule.Config.of()
.withOperandSupplier(b ->
b.operand(EnumerableFilter.class).anyInputs())
.as(Config.class);
b.operand(EnumerableFilter.class).anyInputs());

@Override default EnumerableFilterToCalcRule toRule() {
return new EnumerableFilterToCalcRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Sort;

import org.immutables.value.Value;

/**
* Rule to convert an {@link org.apache.calcite.rel.core.Sort} that has
* {@code offset} or {@code fetch} set to an
Expand All @@ -29,6 +31,7 @@
*
* @see EnumerableRules#ENUMERABLE_LIMIT_RULE
*/
@Value.Enclosing
public class EnumerableLimitRule
extends RelRule<EnumerableLimitRule.Config> {
/** Creates an EnumerableLimitRule. */
Expand Down Expand Up @@ -64,10 +67,10 @@ protected EnumerableLimitRule(Config config) {
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b -> b.operand(Sort.class).anyInputs())
.as(Config.class);
Config DEFAULT = ImmutableEnumerableLimitRule.Config.of()
.withOperandSupplier(b -> b.operand(Sort.class).anyInputs());

@Override default EnumerableLimitRule toRule() {
return new EnumerableLimitRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import org.apache.calcite.rel.core.Sort;
import org.apache.calcite.rel.logical.LogicalSort;

import org.immutables.value.Value;

/**
* Rule to convert an {@link EnumerableLimit} of on
* {@link EnumerableSort} into an {@link EnumerableLimitSort}.
*/
@Value.Enclosing
public class EnumerableLimitSortRule extends RelRule<EnumerableLimitSortRule.Config> {

/**
Expand All @@ -48,10 +51,10 @@ public EnumerableLimitSortRule(Config config) {
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY.withOperandSupplier(
b0 -> b0.operand(LogicalSort.class).predicate(sort -> sort.fetch != null).anyInputs())
.as(Config.class);
Config DEFAULT = ImmutableEnumerableLimitSortRule.Config.of().withOperandSupplier(
b0 -> b0.operand(LogicalSort.class).predicate(sort -> sort.fetch != null).anyInputs());

@Override default EnumerableLimitSortRule toRule() {
return new EnumerableLimitSortRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;

import org.immutables.value.Value;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,13 +38,16 @@
*
* @see EnumerableRules#ENUMERABLE_MERGE_UNION_RULE
*/
@Value.Enclosing
public class EnumerableMergeUnionRule extends RelRule<EnumerableMergeUnionRule.Config> {

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT_CONFIG = EMPTY.withDescription("EnumerableMergeUnionRule").withOperandSupplier(
b0 -> b0.operand(LogicalSort.class).oneInput(
b1 -> b1.operand(LogicalUnion.class).anyInputs())).as(Config.class);
Config DEFAULT_CONFIG = ImmutableEnumerableMergeUnionRule.Config.of()
.withDescription("EnumerableMergeUnionRule").withOperandSupplier(
b0 -> b0.operand(LogicalSort.class).oneInput(
b1 -> b1.operand(LogicalUnion.class).anyInputs()));

@Override default EnumerableMergeUnionRule toRule() {
return new EnumerableMergeUnionRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class EnumerableProjectRule extends ConverterRule {
/** Default configuration. */
static final Config DEFAULT_CONFIG = Config.EMPTY
static final Config DEFAULT_CONFIG = Config.INSTANCE
.as(Config.class)
.withConversion(LogicalProject.class, p -> !p.containsOver(),
Convention.NONE, EnumerableConvention.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package org.apache.calcite.adapter.enumerable;

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

import org.immutables.value.Value;

/** Variant of {@link org.apache.calcite.rel.rules.ProjectToCalcRule} for
* {@link 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) {
Expand All @@ -53,11 +55,12 @@ public EnumerableProjectToCalcRule(RelBuilderFactory relBuilderFactory) {
}

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

@Override default EnumerableProjectToCalcRule toRule() {
return new EnumerableProjectToCalcRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* @see EnumerableRules#ENUMERABLE_TABLE_FUNCTION_SCAN_RULE */
public class EnumerableTableFunctionScanRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.EMPTY
.as(Config.class)
public static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalTableFunctionScan.class, Convention.NONE,
EnumerableConvention.INSTANCE, "EnumerableTableFunctionScanRule")
.withRuleFactory(EnumerableTableFunctionScanRule::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* @see EnumerableRules#ENUMERABLE_TABLE_SCAN_RULE */
public class EnumerableTableScanRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.EMPTY
.as(Config.class)
public static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalTableScan.class,
r -> EnumerableTableScan.canHandle(r.getTable()),
Convention.NONE, EnumerableConvention.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.google.common.collect.ImmutableList;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;

import java.util.List;
import java.util.Map;
Expand All @@ -90,6 +91,7 @@
/**
* Utilities pertaining to {@link BindableRel} and {@link BindableConvention}.
*/
@Value.Enclosing
public class Bindables {
private Bindables() {}

Expand Down Expand Up @@ -188,11 +190,11 @@ public BindableTableScanRule(RelBuilderFactory relBuilderFactory) {
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
Config DEFAULT = ImmutableBindables.Config.of()
.withOperandSupplier(b ->
b.operand(LogicalTableScan.class).noInputs())
.as(Config.class);
b.operand(LogicalTableScan.class).noInputs());

@Override default BindableTableScanRule toRule() {
return new BindableTableScanRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ protected CommonRelSubExprRule(Config config) {
super(config);
}

@Deprecated // to be removed before 2.0
protected CommonRelSubExprRule(RelOptRuleOperand operand) {
this(Config.EMPTY.withOperandSupplier(b -> b.exactly(operand))
.as(Config.class));
}

/** Rule configuration. */
public interface Config extends RelRule.Config {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.calcite.tools.RelBuilderFactory;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;

import java.util.List;

Expand All @@ -47,6 +48,7 @@
* source subset is abstract), the set is flagged, so this converter will be
* expanded as soon as a non-abstract relexp is added to the set.</p>
*/
@Value.Enclosing
public class AbstractConverter extends ConverterImpl {
//~ Constructors -----------------------------------------------------------

Expand Down Expand Up @@ -136,11 +138,11 @@ public ExpandConversionRule(RelBuilderFactory relBuilderFactory) {
}

/** Rule configuration. */
@Value.Immutable
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
Config DEFAULT = ImmutableConverter.Config.of()
.withOperandSupplier(b ->
b.operand(AbstractConverter.class).anyInputs())
.as(Config.class);
b.operand(AbstractConverter.class).anyInputs());

@Override default ExpandConversionRule toRule() {
return new ExpandConversionRule(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ protected <R extends RelNode> ConverterRule(Class<R> clazz,
protected <R extends RelNode> ConverterRule(Class<R> clazz,
Predicate<? super R> predicate, RelTrait in, RelTrait out,
RelBuilderFactory relBuilderFactory, String descriptionPrefix) {
this(Config.EMPTY
this(ImmutableConverterRule.Config.builder()
.withRelBuilderFactory(relBuilderFactory)
.as(Config.class)
.build()
.withConversion(clazz, predicate, in, out, descriptionPrefix));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static class RemoveEmptySingleRule extends PruneEmptyRule {
@Deprecated // to be removed before 2.0
public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz,
String description) {
this(Config.EMPTY.withDescription(description)
this(ImmutablePruneEmptyRuleConfig.of().withDescription(description)
.as(Config.class)
.withOperandFor(clazz, singleRel -> true));
}
Expand All @@ -315,7 +315,7 @@ public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz,
public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz,
Predicate<R> predicate, RelBuilderFactory relBuilderFactory,
String description) {
this(Config.EMPTY.withRelBuilderFactory(relBuilderFactory)
this(ImmutablePruneEmptyRuleConfig.of().withRelBuilderFactory(relBuilderFactory)
.withDescription(description)
.as(Config.class)
.withOperandFor(clazz, predicate));
Expand All @@ -326,7 +326,7 @@ public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz,
public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz,
com.google.common.base.Predicate<R> predicate,
RelBuilderFactory relBuilderFactory, String description) {
this(Config.EMPTY.withRelBuilderFactory(relBuilderFactory)
this(ImmutablePruneEmptyRuleConfig.of().withRelBuilderFactory(relBuilderFactory)
.withDescription(description)
.as(Config.class)
.withOperandFor(clazz, predicate::apply));
Expand Down
Loading

0 comments on commit 5824c54

Please sign in to comment.