Skip to content

Commit

Permalink
[CALCITE-4839] Remove ImmutableBeans implementation and usage
Browse files Browse the repository at this point in the history
Also remove superseded rule configuration interfaces
  • Loading branch information
jacques-n committed Oct 20, 2021
1 parent bf962b8 commit bebe473
Show file tree
Hide file tree
Showing 41 changed files with 16 additions and 1,498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;

import org.immutables.value.Value;
Expand Down Expand Up @@ -166,8 +165,6 @@ public interface Config extends RelRule.Config {
*
* <p>Warning: if the batch size is around or bigger than 1000 there
* can be an error because the generated code exceeds the size limit. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.IntDefault(100)
@Value.Default default int batchSize() {
return 100;
}
Expand Down
25 changes: 1 addition & 24 deletions core/src/main/java/org/apache/calcite/plan/RelRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import com.google.common.collect.ImmutableList;

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

import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -128,32 +126,14 @@ protected RelRule(C config) {
}

/** Rule configuration. */
@SuppressWarnings("deprecation")
public interface Config {
/**
* Empty configuration.
*
* This is based on ImmutableBeans and dynamic proxies and has been replaced
* by the use of the Immutables annotation processor to pre-generate values.
*
* This field will be removed in a subsequent release.
* */
@Deprecated
RelRule.Config EMPTY = ImmutableBeans.create(Config.class)
.withRelBuilderFactory(RelFactories.LOGICAL_BUILDER)
.withOperandSupplier(b -> {
throw new IllegalArgumentException("Rules must have at least one "
+ "operand. Call Config.withOperandSupplier to specify them.");
});

/** Creates a rule that uses this configuration. Sub-class must override. */
RelOptRule toRule();

/** Casts this configuration to another type, usually a sub-class. */
default <T extends Object> T as(Class<T> class_) {
if (Proxy.isProxyClass(this.getClass())) {
return ImmutableBeans.copy(class_, this);
} else if (class_.isAssignableFrom(this.getClass())) {
if (class_.isAssignableFrom(this.getClass())) {
return class_.cast(this);
} else {
throw new UnsupportedOperationException(
Expand All @@ -166,7 +146,6 @@ default <T extends Object> T as(Class<T> class_) {

/** The factory that is used to create a
* {@link org.apache.calcite.tools.RelBuilder} during rule invocations. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@Value.Default default RelBuilderFactory relBuilderFactory() {
return RelFactories.LOGICAL_BUILDER;
}
Expand All @@ -176,14 +155,12 @@ default <T extends Object> T as(Class<T> class_) {

/** Description of the rule instance. */
// CALCITE-4831: remove the second nullable annotation once immutables/#1261 is fixed
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@javax.annotation.Nullable @Nullable String description();

/** Sets {@link #description()}. */
Config withDescription(@Nullable String description);

/** Creates the operands for the rule instance. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@Value.Default default OperandTransform operandSupplier() {
return s -> {
throw new IllegalArgumentException("Rules must have at least one "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.calcite.plan.RelTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;
Expand Down Expand Up @@ -191,19 +190,16 @@ public interface Config extends RelRule.Config {
}
}).build();

@SuppressWarnings("deprecation") @ImmutableBeans.Property
RelTrait inTrait();

/** Sets {@link #inTrait}. */
Config withInTrait(RelTrait trait);

@SuppressWarnings("deprecation") @ImmutableBeans.Property
RelTrait outTrait();

/** Sets {@link #outTrait}. */
Config withOutTrait(RelTrait trait);

@SuppressWarnings("deprecation") @ImmutableBeans.Property
Function<Config, ConverterRule> ruleFactory();

/** Sets {@link #outTrait}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;
Expand Down Expand Up @@ -98,7 +97,6 @@ public interface Config extends RelRule.Config {

/** Returns the rule to be restricted; rule must take a single
* operand expecting a single input. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
ConverterRule converterRule();

/** Sets {@link #converterRule()}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.calcite.sql.fun.SqlSumEmptyIsZeroAggFunction;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Optionality;
Expand Down Expand Up @@ -943,8 +942,6 @@ public interface Config extends RelRule.Config {
}

/** Whether to use GROUPING SETS, default true. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean isUsingGroupingSets() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.calcite.sql.fun.SqlInternalOperators;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Util;
Expand Down Expand Up @@ -530,8 +529,6 @@ public interface Config extends RelRule.Config {
* {@code throwIfNotUnique} is true, the query would throw because of the
* values [100, 120]; if false, the query would sum the distinct values
* [100, 120, 150]. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean throwIfNotUnique() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.Bug;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.mapping.Mapping;
Expand Down Expand Up @@ -470,8 +469,6 @@ public interface Config extends RelRule.Config {
}

/** Whether to push down aggregate functions, default false. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(false)
@Value.Default
default boolean isAllowFunctions() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.CompositeList;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Util;
Expand Down Expand Up @@ -850,7 +849,6 @@ public interface Config extends RelRule.Config {
return new AggregateReduceFunctionsRule(this);
}

@SuppressWarnings("deprecation") @ImmutableBeans.Property
@Nullable Set<SqlKind> functionsToReduce();

/** Sets {@link #functionsToReduce}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;
Expand Down Expand Up @@ -124,8 +123,6 @@ public interface Config extends RelRule.Config {
}

/** Whether to coerce names. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(false)
@Value.Default default boolean isCoerceNames() {
return false;
}
Expand All @@ -134,7 +131,6 @@ public interface Config extends RelRule.Config {
Config withCoerceNames(boolean coerceNames);

/** Class of {@link RelNode} to coerce to. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
Class<? extends RelNode> consumerRelClass();

/** Sets {@link #consumerRelClass()}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private DateRangeRules() { }
* {@code FLOOR} and {@code CEIL} functions to date ranges (typically using
* the {@code BETWEEN} operator). */
public static final RelOptRule FILTER_INSTANCE =
FilterDateRangeRule.Config.DEFAULT
FilterDateRangeRule.FilterDateRangeRuleConfig.DEFAULT
.as(FilterDateRangeRule.FilterDateRangeRuleConfig.class)
.toRule();

Expand Down Expand Up @@ -215,10 +215,6 @@ assert requireNonNull(finder, "finder").timeUnits.isEmpty() && finder.opKinds.is
call.transformTo(relBuilder.build());
}

/** Deprecated, use {@link FilterDateRangeRuleConfig} instead. **/
@Deprecated
public interface Config extends FilterDateRangeRuleConfig { }

/** Rule configuration. */
@Value.Immutable
public interface FilterDateRangeRuleConfig extends RelRule.Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.calcite.rel.logical.LogicalSortExchange;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.util.ImmutableBeans;

import org.immutables.value.Value;

Expand Down Expand Up @@ -195,7 +194,6 @@ public interface Config extends RelRule.Config {
}

/** Forwards a call to {@link #onMatch(RelOptRuleCall)}. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@Value.Parameter
MatchHandler<ExchangeRemoveConstantKeysRule> matchHandler();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -308,10 +307,6 @@ public JoinConditionPushRule(RelFactories.FilterFactory filterFactory,
perform(call, null, join);
}

/** Deprecated, use {@link JoinConditionPushRuleConfig} instead. **/
@Deprecated
public interface Config extends JoinConditionPushRuleConfig { }

/** Rule configuration. */
@Value.Immutable(singleton = false)
public interface JoinConditionPushRuleConfig extends FilterJoinRule.Config {
Expand Down Expand Up @@ -371,10 +366,6 @@ public FilterIntoJoinRule(boolean smart,
perform(call, filter, join);
}

/** Deprecated, use {@link FilterIntoJoinRuleConfig} instead. **/
@Deprecated
public interface Config extends FilterIntoJoinRuleConfig { }

/** Rule configuration. */
@Value.Immutable(singleton = false)
public interface FilterIntoJoinRuleConfig extends FilterJoinRule.Config {
Expand Down Expand Up @@ -404,8 +395,6 @@ public interface Predicate {
*/
public interface Config extends RelRule.Config {
/** Whether to try to strengthen join-type, default false. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(false)
@Value.Default default boolean isSmart() {
return false;
}
Expand All @@ -416,7 +405,6 @@ public interface Config extends RelRule.Config {
/** Predicate that returns whether a filter is valid in the ON clause of a
* join for this particular kind of join. If not, Calcite will push it back to
* above the join. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@Value.Parameter
Predicate getPredicate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import org.immutables.value.Value;

Expand Down Expand Up @@ -221,8 +220,6 @@ public interface Config extends RelRule.Config {

/** Whether to create a {@link Filter} of the same convention as the
* matched Filter. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean isCopyFilter() {
return true;
}
Expand All @@ -232,8 +229,6 @@ public interface Config extends RelRule.Config {

/** Whether to create a {@link Project} of the same convention as the
* matched Project. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean isCopyProject() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.calcite.rex.RexPermuteInputsShuttle;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.mapping.Mappings;

Expand Down Expand Up @@ -179,8 +178,6 @@ public interface Config extends RelRule.Config {
* Whether to emit the new join tree if the new top or bottom join has a condition which
* is always {@code TRUE}.
*/
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean isAllowAlwaysTrueCondition() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;
Expand Down Expand Up @@ -251,8 +250,6 @@ default Config withOperandFor(Class<? extends Join> joinClass) {
}

/** Whether to swap outer joins; default false. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(false)
@Value.Default default boolean isSwapOuter() {
return false;
}
Expand All @@ -262,8 +259,6 @@ default Config withOperandFor(Class<? extends Join> joinClass) {

/** Whether to emit the new join tree if the join condition is {@code TRUE}
* (that is, cartesian joins); default true. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(true)
@Value.Default default boolean isAllowAlwaysTrueCondition() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.calcite.util.Pair;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -428,8 +427,6 @@ public interface Config extends RelRule.Config {
}

/** Whether to include outer joins, default false. */
@SuppressWarnings("deprecation") @ImmutableBeans.Property
@ImmutableBeans.BooleanDefault(false)
@Value.Default default boolean isIncludeOuter() {
return false;
}
Expand Down
Loading

0 comments on commit bebe473

Please sign in to comment.