http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectFilterTransposeRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectFilterTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectFilterTransposeRule.java index f468f9c..dd1c0c9 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectFilterTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectFilterTransposeRule.java @@ -34,9 +34,9 @@ import org.apache.calcite.tools.RelBuilderFactory; * past a {@link org.apache.calcite.rel.core.Filter}. */ public class ProjectFilterTransposeRule extends RelOptRule { - public static final ProjectFilterTransposeRule INSTANCE = new ProjectFilterTransposeRule( - LogicalProject.class, LogicalFilter.class, RelFactories.LOGICAL_BUILDER, - PushProjector.ExprCondition.FALSE); + public static final ProjectFilterTransposeRule INSTANCE = + new ProjectFilterTransposeRule(LogicalProject.class, LogicalFilter.class, + RelFactories.LOGICAL_BUILDER, expr -> false); //~ Instance fields --------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java index 2983703..34dee11 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinTransposeRule.java @@ -38,8 +38,7 @@ import java.util.List; */ public class ProjectJoinTransposeRule extends RelOptRule { public static final ProjectJoinTransposeRule INSTANCE = - new ProjectJoinTransposeRule( - PushProjector.ExprCondition.TRUE, + new ProjectJoinTransposeRule(expr -> true, RelFactories.LOGICAL_BUILDER); //~ Instance fields -------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java index cc773fb..515b779 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java @@ -24,11 +24,8 @@ import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexUtil; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.tools.RelBuilderFactory; -import com.google.common.base.Predicate; - import java.util.List; /** @@ -43,14 +40,6 @@ import java.util.List; * @see ProjectMergeRule */ public class ProjectRemoveRule extends RelOptRule { - //~ Static fields/initializers --------------------------------------------- - private static final Predicate<Project> PREDICATE = - new PredicateImpl<Project>() { - public boolean test(Project input) { - return isTrivial(input); - } - }; - public static final ProjectRemoveRule INSTANCE = new ProjectRemoveRule(RelFactories.LOGICAL_BUILDER); @@ -64,8 +53,8 @@ public class ProjectRemoveRule extends RelOptRule { public ProjectRemoveRule(RelBuilderFactory relBuilderFactory) { // Create a specialized operand to detect non-matches early. This keeps // the rule queue short. - super(operand(Project.class, null, PREDICATE, any()), relBuilderFactory, - null); + super(operandJ(Project.class, null, ProjectRemoveRule::isTrivial, any()), + relBuilderFactory, null); } //~ Methods ---------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectSetOpTransposeRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectSetOpTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectSetOpTransposeRule.java index 48fb027..6190556 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectSetOpTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectSetOpTransposeRule.java @@ -40,8 +40,8 @@ import java.util.List; */ public class ProjectSetOpTransposeRule extends RelOptRule { public static final ProjectSetOpTransposeRule INSTANCE = - new ProjectSetOpTransposeRule( - PushProjector.ExprCondition.FALSE, RelFactories.LOGICAL_BUILDER); + new ProjectSetOpTransposeRule(expr -> false, + RelFactories.LOGICAL_BUILDER); //~ Instance fields -------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java index bd4b5fe..777aa19 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectTableScanRule.java @@ -26,14 +26,12 @@ import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rel.core.TableScan; import org.apache.calcite.rex.RexNode; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.schema.ProjectableFilterableTable; import org.apache.calcite.tools.RelBuilderFactory; import org.apache.calcite.util.ImmutableIntList; import org.apache.calcite.util.mapping.Mapping; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import java.util.List; @@ -50,20 +48,17 @@ import java.util.List; * @see FilterTableScanRule */ public abstract class ProjectTableScanRule extends RelOptRule { - public static final Predicate<TableScan> PREDICATE = - new PredicateImpl<TableScan>() { - public boolean test(TableScan scan) { - // We can only push projects into a ProjectableFilterableTable. - final RelOptTable table = scan.getTable(); - return table.unwrap(ProjectableFilterableTable.class) != null; - } - }; + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public static final com.google.common.base.Predicate<TableScan> PREDICATE = + ProjectTableScanRule::test; /** Rule that matches Project on TableScan. */ public static final ProjectTableScanRule INSTANCE = new ProjectTableScanRule( operand(Project.class, - operand(TableScan.class, null, PREDICATE, none())), + operandJ(TableScan.class, null, ProjectTableScanRule::test, + none())), RelFactories.LOGICAL_BUILDER, "ProjectScanRule") { @Override public void onMatch(RelOptRuleCall call) { @@ -78,7 +73,8 @@ public abstract class ProjectTableScanRule extends RelOptRule { new ProjectTableScanRule( operand(Project.class, operand(EnumerableInterpreter.class, - operand(TableScan.class, null, PREDICATE, none()))), + operandJ(TableScan.class, null, ProjectTableScanRule::test, + none()))), RelFactories.LOGICAL_BUILDER, "ProjectScanRule:interpreter") { @Override public void onMatch(RelOptRuleCall call) { @@ -98,6 +94,12 @@ public abstract class ProjectTableScanRule extends RelOptRule { //~ Methods ---------------------------------------------------------------- + protected static boolean test(TableScan scan) { + // We can only push projects into a ProjectableFilterableTable. + final RelOptTable table = scan.getTable(); + return table.unwrap(ProjectableFilterableTable.class) != null; + } + protected void apply(RelOptRuleCall call, Project project, TableScan scan) { final RelOptTable table = scan.getTable(); assert table.unwrap(ProjectableFilterableTable.class) != null; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java index 4b7a4dc..b85fd44 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java @@ -38,7 +38,6 @@ import org.apache.calcite.rex.RexOver; import org.apache.calcite.rex.RexProgram; import org.apache.calcite.rex.RexVisitorImpl; import org.apache.calcite.rex.RexWindow; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelBuilderFactory; import org.apache.calcite.util.ImmutableIntList; @@ -48,11 +47,9 @@ import org.apache.calcite.util.graph.DefaultEdge; import org.apache.calcite.util.graph.DirectedGraph; import org.apache.calcite.util.graph.TopologicalOrderIterator; -import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.util.ArrayDeque; import java.util.ArrayList; @@ -78,20 +75,6 @@ import java.util.Set; public abstract class ProjectToWindowRule extends RelOptRule { //~ Static fields/initializers --------------------------------------------- - private static final Predicate<Calc> PREDICATE = - new PredicateImpl<Calc>() { - public boolean test(Calc calc) { - return RexOver.containsOver(calc.getProgram()); - } - }; - - private static final Predicate<Project> PREDICATE2 = - new PredicateImpl<Project>() { - public boolean test(Project project) { - return RexOver.containsOver(project.getProjects(), null); - } - }; - public static final ProjectToWindowRule INSTANCE = new CalcToWindowRule(RelFactories.LOGICAL_BUILDER); @@ -129,7 +112,8 @@ public abstract class ProjectToWindowRule extends RelOptRule { */ public CalcToWindowRule(RelBuilderFactory relBuilderFactory) { super( - operand(Calc.class, null, PREDICATE, any()), + operandJ(Calc.class, null, + calc -> RexOver.containsOver(calc.getProgram()), any()), relBuilderFactory, "ProjectToWindowRule"); } @@ -158,7 +142,10 @@ public abstract class ProjectToWindowRule extends RelOptRule { */ public ProjectToLogicalProjectAndWindowRule( RelBuilderFactory relBuilderFactory) { - super(operand(Project.class, null, PREDICATE2, any()), + super( + operandJ(Project.class, null, + project -> RexOver.containsOver(project.getProjects(), null), + any()), relBuilderFactory, "ProjectToWindowRule:project"); } @@ -191,11 +178,7 @@ public abstract class ProjectToWindowRule extends RelOptRule { if (!program.projectsOnlyIdentity()) { relBuilder.project( Lists.transform(program.getProjectList(), - new Function<RexLocalRef, RexNode>() { - public RexNode apply(RexLocalRef a0) { - return program.expandLocalRef(a0); - } - }), + program::expandLocalRef), calc.getRowType().getFieldNames()); } return relBuilder.build(); @@ -314,7 +297,7 @@ public abstract class ProjectToWindowRule extends RelOptRule { // This RexOver cannot be added into any existing cohort if (!isFound) { - final Set<Integer> newSet = Sets.newHashSet(i); + final Set<Integer> newSet = new HashSet<>(ImmutableList.of(i)); windowToIndices.add(Pair.of(over.getWindow(), newSet)); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java b/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java index f6a89ad..1cc48b5 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java @@ -37,15 +37,14 @@ import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelBuilderFactory; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import static org.apache.calcite.plan.RelOptRule.any; import static org.apache.calcite.plan.RelOptRule.none; import static org.apache.calcite.plan.RelOptRule.operand; +import static org.apache.calcite.plan.RelOptRule.operandJ; import static org.apache.calcite.plan.RelOptRule.some; import static org.apache.calcite.plan.RelOptRule.unordered; @@ -76,7 +75,7 @@ public abstract class PruneEmptyRules { public static final RelOptRule UNION_INSTANCE = new RelOptRule( operand(LogicalUnion.class, - unordered(operand(Values.class, null, Values.IS_EMPTY, none()))), + unordered(operandJ(Values.class, null, Values::isEmpty, none()))), "Union") { public void onMatch(RelOptRuleCall call) { final LogicalUnion union = call.rel(0); @@ -124,7 +123,8 @@ public abstract class PruneEmptyRules { public static final RelOptRule MINUS_INSTANCE = new RelOptRule( operand(LogicalMinus.class, - unordered(operand(Values.class, null, Values.IS_EMPTY, none()))), + unordered( + operandJ(Values.class, null, Values::isEmpty, none()))), "Minus") { public void onMatch(RelOptRuleCall call) { final LogicalMinus minus = call.rel(0); @@ -177,7 +177,8 @@ public abstract class PruneEmptyRules { public static final RelOptRule INTERSECT_INSTANCE = new RelOptRule( operand(LogicalIntersect.class, - unordered(operand(Values.class, null, Values.IS_EMPTY, none()))), + unordered( + operandJ(Values.class, null, Values::isEmpty, none()))), "Intersect") { public void onMatch(RelOptRuleCall call) { LogicalIntersect intersect = call.rel(0); @@ -203,8 +204,9 @@ public abstract class PruneEmptyRules { * </ul> */ public static final RelOptRule PROJECT_INSTANCE = - new RemoveEmptySingleRule(Project.class, Predicates.<Project>alwaysTrue(), - RelFactories.LOGICAL_BUILDER, "PruneEmptyProject"); + new RemoveEmptySingleRule(Project.class, + (Predicate<Project>) project -> true, RelFactories.LOGICAL_BUILDER, + "PruneEmptyProject"); /** * Rule that converts a {@link org.apache.calcite.rel.logical.LogicalFilter} @@ -271,7 +273,8 @@ public abstract class PruneEmptyRules { * @see AggregateValuesRule */ public static final RelOptRule AGGREGATE_INSTANCE = - new RemoveEmptySingleRule(Aggregate.class, Aggregate.IS_NOT_GRAND_TOTAL, + new RemoveEmptySingleRule(Aggregate.class, + (Predicate<Aggregate>) Aggregate::isNotGrandTotal, RelFactories.LOGICAL_BUILDER, "PruneEmptyAggregate"); /** @@ -288,7 +291,7 @@ public abstract class PruneEmptyRules { new RelOptRule( operand(Join.class, some( - operand(Values.class, null, Values.IS_EMPTY, none()), + operandJ(Values.class, null, Values::isEmpty, none()), operand(RelNode.class, any()))), "PruneEmptyJoin(left)") { @Override public void onMatch(RelOptRuleCall call) { @@ -317,7 +320,7 @@ public abstract class PruneEmptyRules { operand(Join.class, some( operand(RelNode.class, any()), - operand(Values.class, null, Values.IS_EMPTY, none()))), + operandJ(Values.class, null, Values::isEmpty, none()))), "PruneEmptyJoin(right)") { @Override public void onMatch(RelOptRuleCall call) { Join join = call.rel(0); @@ -333,10 +336,10 @@ public abstract class PruneEmptyRules { /** Planner rule that converts a single-rel (e.g. project, sort, aggregate or * filter) on top of the empty relational expression into empty. */ public static class RemoveEmptySingleRule extends RelOptRule { - /** Creatse a simple RemoveEmptySingleRule. */ + /** Creates a simple RemoveEmptySingleRule. */ public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz, String description) { - this(clazz, Predicates.<R>alwaysTrue(), RelFactories.LOGICAL_BUILDER, + this(clazz, (Predicate<R>) project -> true, RelFactories.LOGICAL_BUILDER, description); } @@ -345,11 +348,20 @@ public abstract class PruneEmptyRules { Predicate<R> predicate, RelBuilderFactory relBuilderFactory, String description) { super( - operand(clazz, null, predicate, - operand(Values.class, null, Values.IS_EMPTY, none())), + operandJ(clazz, null, predicate, + operandJ(Values.class, null, Values::isEmpty, none())), relBuilderFactory, description); } + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public <R extends SingleRel> RemoveEmptySingleRule(Class<R> clazz, + com.google.common.base.Predicate<R> predicate, + RelBuilderFactory relBuilderFactory, String description) { + this(clazz, (Predicate<R>) predicate::apply, relBuilderFactory, + description); + } + public void onMatch(RelOptRuleCall call) { SingleRel single = call.rel(0); call.transformTo(call.builder().push(single).empty().build()); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java index 60a9663..22b8d63 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java @@ -32,7 +32,6 @@ import org.apache.calcite.rex.RexInputRef; import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexUtil; import org.apache.calcite.rex.RexVisitorImpl; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.sql.SemiJoinType; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.tools.RelBuilder; @@ -40,16 +39,15 @@ import org.apache.calcite.util.BitSets; import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.BitSet; import java.util.List; +import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; /** * PushProjector is a utility class used to perform operations used in push @@ -212,7 +210,7 @@ public class PushProjector { this.origFilter = origFilter; this.childRel = childRel; this.preserveExprCondition = preserveExprCondition; - this.relBuilder = Preconditions.checkNotNull(relBuilder); + this.relBuilder = Objects.requireNonNull(relBuilder); if (origProj == null) { origProjExprs = ImmutableList.of(); } else { @@ -615,7 +613,7 @@ public class PushProjector { * @return the created projection */ public RelNode createNewProject(RelNode projChild, int[] adjustments) { - final List<Pair<RexNode, String>> projects = Lists.newArrayList(); + final List<Pair<RexNode, String>> projects = new ArrayList<>(); if (origProj != null) { for (Pair<RexNode, String> p : origProj.getNamedProjects()) { @@ -850,34 +848,19 @@ public class PushProjector { /** * Constant condition that replies {@code false} for all expressions. */ - ExprCondition FALSE = - new ExprConditionImpl() { - @Override public boolean test(RexNode expr) { - return false; - } - }; + ExprCondition FALSE = expr -> false; /** * Constant condition that replies {@code true} for all expressions. */ - ExprCondition TRUE = - new ExprConditionImpl() { - @Override public boolean test(RexNode expr) { - return true; - } - }; - } - - /** Implementation of {@link ExprCondition}. */ - abstract static class ExprConditionImpl extends PredicateImpl<RexNode> - implements ExprCondition { + ExprCondition TRUE = expr -> true; } /** * An expression condition that evaluates to true if the expression is * a call to one of a set of operators. */ - class OperatorExprCondition extends ExprConditionImpl { + class OperatorExprCondition implements ExprCondition { private final Set<SqlOperator> operatorSet; /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java index 296cf35..a3ae9d9 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java @@ -377,7 +377,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule { final List<RexNode> exprList = program.getExprList(); // Form a list of expressions with sub-expressions fully expanded. - final List<RexNode> expandedExprList = Lists.newArrayList(); + final List<RexNode> expandedExprList = new ArrayList<>(); final RexShuttle shuttle = new RexShuttle() { public RexNode visitLocalRef(RexLocalRef localRef) { @@ -394,7 +394,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule { new RexProgramBuilder( calc.getInput().getRowType(), calc.getCluster().getRexBuilder()); - final List<RexLocalRef> list = Lists.newArrayList(); + final List<RexLocalRef> list = new ArrayList<>(); for (RexNode expr : expandedExprList) { list.add(builder.registerInput(expr)); } @@ -563,9 +563,9 @@ public abstract class ReduceExpressionsRule extends RelOptRule { changed |= new CaseShuttle().mutate(expList); // Find reducible expressions. - final List<RexNode> constExps = Lists.newArrayList(); - List<Boolean> addCasts = Lists.newArrayList(); - final List<RexNode> removableCasts = Lists.newArrayList(); + final List<RexNode> constExps = new ArrayList<>(); + List<Boolean> addCasts = new ArrayList<>(); + final List<RexNode> removableCasts = new ArrayList<>(); findReducibleExps(rel.getCluster().getTypeFactory(), expList, predicates.constantMap, constExps, addCasts, removableCasts); if (constExps.isEmpty() && removableCasts.isEmpty()) { @@ -577,7 +577,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule { // reducing that argument to a constant first will result in not being // able to locate the original cast expression. if (!removableCasts.isEmpty()) { - final List<RexNode> reducedExprs = Lists.newArrayList(); + final List<RexNode> reducedExprs = new ArrayList<>(); for (RexNode exp : removableCasts) { RexCall call = (RexCall) exp; reducedExprs.add(call.getOperands().get(0)); @@ -616,7 +616,7 @@ public abstract class ReduceExpressionsRule extends RelOptRule { return changed; } - final List<RexNode> reducedValues = Lists.newArrayList(); + final List<RexNode> reducedValues = new ArrayList<>(); executor.reduce(simplify.rexBuilder, constExps2, reducedValues); // Use RexNode.digest to judge whether each newly generated RexNode http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java index 39db46d..c236015 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java @@ -28,16 +28,14 @@ import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexNode; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelBuilderFactory; import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.ImmutableIntList; -import com.google.common.base.Predicate; -import com.google.common.collect.Lists; - +import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; /** * Planner rule that creates a {@code SemiJoinRule} from a @@ -46,25 +44,19 @@ import java.util.List; */ public abstract class SemiJoinRule extends RelOptRule { private static final Predicate<Join> IS_LEFT_OR_INNER = - new PredicateImpl<Join>() { - public boolean test(Join input) { - switch (input.getJoinType()) { - case LEFT: - case INNER: - return true; - default: - return false; - } + join -> { + switch (join.getJoinType()) { + case LEFT: + case INNER: + return true; + default: + return false; } }; /* Tests if an Aggregate always produces 1 row and 0 columns. */ private static final Predicate<Aggregate> IS_EMPTY_AGGREGATE = - new PredicateImpl<Aggregate>() { - public boolean test(Aggregate input) { - return input.getRowType().getFieldCount() == 0; - } - }; + aggregate -> aggregate.getRowType().getFieldCount() == 0; public static final SemiJoinRule PROJECT = new ProjectToSemiJoinRule(Project.class, Join.class, Aggregate.class, @@ -80,7 +72,7 @@ public abstract class SemiJoinRule extends RelOptRule { super( operand(projectClass, some( - operand(joinClass, null, IS_LEFT_OR_INNER, + operandJ(joinClass, null, IS_LEFT_OR_INNER, some(operand(RelNode.class, any()), operand(aggregateClass, any()))))), relBuilderFactory, description); @@ -89,9 +81,9 @@ public abstract class SemiJoinRule extends RelOptRule { protected SemiJoinRule(Class<Join> joinClass, Class<Aggregate> aggregateClass, RelBuilderFactory relBuilderFactory, String description) { super( - operand(joinClass, null, IS_LEFT_OR_INNER, + operandJ(joinClass, null, IS_LEFT_OR_INNER, some(operand(RelNode.class, any()), - operand(aggregateClass, null, IS_EMPTY_AGGREGATE, any()))), + operandJ(aggregateClass, null, IS_EMPTY_AGGREGATE, any()))), relBuilderFactory, description); } @@ -123,7 +115,7 @@ public abstract class SemiJoinRule extends RelOptRule { relBuilder.push(left); switch (join.getJoinType()) { case INNER: - final List<Integer> newRightKeyBuilder = Lists.newArrayList(); + final List<Integer> newRightKeyBuilder = new ArrayList<>(); final List<Integer> aggregateKeys = aggregate.getGroupSet().asList(); for (int key : joinInfo.rightKeys) { newRightKeyBuilder.add(aggregateKeys.get(key)); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java index 04fbb6d..6a1c76b 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SortJoinTransposeRule.java @@ -34,7 +34,6 @@ import org.apache.calcite.rel.metadata.RelMdUtil; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.tools.RelBuilderFactory; - /** * Planner rule that pushes a {@link org.apache.calcite.rel.core.Sort} past a * {@link org.apache.calcite.rel.core.Join}. http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java index 19cde5f..8bdcdd2 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SortProjectTransposeRule.java @@ -140,7 +140,7 @@ public class SortProjectTransposeRule extends RelOptRule { RelNode newProject = project.copy( sort.getTraitSet(), - ImmutableList.<RelNode>of(newSort)); + ImmutableList.of(newSort)); // Not only is newProject equivalent to sort; // newSort is equivalent to project's input // (but only if the sort is not also applying an offset/limit). http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java index 628219f..974c57d 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java @@ -497,8 +497,9 @@ public abstract class SubQueryRemoveRule extends RelOptRule { public static class SubQueryProjectRemoveRule extends SubQueryRemoveRule { public SubQueryProjectRemoveRule(RelBuilderFactory relBuilderFactory) { super( - operand(Project.class, null, RexUtil.SubQueryFinder.PROJECT_PREDICATE, - any()), relBuilderFactory, "SubQueryRemoveRule:Project"); + operandJ(Project.class, null, + RexUtil.SubQueryFinder::containsSubQuery, any()), + relBuilderFactory, "SubQueryRemoveRule:Project"); } public void onMatch(RelOptRuleCall call) { @@ -526,7 +527,7 @@ public abstract class SubQueryRemoveRule extends RelOptRule { public static class SubQueryFilterRemoveRule extends SubQueryRemoveRule { public SubQueryFilterRemoveRule(RelBuilderFactory relBuilderFactory) { super( - operand(Filter.class, null, RexUtil.SubQueryFinder.FILTER_PREDICATE, + operandJ(Filter.class, null, RexUtil.SubQueryFinder::containsSubQuery, any()), relBuilderFactory, "SubQueryRemoveRule:Filter"); } @@ -563,7 +564,7 @@ public abstract class SubQueryRemoveRule extends RelOptRule { public static class SubQueryJoinRemoveRule extends SubQueryRemoveRule { public SubQueryJoinRemoveRule(RelBuilderFactory relBuilderFactory) { super( - operand(Join.class, null, RexUtil.SubQueryFinder.JOIN_PREDICATE, + operandJ(Join.class, null, RexUtil.SubQueryFinder::containsSubQuery, any()), relBuilderFactory, "SubQueryRemoveRule:Join"); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java index 9fb0426..b7cfab3 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java @@ -118,7 +118,7 @@ public class UnionPullUpConstantsRule extends RelOptRule { List<Pair<RexNode, String>> newChildExprs = new ArrayList<>(); for (int j : refsIndex) { newChildExprs.add( - Pair.<RexNode, String>of(rexBuilder.makeInputRef(input, j), + Pair.of(rexBuilder.makeInputRef(input, j), input.getRowType().getFieldList().get(j).getName())); } if (newChildExprs.isEmpty()) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java index b8b02c6..3774430 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ValuesReduceRule.java @@ -75,7 +75,7 @@ public abstract class ValuesReduceRule extends RelOptRule { public static final ValuesReduceRule FILTER_INSTANCE = new ValuesReduceRule( operand(LogicalFilter.class, - operand(LogicalValues.class, null, Values.IS_NOT_EMPTY, none())), + operandJ(LogicalValues.class, null, Values::isNotEmpty, none())), RelFactories.LOGICAL_BUILDER, "ValuesReduceRule(Filter)") { public void onMatch(RelOptRuleCall call) { @@ -92,7 +92,7 @@ public abstract class ValuesReduceRule extends RelOptRule { public static final ValuesReduceRule PROJECT_INSTANCE = new ValuesReduceRule( operand(LogicalProject.class, - operand(LogicalValues.class, null, Values.IS_NOT_EMPTY, none())), + operandJ(LogicalValues.class, null, Values::isNotEmpty, none())), RelFactories.LOGICAL_BUILDER, "ValuesReduceRule(Project)") { public void onMatch(RelOptRuleCall call) { @@ -110,7 +110,7 @@ public abstract class ValuesReduceRule extends RelOptRule { new ValuesReduceRule( operand(LogicalProject.class, operand(LogicalFilter.class, - operand(LogicalValues.class, null, Values.IS_NOT_EMPTY, + operandJ(LogicalValues.class, null, Values::isNotEmpty, none()))), RelFactories.LOGICAL_BUILDER, "ValuesReduceRule(Project-Filter)") { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/stream/StreamRules.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/stream/StreamRules.java b/core/src/main/java/org/apache/calcite/rel/stream/StreamRules.java index a1e0d58..02d8e68 100644 --- a/core/src/main/java/org/apache/calcite/rel/stream/StreamRules.java +++ b/core/src/main/java/org/apache/calcite/rel/stream/StreamRules.java @@ -45,8 +45,8 @@ import org.apache.calcite.tools.RelBuilderFactory; import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.List; /** @@ -130,7 +130,8 @@ public class StreamRules { public DeltaAggregateTransposeRule(RelBuilderFactory relBuilderFactory) { super( operand(Delta.class, - operand(Aggregate.class, null, Aggregate.NO_INDICATOR, any())), + operandJ(Aggregate.class, null, Aggregate::noIndicator, + any())), relBuilderFactory, null); } @@ -193,7 +194,7 @@ public class StreamRules { final Delta delta = call.rel(0); Util.discard(delta); final Union union = call.rel(1); - final List<RelNode> newInputs = Lists.newArrayList(); + final List<RelNode> newInputs = new ArrayList<>(); for (RelNode input : union.getInputs()) { final LogicalDelta newDelta = LogicalDelta.create(input); @@ -326,7 +327,7 @@ public class StreamRules { join.isSemiJoinDone(), ImmutableList.copyOf(join.getSystemFieldList())); - List<RelNode> inputsToUnion = Lists.newArrayList(); + List<RelNode> inputsToUnion = new ArrayList<>(); inputsToUnion.add(joinL); inputsToUnion.add(joinR); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/DynamicRecordTypeImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/DynamicRecordTypeImpl.java b/core/src/main/java/org/apache/calcite/rel/type/DynamicRecordTypeImpl.java index 82b6714..50f426b 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/DynamicRecordTypeImpl.java +++ b/core/src/main/java/org/apache/calcite/rel/type/DynamicRecordTypeImpl.java @@ -20,7 +20,8 @@ import org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Pair; -import java.util.Collections; +import com.google.common.collect.ImmutableList; + import java.util.List; /** @@ -69,7 +70,7 @@ public class DynamicRecordTypeImpl extends DynamicRecordType { } @Override public RelDataTypePrecedenceList getPrecedenceList() { - return new SqlTypeExplicitPrecedenceList(Collections.<SqlTypeName>emptyList()); + return new SqlTypeExplicitPrecedenceList(ImmutableList.of()); } protected void generateTypeString(StringBuilder sb, boolean withDetail) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java index da65d87..c83e6a2 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java +++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java @@ -23,12 +23,11 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.validate.SqlValidatorUtil; -import com.google.common.base.Preconditions; - import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; /** * RelDataTypeFactory is a factory for datatype descriptors. It defines methods @@ -408,7 +407,7 @@ public interface RelDataTypeFactory { * Creates a Builder with the given type factory. */ public Builder(RelDataTypeFactory typeFactory) { - this.typeFactory = Preconditions.checkNotNull(typeFactory); + this.typeFactory = Objects.requireNonNull(typeFactory); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java index 4151c1a..d529ff7 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java +++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java @@ -25,7 +25,6 @@ import org.apache.calcite.sql.type.SqlTypeUtil; import org.apache.calcite.util.Glossary; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -56,24 +55,23 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory { private static final LoadingCache<Object, RelDataType> CACHE = CacheBuilder.newBuilder() .softValues() - .build( - new CacheLoader<Object, RelDataType>() { - @Override public RelDataType load(@Nonnull Object k) { - if (k instanceof RelDataType) { - return (RelDataType) k; - } - @SuppressWarnings("unchecked") - final Key key = (Key) k; - final ImmutableList.Builder<RelDataTypeField> list = - ImmutableList.builder(); - for (int i = 0; i < key.names.size(); i++) { - list.add( - new RelDataTypeFieldImpl( - key.names.get(i), i, key.types.get(i))); - } - return new RelRecordType(key.kind, list.build()); - } - }); + .build(CacheLoader.from(RelDataTypeFactoryImpl::keyToType)); + + private static RelDataType keyToType(@Nonnull Object k) { + if (k instanceof RelDataType) { + return (RelDataType) k; + } + @SuppressWarnings("unchecked") + final Key key = (Key) k; + final ImmutableList.Builder<RelDataTypeField> list = + ImmutableList.builder(); + for (int i = 0; i < key.names.size(); i++) { + list.add( + new RelDataTypeFieldImpl( + key.names.get(i), i, key.types.get(i))); + } + return new RelRecordType(key.kind, list.build()); + } private static final Map<Class, RelDataTypeFamily> CLASS_FAMILIES = ImmutableMap.<Class, RelDataTypeFamily>builder() @@ -104,7 +102,7 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory { /** Creates a type factory. */ protected RelDataTypeFactoryImpl(RelDataTypeSystem typeSystem) { - this.typeSystem = Preconditions.checkNotNull(typeSystem); + this.typeSystem = Objects.requireNonNull(typeSystem); } //~ Methods ---------------------------------------------------------------- @@ -312,7 +310,7 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory { public RelDataType createTypeWithNullability( final RelDataType type, final boolean nullable) { - Preconditions.checkNotNull(type); + Objects.requireNonNull(type); RelDataType newType; if (type.isNullable() == nullable) { newType = type; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeField.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeField.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeField.java index 36acc1b..913c3a3 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeField.java +++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeField.java @@ -16,8 +16,6 @@ */ package org.apache.calcite.rel.type; -import com.google.common.base.Function; - import java.util.Map; /** @@ -34,8 +32,12 @@ public interface RelDataTypeField extends Map.Entry<String, RelDataType> { /** * Function to transform a set of {@link RelDataTypeField} to * a set of {@link Integer} of the field keys. + * + * @deprecated Use {@code RelDataTypeField::getIndex} */ - class ToFieldIndex implements Function<RelDataTypeField, Integer> { + @Deprecated // to be removed before 2.0 + class ToFieldIndex + implements com.google.common.base.Function<RelDataTypeField, Integer> { @Override public Integer apply(RelDataTypeField o) { return o.getIndex(); } @@ -44,8 +46,12 @@ public interface RelDataTypeField extends Map.Entry<String, RelDataType> { /** * Function to transform a set of {@link RelDataTypeField} to * a set of {@link String} of the field names. + * + * @deprecated Use {@code RelDataTypeField::getName} */ - class ToFieldName implements Function<RelDataTypeField, String> { + @Deprecated // to be removed before 2.0 + class ToFieldName + implements com.google.common.base.Function<RelDataTypeField, String> { @Override public String apply(RelDataTypeField o) { return o.getName(); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java index a559686..5c001f7 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java +++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java @@ -27,10 +27,10 @@ import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import java.io.Serializable; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.List; /** @@ -85,7 +85,7 @@ public abstract class RelDataTypeImpl } } if (elideRecord) { - final List<Slot> slots = Lists.newArrayList(); + final List<Slot> slots = new ArrayList<>(); getFieldRecurse(slots, this, 0, fieldName, caseSensitive); loop: for (Slot slot : slots) { @@ -298,11 +298,7 @@ public abstract class RelDataTypeImpl */ public static RelProtoDataType proto(final RelDataType protoType) { assert protoType != null; - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - return typeFactory.copyType(protoType); - } - }; + return typeFactory -> typeFactory.copyType(protoType); } /** Returns a {@link org.apache.calcite.rel.type.RelProtoDataType} @@ -318,11 +314,9 @@ public abstract class RelDataTypeImpl public static RelProtoDataType proto(final SqlTypeName typeName, final boolean nullable) { assert typeName != null; - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - final RelDataType type = typeFactory.createSqlType(typeName); - return typeFactory.createTypeWithNullability(type, nullable); - } + return typeFactory -> { + final RelDataType type = typeFactory.createSqlType(typeName); + return typeFactory.createTypeWithNullability(type, nullable); }; } @@ -340,11 +334,9 @@ public abstract class RelDataTypeImpl public static RelProtoDataType proto(final SqlTypeName typeName, final int precision, final boolean nullable) { assert typeName != null; - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - final RelDataType type = typeFactory.createSqlType(typeName, precision); - return typeFactory.createTypeWithNullability(type, nullable); - } + return typeFactory -> { + final RelDataType type = typeFactory.createSqlType(typeName, precision); + return typeFactory.createTypeWithNullability(type, nullable); }; } @@ -362,12 +354,10 @@ public abstract class RelDataTypeImpl */ public static RelProtoDataType proto(final SqlTypeName typeName, final int precision, final int scale, final boolean nullable) { - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - final RelDataType type = - typeFactory.createSqlType(typeName, precision, scale); - return typeFactory.createTypeWithNullability(type, nullable); - } + return typeFactory -> { + final RelDataType type = + typeFactory.createSqlType(typeName, precision, scale); + return typeFactory.createTypeWithNullability(type, nullable); }; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java b/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java index f8bf907..0bb4ed0 100644 --- a/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java +++ b/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java @@ -19,10 +19,9 @@ package org.apache.calcite.rel.type; import org.apache.calcite.linq4j.Ord; import org.apache.calcite.sql.type.SqlTypeName; -import com.google.common.base.Preconditions; - import java.io.Serializable; import java.util.List; +import java.util.Objects; /** * RelRecordType represents a structured type having named fields. @@ -39,7 +38,7 @@ public class RelRecordType extends RelDataTypeImpl implements Serializable { */ public RelRecordType(StructKind kind, List<RelDataTypeField> fields) { super(fields); - this.kind = Preconditions.checkNotNull(kind); + this.kind = Objects.requireNonNull(kind); computeDigest(); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java index 5dcc85b..4a26cd8 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java +++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java @@ -20,7 +20,6 @@ import org.apache.calcite.avatica.util.ByteString; import org.apache.calcite.avatica.util.DateTimeUtils; import org.apache.calcite.avatica.util.Spaces; import org.apache.calcite.avatica.util.TimeUnit; -import org.apache.calcite.rel.RelCollation; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.CorrelationId; @@ -49,7 +48,6 @@ import org.apache.calcite.util.TimeString; import org.apache.calcite.util.TimestampString; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -62,6 +60,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Factory for row expressions. @@ -78,13 +77,6 @@ public class RexBuilder { public static final SqlSpecialOperator GET_OPERATOR = new SqlSpecialOperator("_get", SqlKind.OTHER_FUNCTION); - private static final Function<RelDataTypeField, RexInputRef> TO_INPUT_REF = - new Function<RelDataTypeField, RexInputRef>() { - public RexInputRef apply(RelDataTypeField input) { - return new RexInputRef(input.getIndex(), input.getType()); - } - }; - //~ Instance fields -------------------------------------------------------- protected final RelDataTypeFactory typeFactory; @@ -128,7 +120,8 @@ public class RexBuilder { /** Creates a list of {@link org.apache.calcite.rex.RexInputRef} expressions, * projecting the fields of a given record type. */ public List<? extends RexNode> identityProjects(final RelDataType rowType) { - return Lists.transform(rowType.getFieldList(), TO_INPUT_REF); + return Lists.transform(rowType.getFieldList(), + input -> new RexInputRef(input.getIndex(), input.getType())); } //~ Methods ---------------------------------------------------------------- @@ -273,7 +266,7 @@ public class RexBuilder { List<? extends RexNode> exprs) { return op.inferReturnType( new RexCallBinding(typeFactory, op, exprs, - ImmutableList.<RelCollation>of())); + ImmutableList.of())); } /** @@ -391,7 +384,7 @@ public class RexBuilder { new RexOver( bigintType, SqlStdOperatorTable.COUNT, - ImmutableList.<RexNode>of(), + ImmutableList.of(), window, distinct), makeLiteral( @@ -1110,7 +1103,7 @@ public class RexBuilder { * Creates a Date literal. */ public RexLiteral makeDateLiteral(DateString date) { - return makeLiteral(Preconditions.checkNotNull(date), + return makeLiteral(Objects.requireNonNull(date), typeFactory.createSqlType(SqlTypeName.DATE), SqlTypeName.DATE); } @@ -1124,7 +1117,7 @@ public class RexBuilder { * Creates a Time literal. */ public RexLiteral makeTimeLiteral(TimeString time, int precision) { - return makeLiteral(Preconditions.checkNotNull(time), + return makeLiteral(Objects.requireNonNull(time), typeFactory.createSqlType(SqlTypeName.TIME, precision), SqlTypeName.TIME); } @@ -1135,7 +1128,7 @@ public class RexBuilder { public RexLiteral makeTimeWithLocalTimeZoneLiteral( TimeString time, int precision) { - return makeLiteral(Preconditions.checkNotNull(time), + return makeLiteral(Objects.requireNonNull(time), typeFactory.createSqlType(SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE, precision), SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE); } @@ -1152,7 +1145,7 @@ public class RexBuilder { */ public RexLiteral makeTimestampLiteral(TimestampString timestamp, int precision) { - return makeLiteral(Preconditions.checkNotNull(timestamp), + return makeLiteral(Objects.requireNonNull(timestamp), typeFactory.createSqlType(SqlTypeName.TIMESTAMP, precision), SqlTypeName.TIMESTAMP); } @@ -1163,7 +1156,7 @@ public class RexBuilder { public RexLiteral makeTimestampWithLocalTimeZoneLiteral( TimestampString timestamp, int precision) { - return makeLiteral(Preconditions.checkNotNull(timestamp), + return makeLiteral(Objects.requireNonNull(timestamp), typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, precision), SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexCall.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexCall.java b/core/src/main/java/org/apache/calcite/rex/RexCall.java index ac9e09e..498d86e 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexCall.java +++ b/core/src/main/java/org/apache/calcite/rex/RexCall.java @@ -22,10 +22,10 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlSyntax; import org.apache.calcite.util.Litmus; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.Objects; /** * An expression formed by a call to an operator with zero or more expressions @@ -56,8 +56,8 @@ public class RexCall extends RexNode { RelDataType type, SqlOperator op, List<? extends RexNode> operands) { - this.type = Preconditions.checkNotNull(type); - this.op = Preconditions.checkNotNull(op); + this.type = Objects.requireNonNull(type); + this.op = Objects.requireNonNull(op); this.operands = ImmutableList.copyOf(operands); assert op.getKind() != null : op; assert op.validRexOperands(operands.size(), Litmus.THROW) : this; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java b/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java index 2f6197a..750a97b 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java +++ b/core/src/main/java/org/apache/calcite/rex/RexCorrelVariable.java @@ -20,7 +20,7 @@ import org.apache.calcite.rel.core.CorrelationId; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.SqlKind; -import com.google.common.base.Preconditions; +import java.util.Objects; /** * Reference to the current row of a correlating relational expression. @@ -38,7 +38,7 @@ public class RexCorrelVariable extends RexVariable { CorrelationId id, RelDataType type) { super(id.getName(), type); - this.id = Preconditions.checkNotNull(id); + this.id = Objects.requireNonNull(id); } //~ Methods ---------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java index 99f8e78..a5e0aab 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java +++ b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java @@ -116,11 +116,8 @@ public class RexExecutorImpl implements RexExecutor { public void reduce(RexBuilder rexBuilder, List<RexNode> constExps, List<RexNode> reducedValues) { final String code = compile(rexBuilder, constExps, - new RexToLixTranslator.InputGetter() { - public Expression field(BlockBuilder list, int index, - Type storageType) { - throw new UnsupportedOperationException(); - } + (list, index, storageType) -> { + throw new UnsupportedOperationException(); }); final RexExecutable executable = new RexExecutable(code, constExps); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexLiteral.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java index 94ea886..ade5556 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java +++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java @@ -211,8 +211,8 @@ public class RexLiteral extends RexNode { RelDataType type, SqlTypeName typeName) { this.value = value; - this.type = Preconditions.checkNotNull(type); - this.typeName = Preconditions.checkNotNull(typeName); + this.type = Objects.requireNonNull(type); + this.typeName = Objects.requireNonNull(typeName); Preconditions.checkArgument(valueMatchesType(value, typeName, true)); Preconditions.checkArgument((value == null) == type.isNullable()); Preconditions.checkArgument(typeName != SqlTypeName.ANY); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexOver.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexOver.java b/core/src/main/java/org/apache/calcite/rex/RexOver.java index 7be2af3..fe7f7d9 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexOver.java +++ b/core/src/main/java/org/apache/calcite/rex/RexOver.java @@ -25,6 +25,7 @@ import org.apache.calcite.util.Util; import com.google.common.base.Preconditions; import java.util.List; +import java.util.Objects; /** * Call to an aggregate function over a window. @@ -66,7 +67,7 @@ public class RexOver extends RexCall { boolean distinct) { super(type, op, operands); Preconditions.checkArgument(op.isAggregator()); - this.window = Preconditions.checkNotNull(window); + this.window = Objects.requireNonNull(window); this.distinct = distinct; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexPermuteInputsShuttle.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexPermuteInputsShuttle.java b/core/src/main/java/org/apache/calcite/rex/RexPermuteInputsShuttle.java index 1750477..1d8d41e 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexPermuteInputsShuttle.java +++ b/core/src/main/java/org/apache/calcite/rex/RexPermuteInputsShuttle.java @@ -66,7 +66,7 @@ public class RexPermuteInputsShuttle extends RexShuttle { * otherwise works OK. */ public static RexPermuteInputsShuttle of(Mappings.TargetMapping mapping) { return new RexPermuteInputsShuttle(mapping, - ImmutableList.<RelDataTypeField>of()); + ImmutableList.of()); } //~ Methods ---------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexProgram.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexProgram.java b/core/src/main/java/org/apache/calcite/rex/RexProgram.java index e710386..32e438c 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexProgram.java +++ b/core/src/main/java/org/apache/calcite/rex/RexProgram.java @@ -34,7 +34,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Permutation; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import java.io.PrintWriter; @@ -514,7 +513,7 @@ public class RexProgram { * <p>Neither list is null. * The filters are evaluated first. */ public Pair<ImmutableList<RexNode>, ImmutableList<RexNode>> split() { - final List<RexNode> filters = Lists.newArrayList(); + final List<RexNode> filters = new ArrayList<>(); if (condition != null) { RelOptUtil.decomposeConjunction(expandLocalRef(condition), filters); } @@ -574,7 +573,7 @@ public class RexProgram { // to the output. outputCollations.add(RelCollations.of(fieldCollations)); } - Collections.sort(outputCollations, Ordering.natural()); + outputCollations.sort(Ordering.natural()); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java index 2964a48..a4a62d9 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java +++ b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java @@ -24,12 +24,11 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Workspace for constructing a {@link RexProgram}. @@ -67,8 +66,8 @@ public class RexProgramBuilder { */ private RexProgramBuilder(RelDataType inputRowType, RexBuilder rexBuilder, RexSimplify simplify) { - this.inputRowType = Preconditions.checkNotNull(inputRowType); - this.rexBuilder = Preconditions.checkNotNull(rexBuilder); + this.inputRowType = Objects.requireNonNull(inputRowType); + this.rexBuilder = Objects.requireNonNull(rexBuilder); this.simplify = simplify; // may be null this.validating = assertionsAreEnabled(); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexShuttle.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexShuttle.java b/core/src/main/java/org/apache/calcite/rex/RexShuttle.java index 6714be1..d79dcbf 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexShuttle.java +++ b/core/src/main/java/org/apache/calcite/rex/RexShuttle.java @@ -16,13 +16,11 @@ */ package org.apache.calcite.rex; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; /** * Passes over a row-expression, calling a handler method for each node, @@ -269,11 +267,8 @@ public class RexShuttle implements RexVisitor<RexNode> { * Applies this shuttle to each expression in an iterable. */ public final Iterable<RexNode> apply(Iterable<? extends RexNode> iterable) { - return Iterables.transform(iterable, new Function<RexNode, RexNode>() { - public RexNode apply(@Nullable RexNode t) { - return t == null ? null : t.accept(RexShuttle.this); - } - }); + return Iterables.transform(iterable, + t -> t == null ? null : t.accept(RexShuttle.this)); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexSimplify.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index d51ffe7..8ebf045 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -31,7 +31,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BoundType; import com.google.common.collect.ImmutableList; @@ -47,6 +46,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Function; @@ -76,11 +76,11 @@ public class RexSimplify { /** Internal constructor. */ private RexSimplify(RexBuilder rexBuilder, RelOptPredicateList predicates, boolean unknownAsFalse, boolean paranoid, RexExecutor executor) { - this.rexBuilder = Preconditions.checkNotNull(rexBuilder); - this.predicates = Preconditions.checkNotNull(predicates); + this.rexBuilder = Objects.requireNonNull(rexBuilder); + this.predicates = Objects.requireNonNull(predicates); this.unknownAsFalse = unknownAsFalse; this.paranoid = paranoid; - this.executor = Preconditions.checkNotNull(executor); + this.executor = Objects.requireNonNull(executor); } @Deprecated // to be removed before 2.0 @@ -1152,8 +1152,8 @@ public class RexSimplify { break; } final List<RexNode> reducedValues = new ArrayList<>(); - executor.reduce(rexBuilder, ImmutableList.<RexNode>of(e), reducedValues); - return Preconditions.checkNotNull( + executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues); + return Objects.requireNonNull( Iterables.getOnlyElement(reducedValues)); default: return e; @@ -1504,9 +1504,9 @@ public class RexSimplify { final RexLiteral literal; private Comparison(RexNode ref, SqlKind kind, RexLiteral literal) { - this.ref = Preconditions.checkNotNull(ref); - this.kind = Preconditions.checkNotNull(kind); - this.literal = Preconditions.checkNotNull(literal); + this.ref = Objects.requireNonNull(ref); + this.kind = Objects.requireNonNull(kind); + this.literal = Objects.requireNonNull(literal); } /** Creates a comparison, or returns null. */ @@ -1545,8 +1545,8 @@ public class RexSimplify { final SqlKind kind; private IsPredicate(RexNode ref, SqlKind kind) { - this.ref = Preconditions.checkNotNull(ref); - this.kind = Preconditions.checkNotNull(kind); + this.ref = Objects.requireNonNull(ref); + this.kind = Objects.requireNonNull(kind); } /** Creates an IS predicate, or returns null. */ http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexSqlStandardConvertletTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexSqlStandardConvertletTable.java b/core/src/main/java/org/apache/calcite/rex/RexSqlStandardConvertletTable.java index e69dfc1..e93df95 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSqlStandardConvertletTable.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSqlStandardConvertletTable.java @@ -189,26 +189,21 @@ public class RexSqlStandardConvertletTable */ private void registerTypeAppendOp(final SqlOperator op) { registerOp( - op, - new RexSqlConvertlet() { - public SqlNode convertCall( - RexToSqlNodeConverter converter, - RexCall call) { - SqlNode[] operands = - convertExpressionList(converter, call.operands); - if (operands == null) { - return null; - } - List<SqlNode> operandList = - new ArrayList<SqlNode>(Arrays.asList(operands)); - SqlDataTypeSpec typeSpec = - SqlTypeUtil.convertTypeToSpec(call.getType()); - operandList.add(typeSpec); - return new SqlBasicCall( - op, - operandList.toArray(new SqlNode[operandList.size()]), - SqlParserPos.ZERO); + op, (converter, call) -> { + SqlNode[] operands = + convertExpressionList(converter, call.operands); + if (operands == null) { + return null; } + List<SqlNode> operandList = + new ArrayList<SqlNode>(Arrays.asList(operands)); + SqlDataTypeSpec typeSpec = + SqlTypeUtil.convertTypeToSpec(call.getType()); + operandList.add(typeSpec); + return new SqlBasicCall( + op, + operandList.toArray(new SqlNode[0]), + SqlParserPos.ZERO); }); } @@ -220,33 +215,28 @@ public class RexSqlStandardConvertletTable */ private void registerCaseOp(final SqlOperator op) { registerOp( - op, - new RexSqlConvertlet() { - public SqlNode convertCall( - RexToSqlNodeConverter converter, - RexCall call) { - assert op instanceof SqlCaseOperator; - SqlNode[] operands = - convertExpressionList(converter, call.operands); - if (operands == null) { - return null; - } - SqlNodeList whenList = new SqlNodeList(SqlParserPos.ZERO); - SqlNodeList thenList = new SqlNodeList(SqlParserPos.ZERO); - int i = 0; - while (i < operands.length - 1) { - whenList.add(operands[i]); - ++i; - thenList.add(operands[i]); - ++i; - } - SqlNode elseExpr = operands[i]; - SqlNode[] newOperands = new SqlNode[3]; - newOperands[0] = whenList; - newOperands[1] = thenList; - newOperands[2] = elseExpr; - return op.createCall(null, SqlParserPos.ZERO, newOperands); + op, (converter, call) -> { + assert op instanceof SqlCaseOperator; + SqlNode[] operands = + convertExpressionList(converter, call.operands); + if (operands == null) { + return null; + } + SqlNodeList whenList = new SqlNodeList(SqlParserPos.ZERO); + SqlNodeList thenList = new SqlNodeList(SqlParserPos.ZERO); + int i = 0; + while (i < operands.length - 1) { + whenList.add(operands[i]); + ++i; + thenList.add(operands[i]); + ++i; } + SqlNode elseExpr = operands[i]; + SqlNode[] newOperands = new SqlNode[3]; + newOperands[0] = whenList; + newOperands[1] = thenList; + newOperands[2] = elseExpr; + return op.createCall(null, SqlParserPos.ZERO, newOperands); }); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java b/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java index dc0d405..05fd176 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java @@ -86,7 +86,7 @@ public class RexSubQuery extends RexCall { final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory(); final RelDataType type = typeFactory.createSqlType(SqlTypeName.BOOLEAN); return new RexSubQuery(type, SqlStdOperatorTable.EXISTS, - ImmutableList.<RexNode>of(), rel); + ImmutableList.of(), rel); } /** Creates a scalar sub-query. */ @@ -97,7 +97,7 @@ public class RexSubQuery extends RexCall { final RelDataType type = typeFactory.createTypeWithNullability(fieldList.get(0).getType(), true); return new RexSubQuery(type, SqlStdOperatorTable.SCALAR_QUERY, - ImmutableList.<RexNode>of(), rel); + ImmutableList.of(), rel); } public <R> R accept(RexVisitor<R> visitor) {
