You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2018/07/09 07:49:44 UTC
[22/30] calcite git commit: [CALCITE-2259] Allow Java 8 syntax
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
index d4748ef..f04df74 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoinRule.java
@@ -30,8 +30,7 @@ import org.apache.calcite.rel.core.JoinInfo;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.logical.LogicalJoin;
-import com.google.common.collect.Lists;
-
+import java.util.ArrayList;
import java.util.List;
/** Planner rule that converts a
@@ -61,14 +60,14 @@ class EnumerableMergeJoinRule extends ConverterRule {
// EnumerableMergeJoin CAN support cartesian join, but disable it for now.
return null;
}
- final List<RelNode> newInputs = Lists.newArrayList();
- final List<RelCollation> collations = Lists.newArrayList();
+ final List<RelNode> newInputs = new ArrayList<>();
+ final List<RelCollation> collations = new ArrayList<>();
int offset = 0;
for (Ord<RelNode> ord : Ord.zip(join.getInputs())) {
RelTraitSet traits = ord.e.getTraitSet()
.replace(EnumerableConvention.INSTANCE);
if (!info.pairs().isEmpty()) {
- final List<RelFieldCollation> fieldCollations = Lists.newArrayList();
+ final List<RelFieldCollation> fieldCollations = new ArrayList<>();
for (int key : info.keys().get(ord.i)) {
fieldCollations.add(
new RelFieldCollation(key, RelFieldCollation.Direction.ASCENDING,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
index a1c3984..9418a20 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
@@ -18,7 +18,6 @@ package org.apache.calcite.adapter.enumerable;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelTraitSet;
-import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollationTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Project;
@@ -26,10 +25,10 @@ import org.apache.calcite.rel.metadata.RelMdCollation;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.util.Util;
-import com.google.common.base.Supplier;
-
import java.util.List;
/** Implementation of {@link org.apache.calcite.rel.core.Project} in
@@ -73,14 +72,19 @@ public class EnumerableProject extends Project implements EnumerableRel {
final RelTraitSet traitSet =
cluster.traitSet().replace(EnumerableConvention.INSTANCE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
- new Supplier<List<RelCollation>>() {
- public List<RelCollation> get() {
- return RelMdCollation.project(mq, input, projects);
- }
- });
+ () -> RelMdCollation.project(mq, input, projects));
return new EnumerableProject(cluster, traitSet, input, projects, rowType);
}
+ static RelNode create(RelNode child, List<? extends RexNode> projects,
+ List<String> fieldNames) {
+ final RelOptCluster cluster = child.getCluster();
+ final RelDataType rowType =
+ RexUtil.createStructType(cluster.getTypeFactory(), projects,
+ fieldNames, SqlValidatorUtil.F_SUGGESTER);
+ return create(child, projects, rowType);
+ }
+
public EnumerableProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> projects, RelDataType rowType) {
return new EnumerableProject(getCluster(), traitSet, input,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProjectRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProjectRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProjectRule.java
index 9c015a0..b35f382 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProjectRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProjectRule.java
@@ -23,15 +23,18 @@ import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.logical.LogicalProject;
+import java.util.function.Predicate;
+
/**
* Rule to convert a {@link org.apache.calcite.rel.logical.LogicalProject} to an
* {@link EnumerableProject}.
*/
class EnumerableProjectRule extends ConverterRule {
EnumerableProjectRule() {
- super(LogicalProject.class, RelOptUtil.PROJECT_PREDICATE, Convention.NONE,
- EnumerableConvention.INSTANCE, RelFactories.LOGICAL_BUILDER,
- "EnumerableProjectRule");
+ super(LogicalProject.class,
+ (Predicate<LogicalProject>) RelOptUtil::containsMultisetOrWindowedAgg,
+ Convention.NONE, EnumerableConvention.INSTANCE,
+ RelFactories.LOGICAL_BUILDER, "EnumerableProjectRule");
}
public RelNode convert(RelNode rel) {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRel.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRel.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRel.java
index 5f9b7d3..18f2594 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRel.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRel.java
@@ -17,15 +17,8 @@
package org.apache.calcite.adapter.enumerable;
import org.apache.calcite.linq4j.tree.BlockStatement;
-import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.rel.RelNode;
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.sql.validate.SqlValidatorUtil;
-
-import java.util.List;
/**
* A relational expression of one of the
@@ -34,24 +27,9 @@ import java.util.List;
*/
public interface EnumerableRel
extends RelNode {
- RelFactories.FilterFactory FILTER_FACTORY =
- new RelFactories.FilterFactory() {
- public RelNode createFilter(RelNode child, RexNode condition) {
- return EnumerableFilter.create(child, condition);
- }
- };
+ RelFactories.FilterFactory FILTER_FACTORY = EnumerableFilter::create;
- RelFactories.ProjectFactory PROJECT_FACTORY =
- new RelFactories.ProjectFactory() {
- public RelNode createProject(RelNode child,
- List<? extends RexNode> projects, List<String> fieldNames) {
- final RelOptCluster cluster = child.getCluster();
- final RelDataType rowType =
- RexUtil.createStructType(cluster.getTypeFactory(), projects,
- fieldNames, SqlValidatorUtil.F_SUGGESTER);
- return EnumerableProject.create(child, projects, rowType);
- }
- };
+ RelFactories.ProjectFactory PROJECT_FACTORY = EnumerableProject::create;
//~ Methods ----------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
index dfae89f..b331511 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
@@ -42,11 +42,9 @@ import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.runtime.Bindable;
import org.apache.calcite.util.BuiltInMethod;
-import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
import java.io.Serializable;
import java.lang.reflect.Method;
@@ -56,7 +54,9 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.IdentityHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -69,17 +69,13 @@ import java.util.Set;
public class EnumerableRelImplementor extends JavaRelImplementor {
public final Map<String, Object> map;
private final Map<String, RexToLixTranslator.InputGetter> corrVars =
- Maps.newHashMap();
+ new HashMap<>();
private final Map<Object, ParameterExpression> stashedParameters =
- Maps.newIdentityHashMap();
+ new IdentityHashMap<>();
int windowCount = 0;
protected final Function1<String, RexToLixTranslator.InputGetter> allCorrelateVariables =
- new Function1<String, RexToLixTranslator.InputGetter>() {
- public RexToLixTranslator.InputGetter apply(String name) {
- return getCorrelVariableGetter(name);
- }
- };
+ this::getCorrelVariableGetter;
public EnumerableRelImplementor(RexBuilder rexBuilder,
Map<String, Object> internalParameters) {
@@ -139,16 +135,12 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
// It is convenient for passing non-literal "compile-time" constants
final Collection<Statement> stashed =
Collections2.transform(stashedParameters.values(),
- new Function<ParameterExpression, Statement>() {
- public Statement apply(ParameterExpression input) {
- return Expressions.declare(Modifier.FINAL, input,
- Expressions.convert_(
- Expressions.call(DataContext.ROOT,
- BuiltInMethod.DATA_CONTEXT_GET.method,
- Expressions.constant(input.name)),
- input.type));
- }
- });
+ input -> Expressions.declare(Modifier.FINAL, input,
+ Expressions.convert_(
+ Expressions.call(DataContext.ROOT,
+ BuiltInMethod.DATA_CONTEXT_GET.method,
+ Expressions.constant(input.name)),
+ input.type)));
final BlockStatement block = Expressions.block(
Iterables.concat(
@@ -170,14 +162,14 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
memberDeclarations.add(
Expressions.methodDecl(Modifier.PUBLIC, Class.class,
BuiltInMethod.TYPED_GET_ELEMENT_TYPE.method.getName(),
- Collections.<ParameterExpression>emptyList(),
+ ImmutableList.of(),
Blocks.toFunctionBlock(
Expressions.return_(null,
Expressions.constant(result.physType.getJavaRowType())))));
return Expressions.classDecl(Modifier.PUBLIC,
"Baz",
null,
- Collections.<Type>singletonList(Bindable.class),
+ Collections.singletonList(Bindable.class),
memberDeclarations);
}
@@ -188,7 +180,7 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
Modifier.PUBLIC | Modifier.STATIC,
type.getName(),
null,
- ImmutableList.<Type>of(Serializable.class),
+ ImmutableList.of(Serializable.class),
new ArrayList<MemberDeclaration>());
// For each field:
@@ -302,7 +294,7 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
Modifier.PUBLIC,
int.class,
"hashCode",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
blockBuilder3.toBlock()));
// compareTo method:
@@ -400,7 +392,7 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
Modifier.PUBLIC,
String.class,
"toString",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
blockBuilder5.toBlock()));
return classDeclaration;
@@ -455,12 +447,10 @@ public class EnumerableRelImplementor extends JavaRelImplementor {
public void registerCorrelVariable(final String name,
final ParameterExpression pe,
final BlockBuilder corrBlock, final PhysType physType) {
- corrVars.put(name, new RexToLixTranslator.InputGetter() {
- public Expression field(BlockBuilder list, int index, Type storageType) {
- Expression fieldReference =
- physType.fieldReference(pe, index, storageType);
- return corrBlock.append(name + "_" + index, fieldReference);
- }
+ corrVars.put(name, (list, index, storageType) -> {
+ Expression fieldReference =
+ physType.fieldReference(pe, index, storageType);
+ return corrBlock.append(name + "_" + index, fieldReference);
});
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java
index 8a21b1e..a5a4190 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java
@@ -24,7 +24,7 @@ import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.logical.LogicalTableFunctionScan;
import org.apache.calcite.tools.RelBuilderFactory;
-import com.google.common.base.Predicates;
+import java.util.function.Predicate;
/** Planner rule that converts a
* {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan}
@@ -42,7 +42,7 @@ public class EnumerableTableFunctionScanRule extends ConverterRule {
* @param relBuilderFactory Builder for relational expressions
*/
public EnumerableTableFunctionScanRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalTableFunctionScan.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalTableFunctionScan.class, (Predicate<RelNode>) r -> true,
Convention.NONE, EnumerableConvention.INSTANCE, relBuilderFactory,
"EnumerableTableFunctionScanRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java
index 87eaefe..3e960b2 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java
@@ -24,7 +24,7 @@ import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.schema.ModifiableTable;
import org.apache.calcite.tools.RelBuilderFactory;
-import com.google.common.base.Predicates;
+import java.util.function.Predicate;
/** Planner rule that converts a
* {@link org.apache.calcite.rel.logical.LogicalTableModify}
@@ -37,7 +37,7 @@ public class EnumerableTableModifyRule extends ConverterRule {
* @param relBuilderFactory Builder for relational expressions
*/
public EnumerableTableModifyRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalTableModify.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalTableModify.class, (Predicate<RelNode>) r -> true,
Convention.NONE, EnumerableConvention.INSTANCE, relBuilderFactory,
"EnumerableTableModificationRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
index 3b4d8a1..78826a1 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
@@ -31,7 +31,6 @@ import org.apache.calcite.linq4j.tree.Types;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelTraitSet;
-import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollationTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.TableScan;
@@ -45,7 +44,6 @@ import org.apache.calcite.schema.StreamableTable;
import org.apache.calcite.schema.Table;
import org.apache.calcite.util.BuiltInMethod;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Type;
@@ -76,15 +74,12 @@ public class EnumerableTableScan
Class elementType = EnumerableTableScan.deduceElementType(table);
final RelTraitSet traitSet =
cluster.traitSetOf(EnumerableConvention.INSTANCE)
- .replaceIfs(RelCollationTraitDef.INSTANCE,
- new Supplier<List<RelCollation>>() {
- public List<RelCollation> get() {
- if (table != null) {
- return table.getStatistic().getCollations();
- }
- return ImmutableList.of();
- }
- });
+ .replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
+ if (table != null) {
+ return table.getStatistic().getCollations();
+ }
+ return ImmutableList.of();
+ });
return new EnumerableTableScan(cluster, traitSet, relOptTable, elementType);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java
index adcfa09..3fe1a56 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java
@@ -26,7 +26,7 @@ import org.apache.calcite.rel.logical.LogicalTableScan;
import org.apache.calcite.schema.Table;
import org.apache.calcite.tools.RelBuilderFactory;
-import com.google.common.base.Predicates;
+import java.util.function.Predicate;
/** Planner rule that converts a
* {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan}
@@ -45,7 +45,7 @@ public class EnumerableTableScanRule extends ConverterRule {
* @param relBuilderFactory Builder for relational expressions
*/
public EnumerableTableScanRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalTableScan.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalTableScan.class, (Predicate<RelNode>) r -> true,
Convention.NONE, EnumerableConvention.INSTANCE, relBuilderFactory,
"EnumerableTableScanRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java
index 9818622..2417c16 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java
@@ -116,7 +116,7 @@ public class EnumerableUncollect extends Uncollect implements EnumerableRel {
Expressions.constant(Ints.toArray(fieldCounts)),
Expressions.constant(withOrdinality),
Expressions.constant(
- inputTypes.toArray(new FlatProductInputType[inputTypes.size()])));
+ inputTypes.toArray(new FlatProductInputType[0])));
builder.add(
Expressions.return_(null,
Expressions.call(child_,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java
index b4a95c3..ebf6ffd 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java
@@ -23,9 +23,7 @@ import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.calcite.linq4j.tree.Primitive;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelTraitSet;
-import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelCollationTraitDef;
-import org.apache.calcite.rel.RelDistribution;
import org.apache.calcite.rel.RelDistributionTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Values;
@@ -38,7 +36,6 @@ import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.Pair;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Type;
@@ -62,17 +59,9 @@ public class EnumerableValues extends Values implements EnumerableRel {
final RelTraitSet traitSet =
cluster.traitSetOf(EnumerableConvention.INSTANCE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
- new Supplier<List<RelCollation>>() {
- public List<RelCollation> get() {
- return RelMdCollation.values(mq, rowType, tuples);
- }
- })
+ () -> RelMdCollation.values(mq, rowType, tuples))
.replaceIf(RelDistributionTraitDef.INSTANCE,
- new Supplier<RelDistribution>() {
- public RelDistribution get() {
- return RelMdDistribution.values(rowType, tuples);
- }
- });
+ () -> RelMdDistribution.values(rowType, tuples));
return new EnumerableValues(cluster, rowType, tuples, traitSet);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java
index b401598..b48251b 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java
@@ -22,7 +22,7 @@ import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.logical.LogicalValues;
import org.apache.calcite.tools.RelBuilderFactory;
-import com.google.common.base.Predicates;
+import java.util.function.Predicate;
/** Planner rule that converts a
* {@link org.apache.calcite.rel.logical.LogicalValues}
@@ -35,7 +35,7 @@ public class EnumerableValuesRule extends ConverterRule {
* @param relBuilderFactory Builder for relational expressions
*/
public EnumerableValuesRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalValues.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalValues.class, (Predicate<RelNode>) r -> true,
Convention.NONE, EnumerableConvention.INSTANCE, relBuilderFactory,
"EnumerableValuesRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
index 9c7c737..110c724 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
@@ -53,7 +53,6 @@ import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Modifier;
@@ -62,6 +61,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.function.Function;
/** Implementation of {@link org.apache.calcite.rel.core.Window} in
* {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */
@@ -429,24 +429,21 @@ public class EnumerableWindow extends Window implements EnumerableRel {
hasRows, frameRowCount, partitionRowCount,
jDecl, inputPhysTypeFinal);
- final Function<AggImpState, List<RexNode>> rexArguments =
- new Function<AggImpState, List<RexNode>>() {
- public List<RexNode> apply(AggImpState agg) {
- List<Integer> argList = agg.call.getArgList();
- List<RelDataType> inputTypes =
- EnumUtils.fieldRowTypes(
- result.physType.getRowType(),
- constants,
- argList);
- List<RexNode> args = new ArrayList<RexNode>(
- inputTypes.size());
- for (int i = 0; i < argList.size(); i++) {
- Integer idx = argList.get(i);
- args.add(new RexInputRef(idx, inputTypes.get(i)));
- }
- return args;
- }
- };
+ final Function<AggImpState, List<RexNode>> rexArguments = agg -> {
+ List<Integer> argList = agg.call.getArgList();
+ List<RelDataType> inputTypes =
+ EnumUtils.fieldRowTypes(
+ result.physType.getRowType(),
+ constants,
+ argList);
+ List<RexNode> args = new ArrayList<RexNode>(
+ inputTypes.size());
+ for (int i = 0; i < argList.size(); i++) {
+ Integer idx = argList.get(i);
+ args.add(new RexInputRef(idx, inputTypes.get(i)));
+ }
+ return args;
+ };
implementAdd(aggs, builder7, resultContextBuilder, rexArguments, jDecl);
@@ -533,107 +530,101 @@ public class EnumerableWindow extends Window implements EnumerableRel {
final Expression partitionRowCount,
final DeclarationStatement jDecl,
final PhysType inputPhysType) {
- return new Function<BlockBuilder,
- WinAggFrameResultContext>() {
- public WinAggFrameResultContext apply(
- final BlockBuilder block) {
- return new WinAggFrameResultContext() {
- public RexToLixTranslator rowTranslator(Expression rowIndex) {
- Expression row =
- getRow(rowIndex);
- final RexToLixTranslator.InputGetter inputGetter =
- new WindowRelInputGetter(row, inputPhysType,
- result.physType.getRowType().getFieldCount(),
- translatedConstants);
-
- return RexToLixTranslator.forAggregation(typeFactory,
- block, inputGetter);
- }
+ return block -> new WinAggFrameResultContext() {
+ public RexToLixTranslator rowTranslator(Expression rowIndex) {
+ Expression row =
+ getRow(rowIndex);
+ final RexToLixTranslator.InputGetter inputGetter =
+ new WindowRelInputGetter(row, inputPhysType,
+ result.physType.getRowType().getFieldCount(),
+ translatedConstants);
+
+ return RexToLixTranslator.forAggregation(typeFactory,
+ block, inputGetter);
+ }
- public Expression computeIndex(Expression offset,
- WinAggImplementor.SeekType seekType) {
- Expression index;
- if (seekType == WinAggImplementor.SeekType.AGG_INDEX) {
- index = jDecl.parameter;
- } else if (seekType == WinAggImplementor.SeekType.SET) {
- index = i_;
- } else if (seekType == WinAggImplementor.SeekType.START) {
- index = startX;
- } else if (seekType == WinAggImplementor.SeekType.END) {
- index = endX;
- } else {
- throw new IllegalArgumentException("SeekSet " + seekType
- + " is not supported");
- }
- if (!Expressions.constant(0).equals(offset)) {
- index = block.append("idx", Expressions.add(index, offset));
- }
- return index;
- }
+ public Expression computeIndex(Expression offset,
+ WinAggImplementor.SeekType seekType) {
+ Expression index;
+ if (seekType == WinAggImplementor.SeekType.AGG_INDEX) {
+ index = jDecl.parameter;
+ } else if (seekType == WinAggImplementor.SeekType.SET) {
+ index = i_;
+ } else if (seekType == WinAggImplementor.SeekType.START) {
+ index = startX;
+ } else if (seekType == WinAggImplementor.SeekType.END) {
+ index = endX;
+ } else {
+ throw new IllegalArgumentException("SeekSet " + seekType
+ + " is not supported");
+ }
+ if (!Expressions.constant(0).equals(offset)) {
+ index = block.append("idx", Expressions.add(index, offset));
+ }
+ return index;
+ }
- private Expression checkBounds(Expression rowIndex,
- Expression minIndex, Expression maxIndex) {
- if (rowIndex == i_ || rowIndex == startX || rowIndex == endX) {
- // No additional bounds check required
- return hasRows;
- }
+ private Expression checkBounds(Expression rowIndex,
+ Expression minIndex, Expression maxIndex) {
+ if (rowIndex == i_ || rowIndex == startX || rowIndex == endX) {
+ // No additional bounds check required
+ return hasRows;
+ }
- //noinspection UnnecessaryLocalVariable
- Expression res = block.append("rowInFrame",
- Expressions.foldAnd(
- ImmutableList.of(hasRows,
- Expressions.greaterThanOrEqual(rowIndex, minIndex),
- Expressions.lessThanOrEqual(rowIndex, maxIndex))));
+ //noinspection UnnecessaryLocalVariable
+ Expression res = block.append("rowInFrame",
+ Expressions.foldAnd(
+ ImmutableList.of(hasRows,
+ Expressions.greaterThanOrEqual(rowIndex, minIndex),
+ Expressions.lessThanOrEqual(rowIndex, maxIndex))));
- return res;
- }
+ return res;
+ }
- public Expression rowInFrame(Expression rowIndex) {
- return checkBounds(rowIndex, startX, endX);
- }
+ public Expression rowInFrame(Expression rowIndex) {
+ return checkBounds(rowIndex, startX, endX);
+ }
- public Expression rowInPartition(Expression rowIndex) {
- return checkBounds(rowIndex, minX, maxX);
- }
+ public Expression rowInPartition(Expression rowIndex) {
+ return checkBounds(rowIndex, minX, maxX);
+ }
- public Expression compareRows(Expression a, Expression b) {
- return Expressions.call(comparator_,
- BuiltInMethod.COMPARATOR_COMPARE.method,
- getRow(a), getRow(b));
- }
+ public Expression compareRows(Expression a, Expression b) {
+ return Expressions.call(comparator_,
+ BuiltInMethod.COMPARATOR_COMPARE.method,
+ getRow(a), getRow(b));
+ }
- public Expression getRow(Expression rowIndex) {
- return block.append(
- "jRow",
- RexToLixTranslator.convert(
- Expressions.arrayIndex(rows_, rowIndex),
- inputPhysType.getJavaRowType()));
- }
+ public Expression getRow(Expression rowIndex) {
+ return block.append(
+ "jRow",
+ RexToLixTranslator.convert(
+ Expressions.arrayIndex(rows_, rowIndex),
+ inputPhysType.getJavaRowType()));
+ }
- public Expression index() {
- return i_;
- }
+ public Expression index() {
+ return i_;
+ }
- public Expression startIndex() {
- return startX;
- }
+ public Expression startIndex() {
+ return startX;
+ }
- public Expression endIndex() {
- return endX;
- }
+ public Expression endIndex() {
+ return endX;
+ }
- public Expression hasRows() {
- return hasRows;
- }
+ public Expression hasRows() {
+ return hasRows;
+ }
- public Expression getFrameRowCount() {
- return frameRowCount;
- }
+ public Expression getFrameRowCount() {
+ return frameRowCount;
+ }
- public Expression getPartitionRowCount() {
- return partitionRowCount;
- }
- };
+ public Expression getPartitionRowCount() {
+ return partitionRowCount;
}
};
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/NestedBlockBuilderImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/NestedBlockBuilderImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/NestedBlockBuilderImpl.java
index 1caa47e..d0fadf3 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/NestedBlockBuilderImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/NestedBlockBuilderImpl.java
@@ -52,7 +52,7 @@ public class NestedBlockBuilderImpl implements NestedBlockBuilder {
*/
public final BlockBuilder nestBlock() {
BlockBuilder block = new BlockBuilder(true, currentBlock());
- nestBlock(block, Collections.<RexNode, Boolean>emptyMap());
+ nestBlock(block, Collections.emptyMap());
return block;
}
@@ -63,7 +63,7 @@ public class NestedBlockBuilderImpl implements NestedBlockBuilder {
* @see #exitBlock()
*/
public final void nestBlock(BlockBuilder block) {
- nestBlock(block, Collections.<RexNode, Boolean>emptyMap());
+ nestBlock(block, Collections.emptyMap());
}
/**
@@ -77,7 +77,7 @@ public class NestedBlockBuilderImpl implements NestedBlockBuilder {
Map<RexNode, Boolean> nullables) {
blocks.add(block);
Map<RexNode, Boolean> prev = this.nullables.isEmpty()
- ? Collections.<RexNode, Boolean>emptyMap()
+ ? Collections.emptyMap()
: this.nullables.get(this.nullables.size() - 1);
Map<RexNode, Boolean> next;
if (nullables == null || nullables.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
index 487ddee..7464a27 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
@@ -39,14 +39,12 @@ import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.AbstractList;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -173,7 +171,7 @@ public class PhysTypeImpl implements PhysType {
JavaRowFormat targetFormat) {
final PhysType targetPhysType =
project(fields, true, targetFormat);
- final List<Expression> expressions = Lists.newArrayList();
+ final List<Expression> expressions = new ArrayList<>();
for (Ord<Integer> ord : Ord.zip(fields)) {
final Integer field = ord.e;
if (usedFields.contains(field)) {
@@ -210,8 +208,7 @@ public class PhysTypeImpl implements PhysType {
project(fields, targetFormat);
switch (format) {
case SCALAR:
- return Pair.of(parameter.getType(),
- Collections.<Expression>singletonList(parameter));
+ return Pair.of(parameter.getType(), ImmutableList.of(parameter));
default:
return Pair.of(targetPhysType.getJavaRowType(),
fieldReferences(parameter, fields));
@@ -262,8 +259,7 @@ public class PhysTypeImpl implements PhysType {
Function1.class,
fieldReference(parameter, collation.getFieldIndex()),
parameter);
- return Pair.<Expression, Expression>of(
- selector,
+ return Pair.of(selector,
Expressions.call(
BuiltInMethod.NULLS_COMPARATOR.method,
Expressions.constant(
@@ -332,7 +328,7 @@ public class PhysTypeImpl implements PhysType {
Expressions.return_(null, Expressions.constant(0)));
final List<MemberDeclaration> memberDeclarations =
- Expressions.<MemberDeclaration>list(
+ Expressions.list(
Expressions.methodDecl(
Modifier.PUBLIC,
int.class,
@@ -366,11 +362,9 @@ public class PhysTypeImpl implements PhysType {
ImmutableList.of(parameterO0, parameterO1),
bridgeBody.toBlock()));
}
- return Pair.<Expression, Expression>of(
- selector,
- Expressions.new_(
- Comparator.class,
- Collections.<Expression>emptyList(),
+ return Pair.of(selector,
+ Expressions.new_(Comparator.class,
+ ImmutableList.of(),
memberDeclarations));
}
@@ -433,7 +427,7 @@ public class PhysTypeImpl implements PhysType {
Expressions.return_(null, Expressions.constant(0)));
final List<MemberDeclaration> memberDeclarations =
- Expressions.<MemberDeclaration>list(
+ Expressions.list(
Expressions.methodDecl(
Modifier.PUBLIC,
int.class,
@@ -468,7 +462,7 @@ public class PhysTypeImpl implements PhysType {
}
return Expressions.new_(
Comparator.class,
- Collections.<Expression>emptyList(),
+ ImmutableList.of(),
memberDeclarations);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 1ccc477..1bc9de4 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -57,9 +57,7 @@ import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Util;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -74,6 +72,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
import static org.apache.calcite.linq4j.tree.ExpressionType.Add;
import static org.apache.calcite.linq4j.tree.ExpressionType.AndAlso;
@@ -231,9 +230,9 @@ public class RexImpTable {
private final Map<SqlOperator, CallImplementor> map = new HashMap<>();
private final Map<SqlAggFunction, Supplier<? extends AggImplementor>> aggMap =
- Maps.newHashMap();
+ new HashMap<>();
private final Map<SqlAggFunction, Supplier<? extends WinAggImplementor>> winAggMap =
- Maps.newHashMap();
+ new HashMap<>();
RexImpTable() {
defineMethod(ROW, BuiltInMethod.ARRAY.method, NullPolicy.ANY);
@@ -327,12 +326,7 @@ public class RexImpTable {
defineMethod(TAN, "tan", NullPolicy.STRICT);
defineMethod(TRUNCATE, "struncate", NullPolicy.STRICT);
- map.put(PI, new CallImplementor() {
- @Override public Expression implement(RexToLixTranslator translator,
- RexCall call, NullAs nullAs) {
- return Expressions.constant(Math.PI);
- }
- });
+ map.put(PI, (translator, call, nullAs) -> Expressions.constant(Math.PI));
// datetime
defineImplementor(DATETIME_PLUS, NullPolicy.STRICT,
@@ -413,13 +407,7 @@ public class RexImpTable {
map.put(ARRAY_VALUE_CONSTRUCTOR, value);
map.put(ITEM, new ItemImplementor());
- map.put(DEFAULT,
- new CallImplementor() {
- public Expression implement(RexToLixTranslator translator,
- RexCall call, NullAs nullAs) {
- return Expressions.constant(null);
- }
- });
+ map.put(DEFAULT, (translator, call, nullAs) -> Expressions.constant(null));
// Sequences
defineImplementor(CURRENT_VALUE, NullPolicy.STRICT,
@@ -482,15 +470,13 @@ public class RexImpTable {
throw new IllegalArgumentException(
klass + " should implement zero arguments constructor");
}
- return new Supplier<T>() {
- public T get() {
- try {
- return constructor.newInstance();
- } catch (InstantiationException | IllegalAccessException
- | InvocationTargetException e) {
- throw new IllegalStateException(
- "Error while creating aggregate implementor " + constructor, e);
- }
+ return () -> {
+ try {
+ return constructor.newInstance();
+ } catch (InstantiationException | IllegalAccessException
+ | InvocationTargetException e) {
+ throw new IllegalStateException(
+ "Error while creating aggregate implementor " + constructor, e);
}
};
}
@@ -528,14 +514,9 @@ public class RexImpTable {
case ANY:
case STRICT:
case SEMI_STRICT:
- return new CallImplementor() {
- public Expression implement(
- RexToLixTranslator translator, RexCall call, NullAs nullAs) {
- return implementNullSemantics0(
- translator, call, nullAs, nullPolicy, harmonize,
- implementor);
- }
- };
+ return (translator, call, nullAs) -> implementNullSemantics0(
+ translator, call, nullAs, nullPolicy, harmonize,
+ implementor);
case AND:
/* TODO:
if (nullAs == NullAs.FALSE) {
@@ -549,41 +530,38 @@ public class RexImpTable {
// b0 == null ? (b1 == null || b1 ? null : Boolean.FALSE)
// : b0 ? b1
// : Boolean.FALSE;
- return new CallImplementor() {
- public Expression implement(
- RexToLixTranslator translator, RexCall call, NullAs nullAs) {
- assert call.getOperator() == AND
- : "AND null semantics is supported only for AND operator. Actual operator is "
- + String.valueOf(call.getOperator());
- final RexCall call2 = call2(false, translator, call);
- switch (nullAs) {
- case NOT_POSSIBLE: // Just foldAnd
- case TRUE:
- // AND call should return false iff has FALSEs,
- // thus if we convert nulls to true then no harm is made
- case FALSE:
- // AND call should return false iff has FALSEs or has NULLs,
- // thus if we convert nulls to false, no harm is made
- final List<Expression> expressions =
- translator.translateList(call2.getOperands(), nullAs);
- return Expressions.foldAnd(expressions);
- case NULL:
- case IS_NULL:
- case IS_NOT_NULL:
- final List<Expression> nullAsTrue =
- translator.translateList(call2.getOperands(), NullAs.TRUE);
- final List<Expression> nullAsIsNull =
- translator.translateList(call2.getOperands(), NullAs.IS_NULL);
- Expression hasFalse = Expressions.not(Expressions.foldAnd(nullAsTrue));
- Expression hasNull = Expressions.foldOr(nullAsIsNull);
- Expression result = nullAs.handle(
- Expressions.condition(hasFalse, BOXED_FALSE_EXPR,
- Expressions.condition(hasNull, NULL_EXPR, BOXED_TRUE_EXPR)));
- return result;
- default:
- throw new IllegalArgumentException(
- "Unknown nullAs when implementing AND: " + nullAs);
- }
+ return (translator, call, nullAs) -> {
+ assert call.getOperator() == AND
+ : "AND null semantics is supported only for AND operator. Actual operator is "
+ + String.valueOf(call.getOperator());
+ final RexCall call2 = call2(false, translator, call);
+ switch (nullAs) {
+ case NOT_POSSIBLE: // Just foldAnd
+ case TRUE:
+ // AND call should return false iff has FALSEs,
+ // thus if we convert nulls to true then no harm is made
+ case FALSE:
+ // AND call should return false iff has FALSEs or has NULLs,
+ // thus if we convert nulls to false, no harm is made
+ final List<Expression> expressions =
+ translator.translateList(call2.getOperands(), nullAs);
+ return Expressions.foldAnd(expressions);
+ case NULL:
+ case IS_NULL:
+ case IS_NOT_NULL:
+ final List<Expression> nullAsTrue =
+ translator.translateList(call2.getOperands(), NullAs.TRUE);
+ final List<Expression> nullAsIsNull =
+ translator.translateList(call2.getOperands(), NullAs.IS_NULL);
+ Expression hasFalse =
+ Expressions.not(Expressions.foldAnd(nullAsTrue));
+ Expression hasNull = Expressions.foldOr(nullAsIsNull);
+ return nullAs.handle(
+ Expressions.condition(hasFalse, BOXED_FALSE_EXPR,
+ Expressions.condition(hasNull, NULL_EXPR, BOXED_TRUE_EXPR)));
+ default:
+ throw new IllegalArgumentException(
+ "Unknown nullAs when implementing AND: " + nullAs);
}
};
case OR:
@@ -594,41 +572,38 @@ public class RexImpTable {
// b0 == null ? (b1 == null || !b1 ? null : Boolean.TRUE)
// : !b0 ? b1
// : Boolean.TRUE;
- return new CallImplementor() {
- public Expression implement(
- RexToLixTranslator translator, RexCall call, final NullAs nullAs) {
- assert call.getOperator() == OR
- : "OR null semantics is supported only for OR operator. Actual operator is "
- + String.valueOf(call.getOperator());
- final RexCall call2 = call2(harmonize, translator, call);
- switch (nullAs) {
- case NOT_POSSIBLE: // Just foldOr
- case TRUE:
- // This should return false iff all arguments are FALSE,
- // thus we convert nulls to TRUE and foldOr
- case FALSE:
- // This should return true iff has TRUE arguments,
- // thus we convert nulls to FALSE and foldOr
- final List<Expression> expressions =
- translator.translateList(call2.getOperands(), nullAs);
- return Expressions.foldOr(expressions);
- case NULL:
- case IS_NULL:
- case IS_NOT_NULL:
- final List<Expression> nullAsFalse =
- translator.translateList(call2.getOperands(), NullAs.FALSE);
- final List<Expression> nullAsIsNull =
- translator.translateList(call2.getOperands(), NullAs.IS_NULL);
- Expression hasTrue = Expressions.foldOr(nullAsFalse);
- Expression hasNull = Expressions.foldOr(nullAsIsNull);
- Expression result = nullAs.handle(
- Expressions.condition(hasTrue, BOXED_TRUE_EXPR,
- Expressions.condition(hasNull, NULL_EXPR, BOXED_FALSE_EXPR)));
- return result;
- default:
- throw new IllegalArgumentException(
- "Unknown nullAs when implementing OR: " + nullAs);
- }
+ return (translator, call, nullAs) -> {
+ assert call.getOperator() == OR
+ : "OR null semantics is supported only for OR operator. Actual operator is "
+ + String.valueOf(call.getOperator());
+ final RexCall call2 = call2(harmonize, translator, call);
+ switch (nullAs) {
+ case NOT_POSSIBLE: // Just foldOr
+ case TRUE:
+ // This should return false iff all arguments are FALSE,
+ // thus we convert nulls to TRUE and foldOr
+ case FALSE:
+ // This should return true iff has TRUE arguments,
+ // thus we convert nulls to FALSE and foldOr
+ final List<Expression> expressions =
+ translator.translateList(call2.getOperands(), nullAs);
+ return Expressions.foldOr(expressions);
+ case NULL:
+ case IS_NULL:
+ case IS_NOT_NULL:
+ final List<Expression> nullAsFalse =
+ translator.translateList(call2.getOperands(), NullAs.FALSE);
+ final List<Expression> nullAsIsNull =
+ translator.translateList(call2.getOperands(), NullAs.IS_NULL);
+ Expression hasTrue = Expressions.foldOr(nullAsFalse);
+ Expression hasNull = Expressions.foldOr(nullAsIsNull);
+ Expression result = nullAs.handle(
+ Expressions.condition(hasTrue, BOXED_TRUE_EXPR,
+ Expressions.condition(hasNull, NULL_EXPR, BOXED_FALSE_EXPR)));
+ return result;
+ default:
+ throw new IllegalArgumentException(
+ "Unknown nullAs when implementing OR: " + nullAs);
}
};
case NOT:
@@ -661,13 +636,10 @@ public class RexImpTable {
}
};
case NONE:
- return new CallImplementor() {
- public Expression implement(
- RexToLixTranslator translator, RexCall call, NullAs nullAs) {
- final RexCall call2 = call2(false, translator, call);
- return implementCall(
- translator, call2, implementor, nullAs);
- }
+ return (translator, call, nullAs) -> {
+ final RexCall call2 = call2(false, translator, call);
+ return implementCall(
+ translator, call2, implementor, nullAs);
};
default:
throw new AssertionError(nullPolicy);
@@ -1383,9 +1355,9 @@ public class RexImpTable {
@Override public List<Type> getNotNullState(AggContext info) {
if (afi.isStatic) {
- return Collections.<Type>singletonList(afi.accumulatorType);
+ return Collections.singletonList(afi.accumulatorType);
}
- return Arrays.<Type>asList(afi.accumulatorType, afi.declaringClass);
+ return Arrays.asList(afi.accumulatorType, afi.declaringClass);
}
@Override protected void implementNotNullReset(AggContext info,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
index f131cf8..0c460d3 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
@@ -75,7 +75,7 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.UPPER;
*/
public class RexToLixTranslator {
public static final Map<Method, SqlOperator> JAVA_TO_SQL_METHOD_MAP =
- Util.<Method, SqlOperator>mapOf(
+ Util.mapOf(
findMethod(String.class, "toUpperCase"), UPPER,
findMethod(
SqlFunctions.class, "substring", String.class, Integer.TYPE,
@@ -109,7 +109,7 @@ public class RexToLixTranslator {
private RexToLixTranslator(RexProgram program, JavaTypeFactory typeFactory,
Expression root, InputGetter inputGetter, BlockBuilder list) {
this(program, typeFactory, root, inputGetter, list,
- Collections.<RexNode, Boolean>emptyMap(),
+ Collections.emptyMap(),
new RexBuilder(typeFactory));
}
@@ -1223,7 +1223,7 @@ public class RexToLixTranslator {
return this;
}
return new RexToLixTranslator(program, typeFactory, root, inputGetter,
- block, ImmutableMap.<RexNode, Boolean>of(), builder, this, correlates);
+ block, ImmutableMap.of(), builder, this, correlates);
}
public RexToLixTranslator setCorrelates(
@@ -1232,7 +1232,7 @@ public class RexToLixTranslator {
return this;
}
return new RexToLixTranslator(program, typeFactory, root, inputGetter, list,
- Collections.<RexNode, Boolean>emptyMap(), builder, this, correlates);
+ Collections.emptyMap(), builder, this, correlates);
}
public RelDataType nullifyType(RelDataType type, boolean nullable) {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
index 9932cab..69b4788 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
@@ -24,9 +24,8 @@ import org.apache.calcite.linq4j.tree.BlockBuilder;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
-import com.google.common.base.Function;
-
import java.util.List;
+import java.util.function.Function;
/**
* Implementation of
@@ -39,6 +38,13 @@ public abstract class WinAggAddContextImpl extends WinAggResultContextImpl
super(block, accumulator, frame);
}
+ @SuppressWarnings("Guava")
+ @Deprecated // to be removed before 2.0
+ public WinAggAddContextImpl(BlockBuilder block, List<Expression> accumulator,
+ com.google.common.base.Function<BlockBuilder, WinAggFrameResultContext> frame) {
+ this(block, accumulator, (Function<BlockBuilder, WinAggFrameResultContext>) frame::apply);
+ }
+
public final RexToLixTranslator rowTranslator() {
return rowTranslator(
computeIndex(Expressions.constant(0),
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
index df0d639..a204c3b 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
@@ -23,9 +23,8 @@ import org.apache.calcite.adapter.enumerable.WinAggResultContext;
import org.apache.calcite.linq4j.tree.BlockBuilder;
import org.apache.calcite.linq4j.tree.Expression;
-import com.google.common.base.Function;
-
import java.util.List;
+import java.util.function.Function;
/**
* Implementation of
@@ -38,6 +37,7 @@ public abstract class WinAggResultContextImpl extends AggResultContextImpl
/**
* Creates window aggregate result context.
+ *
* @param block code block that will contain the added initialization
* @param accumulator accumulator variables that store the intermediate
* aggregate state
@@ -49,6 +49,15 @@ public abstract class WinAggResultContextImpl extends AggResultContextImpl
this.frame = frameContextBuilder;
}
+ @SuppressWarnings("Guava")
+ @Deprecated // to be removed before 2.0
+ public WinAggResultContextImpl(BlockBuilder block,
+ List<Expression> accumulator,
+ com.google.common.base.Function<BlockBuilder, WinAggFrameResultContext> frameContextBuilder) {
+ this(block, accumulator,
+ (Function<BlockBuilder, WinAggFrameResultContext>) frameContextBuilder::apply);
+ }
+
private WinAggFrameResultContext getFrame() {
return frame.apply(currentBlock());
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
index 87658d5..9f152b4 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
@@ -61,7 +61,6 @@ import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexOver;
import org.apache.calcite.rex.RexProgram;
import org.apache.calcite.rex.RexVisitorImpl;
-import org.apache.calcite.runtime.PredicateImpl;
import org.apache.calcite.schema.ModifiableTable;
import org.apache.calcite.sql.SqlAggFunction;
import org.apache.calcite.sql.SqlDialect;
@@ -72,8 +71,6 @@ import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import org.slf4j.Logger;
@@ -81,7 +78,7 @@ import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import javax.annotation.Nullable;
+import java.util.function.Predicate;
/**
* Rules and relational operators for
@@ -100,7 +97,7 @@ public class JdbcRules {
public static List<RelOptRule> rules(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- return ImmutableList.<RelOptRule>of(
+ return ImmutableList.of(
new JdbcToEnumerableConverterRule(out, relBuilderFactory),
new JdbcJoinRule(out, relBuilderFactory),
new JdbcCalcRule(out, relBuilderFactory),
@@ -119,10 +116,11 @@ public class JdbcRules {
abstract static class JdbcConverterRule extends ConverterRule {
protected final JdbcConvention out;
+ @SuppressWarnings("unchecked")
@Deprecated // to be removed before 2.0
JdbcConverterRule(Class<? extends RelNode> clazz, RelTrait in,
JdbcConvention out, String description) {
- this(clazz, Predicates.<RelNode>alwaysTrue(), in, out,
+ this(clazz, (Predicate<RelNode>) r -> true, in, out,
RelFactories.LOGICAL_BUILDER, description);
}
@@ -132,6 +130,16 @@ public class JdbcRules {
super(clazz, predicate, in, out, relBuilderFactory, description);
this.out = out;
}
+
+ @SuppressWarnings({"Guava", "unchecked"})
+ @Deprecated // to be removed before 2.0
+ <R extends RelNode> JdbcConverterRule(Class<R> clazz,
+ com.google.common.base.Predicate<? super R> predicate,
+ RelTrait in, JdbcConvention out,
+ RelBuilderFactory relBuilderFactory, String description) {
+ this(clazz, (Predicate<R>) predicate, in, out, relBuilderFactory,
+ description);
+ }
}
/** Rule that converts a join to JDBC. */
@@ -144,7 +152,7 @@ public class JdbcRules {
/** Creates a JdbcJoinRule. */
public JdbcJoinRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Join.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Join.class, (Predicate<RelNode>) r -> true, Convention.NONE,
out, relBuilderFactory, "JdbcJoinRule");
}
@@ -299,7 +307,7 @@ public class JdbcRules {
/** Creates a JdbcCalcRule. */
private JdbcCalcRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Calc.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Calc.class, (Predicate<RelNode>) r -> true, Convention.NONE,
out, relBuilderFactory, "JdbcCalcRule");
}
@@ -380,16 +388,10 @@ public class JdbcRules {
/** Creates a JdbcProjectRule. */
public JdbcProjectRule(final JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Project.class,
- new PredicateImpl<Project>() {
- public boolean test(@Nullable Project project) {
- assert project != null;
- return (out.dialect.supportsWindowFunctions()
+ super(Project.class, (Predicate<Project>) project ->
+ (out.dialect.supportsWindowFunctions()
|| !RexOver.containsOver(project.getProjects(), null))
- && !userDefinedFunctionInProject(project);
- }
-
- },
+ && !userDefinedFunctionInProject(project),
Convention.NONE, out, relBuilderFactory, "JdbcProjectRule");
}
@@ -469,17 +471,9 @@ public class JdbcRules {
/** Creates a JdbcFilterRule. */
public JdbcFilterRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(
- Filter.class,
- new PredicateImpl<Filter>() {
- @Override public boolean test(Filter filter) {
- return !userDefinedFunctionInFilter(filter);
- }
- },
- Convention.NONE,
- out,
- relBuilderFactory,
- "JdbcFilterRule");
+ super(Filter.class,
+ (Predicate<Filter>) r -> !userDefinedFunctionInFilter(r),
+ Convention.NONE, out, relBuilderFactory, "JdbcFilterRule");
}
private static boolean userDefinedFunctionInFilter(Filter filter) {
@@ -535,7 +529,7 @@ public class JdbcRules {
/** Creates a JdbcAggregateRule. */
public JdbcAggregateRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Aggregate.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Aggregate.class, (Predicate<RelNode>) r -> true, Convention.NONE,
out, relBuilderFactory, "JdbcAggregateRule");
}
@@ -620,7 +614,7 @@ public class JdbcRules {
/** Creates a JdbcSortRule. */
public JdbcSortRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Sort.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE, out,
+ super(Sort.class, (Predicate<RelNode>) r -> true, Convention.NONE, out,
relBuilderFactory, "JdbcSortRule");
}
@@ -691,7 +685,7 @@ public class JdbcRules {
/** Creates a JdbcUnionRule. */
public JdbcUnionRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Union.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE, out,
+ super(Union.class, (Predicate<RelNode>) r -> true, Convention.NONE, out,
relBuilderFactory, "JdbcUnionRule");
}
@@ -737,7 +731,7 @@ public class JdbcRules {
/** Creates a JdbcIntersectRule. */
private JdbcIntersectRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Intersect.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Intersect.class, (Predicate<RelNode>) r -> true, Convention.NONE,
out, relBuilderFactory, "JdbcIntersectRule");
}
@@ -784,7 +778,7 @@ public class JdbcRules {
/** Creates a JdbcMinusRule. */
private JdbcMinusRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Minus.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE, out,
+ super(Minus.class, (Predicate<RelNode>) r -> true, Convention.NONE, out,
relBuilderFactory, "JdbcMinusRule");
}
@@ -823,7 +817,7 @@ public class JdbcRules {
/** Creates a JdbcTableModificationRule. */
private JdbcTableModificationRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(TableModify.class, Predicates.<RelNode>alwaysTrue(),
+ super(TableModify.class, (Predicate<RelNode>) r -> true,
Convention.NONE, out, relBuilderFactory, "JdbcTableModificationRule");
}
@@ -899,7 +893,7 @@ public class JdbcRules {
/** Creates a JdbcValuesRule. */
private JdbcValuesRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(Values.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Values.class, (Predicate<RelNode>) r -> true, Convention.NONE,
out, relBuilderFactory, "JdbcValuesRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
index 52dd865..37893d7 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
@@ -38,7 +38,6 @@ import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.Util;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
@@ -52,6 +51,7 @@ import java.sql.Statement;
import java.util.Collection;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import javax.sql.DataSource;
@@ -89,8 +89,8 @@ public class JdbcSchema implements Schema {
JdbcConvention convention, String catalog, String schema,
ImmutableMap<String, JdbcTable> tableMap) {
super();
- this.dataSource = Preconditions.checkNotNull(dataSource);
- this.dialect = Preconditions.checkNotNull(dialect);
+ this.dataSource = Objects.requireNonNull(dataSource);
+ this.dialect = Objects.requireNonNull(dialect);
this.convention = convention;
this.catalog = catalog;
this.schema = schema;
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
index 02b6207..7a356fa 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
@@ -35,7 +35,6 @@ import org.apache.calcite.rel.core.TableModify.Operation;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.runtime.ResultSetEnumerable;
@@ -54,8 +53,6 @@ import org.apache.calcite.sql.util.SqlString;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.sql.SQLException;
@@ -63,6 +60,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
/**
* Queryable that gets its data from a table within a JDBC connection.
@@ -90,7 +88,7 @@ public class JdbcTable extends AbstractQueryableTable
this.jdbcCatalogName = jdbcCatalogName;
this.jdbcSchemaName = jdbcSchemaName;
this.jdbcTableName = tableName;
- this.jdbcTableType = Preconditions.checkNotNull(jdbcTableType);
+ this.jdbcTableType = Objects.requireNonNull(jdbcTableType);
}
public String toString() {
@@ -121,17 +119,14 @@ public class JdbcTable extends AbstractQueryableTable
private List<Pair<ColumnMetaData.Rep, Integer>> fieldClasses(
final JavaTypeFactory typeFactory) {
final RelDataType rowType = protoRowType.apply(typeFactory);
- return Lists.transform(rowType.getFieldList(),
- new Function<RelDataTypeField, Pair<ColumnMetaData.Rep, Integer>>() {
- public Pair<ColumnMetaData.Rep, Integer> apply(RelDataTypeField f) {
- final RelDataType type = f.getType();
- final Class clazz = (Class) typeFactory.getJavaClass(type);
- final ColumnMetaData.Rep rep =
- Util.first(ColumnMetaData.Rep.of(clazz),
- ColumnMetaData.Rep.OBJECT);
- return Pair.of(rep, type.getSqlTypeName().getJdbcOrdinal());
- }
- });
+ return Lists.transform(rowType.getFieldList(), f -> {
+ final RelDataType type = f.getType();
+ final Class clazz = (Class) typeFactory.getJavaClass(type);
+ final ColumnMetaData.Rep rep =
+ Util.first(ColumnMetaData.Rep.of(clazz),
+ ColumnMetaData.Rep.OBJECT);
+ return Pair.of(rep, type.getSqlTypeName().getJdbcOrdinal());
+ });
}
SqlString generateSql() {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverterRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverterRule.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverterRule.java
index e5eec50..e685922 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverterRule.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverterRule.java
@@ -22,7 +22,7 @@ import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.tools.RelBuilderFactory;
-import com.google.common.base.Predicates;
+import java.util.function.Predicate;
/**
* Rule to convert a relational expression from
@@ -33,7 +33,7 @@ public class JdbcToEnumerableConverterRule extends ConverterRule {
/** Creates a JdbcToEnumerableConverterRule. */
public JdbcToEnumerableConverterRule(JdbcConvention out,
RelBuilderFactory relBuilderFactory) {
- super(RelNode.class, Predicates.<RelNode>alwaysTrue(), out,
+ super(RelNode.class, (Predicate<RelNode>) r -> true, out,
EnumerableConvention.INSTANCE, relBuilderFactory,
"JdbcToEnumerableConverterRule:" + out);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java
index 113b88a..7d5b8da 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java
@@ -127,16 +127,14 @@ final class JdbcUtils {
public static Function1<ResultSet, Function0<Object[]>> factory(
final List<Pair<ColumnMetaData.Rep, Integer>> list) {
- return new Function1<ResultSet, Function0<Object[]>>() {
- public Function0<Object[]> apply(ResultSet resultSet) {
- try {
- return new ObjectArrayRowBuilder(
- resultSet,
- Pair.left(list).toArray(new ColumnMetaData.Rep[list.size()]),
- Ints.toArray(Pair.right(list)));
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
+ return resultSet -> {
+ try {
+ return new ObjectArrayRowBuilder(
+ resultSet,
+ Pair.left(list).toArray(new ColumnMetaData.Rep[list.size()]),
+ Ints.toArray(Pair.right(list)));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
}
};
}
@@ -212,17 +210,18 @@ final class JdbcUtils {
public static final DataSourcePool INSTANCE = new DataSourcePool();
private final LoadingCache<List<String>, BasicDataSource> cache =
- CacheBuilder.newBuilder().softValues().build(
- new CacheLoader<List<String>, BasicDataSource>() {
- @Override public BasicDataSource load(@Nonnull List<String> key) {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setUrl(key.get(0));
- dataSource.setUsername(key.get(1));
- dataSource.setPassword(key.get(2));
- dataSource.setDriverClassName(key.get(3));
- return dataSource;
- }
- });
+ CacheBuilder.newBuilder().softValues()
+ .build(CacheLoader.from(DataSourcePool::dataSource));
+
+ private static @Nonnull BasicDataSource dataSource(
+ @Nonnull List<String> key) {
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setUrl(key.get(0));
+ dataSource.setUsername(key.get(1));
+ dataSource.setPassword(key.get(2));
+ dataSource.setDriverClassName(key.get(3));
+ return dataSource;
+ }
public DataSource get(String url, String driverClassName,
String username, String password) {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/config/CalciteConnectionConfigImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/config/CalciteConnectionConfigImpl.java b/core/src/main/java/org/apache/calcite/config/CalciteConnectionConfigImpl.java
index bf057cb..6c176b8 100644
--- a/core/src/main/java/org/apache/calcite/config/CalciteConnectionConfigImpl.java
+++ b/core/src/main/java/org/apache/calcite/config/CalciteConnectionConfigImpl.java
@@ -99,7 +99,7 @@ public class CalciteConnectionConfigImpl extends ConnectionConfigImpl
tables.add(SqlStdOperatorTable.instance());
return operatorTableClass.cast(
ChainedSqlOperatorTable.of(
- tables.toArray(new SqlOperatorTable[tables.size()])));
+ tables.toArray(new SqlOperatorTable[0])));
}
private static void operatorTable(String s,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
index 390849c..c547dfc 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
@@ -40,25 +40,24 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Pair;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
+import java.util.function.Supplier;
/**
* Interpreter node that implements an
* {@link org.apache.calcite.rel.core.Aggregate}.
*/
public class AggregateNode extends AbstractSingleNode<Aggregate> {
- private final List<Grouping> groups = Lists.newArrayList();
+ private final List<Grouping> groups = new ArrayList<>();
private final ImmutableBitSet unionGroups;
private final int outputRowLength;
private final ImmutableList<AccumulatorFactory> accumulatorFactories;
@@ -106,19 +105,13 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
boolean ignoreFilter) {
if (call.filterArg >= 0 && !ignoreFilter) {
final AccumulatorFactory factory = getAccumulator(call, true);
- return new AccumulatorFactory() {
- public Accumulator get() {
- final Accumulator accumulator = factory.get();
- return new FilterAccumulator(accumulator, call.filterArg);
- }
+ return () -> {
+ final Accumulator accumulator = factory.get();
+ return new FilterAccumulator(accumulator, call.filterArg);
};
}
if (call.getAggregation() == SqlStdOperatorTable.COUNT) {
- return new AccumulatorFactory() {
- public Accumulator get() {
- return new CountAccumulator(call);
- }
- };
+ return () -> new CountAccumulator(call);
} else if (call.getAggregation() == SqlStdOperatorTable.SUM
|| call.getAggregation() == SqlStdOperatorTable.SUM0) {
final Class<?> clazz;
@@ -340,7 +333,7 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
*/
private class Grouping {
private final ImmutableBitSet grouping;
- private final Map<Row, AccumulatorList> accumulators = Maps.newHashMap();
+ private final Map<Row, AccumulatorList> accumulators = new HashMap<>();
private Grouping(ImmutableBitSet grouping) {
this.grouping = grouping;
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
index a26325e..c7df83b 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java
@@ -72,12 +72,12 @@ import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import com.google.common.base.Preconditions;
-import com.google.common.base.Predicates;
-import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
+import java.util.function.Predicate;
/**
* Utilities pertaining to {@link BindableRel} and {@link BindableConvention}.
@@ -174,15 +174,15 @@ public class Bindables {
RelOptTable table, ImmutableList<RexNode> filters,
ImmutableIntList projects) {
super(cluster, traitSet, table);
- this.filters = Preconditions.checkNotNull(filters);
- this.projects = Preconditions.checkNotNull(projects);
+ this.filters = Objects.requireNonNull(filters);
+ this.projects = Objects.requireNonNull(projects);
Preconditions.checkArgument(canHandle(table));
}
/** Creates a BindableTableScan. */
public static BindableTableScan create(RelOptCluster cluster,
RelOptTable relOptTable) {
- return create(cluster, relOptTable, ImmutableList.<RexNode>of(),
+ return create(cluster, relOptTable, ImmutableList.of(),
identity(relOptTable));
}
@@ -193,15 +193,12 @@ public class Bindables {
final Table table = relOptTable.unwrap(Table.class);
final RelTraitSet traitSet =
cluster.traitSetOf(BindableConvention.INSTANCE)
- .replaceIfs(RelCollationTraitDef.INSTANCE,
- new Supplier<List<RelCollation>>() {
- public List<RelCollation> get() {
- if (table != null) {
- return table.getStatistic().getCollations();
- }
- return ImmutableList.of();
- }
- });
+ .replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
+ if (table != null) {
+ return table.getStatistic().getCollations();
+ }
+ return ImmutableList.of();
+ });
return new BindableTableScan(cluster, traitSet, relOptTable,
ImmutableList.copyOf(filters), ImmutableIntList.copyOf(projects));
}
@@ -268,8 +265,10 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableFilterRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalFilter.class, RelOptUtil.FILTER_PREDICATE, Convention.NONE,
- BindableConvention.INSTANCE, relBuilderFactory, "BindableFilterRule");
+ super(LogicalFilter.class,
+ (Predicate<LogicalFilter>) RelOptUtil::containsMultisetOrWindowedAgg,
+ Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
+ "BindableFilterRule");
}
public RelNode convert(RelNode rel) {
@@ -299,11 +298,7 @@ public class Bindables {
final RelTraitSet traitSet =
cluster.traitSetOf(BindableConvention.INSTANCE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
- new Supplier<List<RelCollation>>() {
- public List<RelCollation> get() {
- return RelMdCollation.filter(mq, input);
- }
- });
+ () -> RelMdCollation.filter(mq, input));
return new BindableFilter(cluster, traitSet, input, condition);
}
@@ -337,8 +332,9 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableProjectRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalProject.class, RelOptUtil.PROJECT_PREDICATE, Convention.NONE,
- BindableConvention.INSTANCE, relBuilderFactory,
+ super(LogicalProject.class,
+ (Predicate<LogicalProject>) RelOptUtil::containsMultisetOrWindowedAgg,
+ Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableProjectRule");
}
@@ -394,7 +390,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableSortRule(RelBuilderFactory relBuilderFactory) {
- super(Sort.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE,
+ super(Sort.class, (Predicate<RelNode>) r -> true, Convention.NONE,
BindableConvention.INSTANCE, relBuilderFactory, "BindableSortRule");
}
@@ -450,7 +446,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableJoinRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalJoin.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalJoin.class, (Predicate<RelNode>) r -> true,
Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableJoinRule");
}
@@ -520,7 +516,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableUnionRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalUnion.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalUnion.class, (Predicate<RelNode>) r -> true,
Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableUnionRule");
}
@@ -595,7 +591,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableValuesRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalValues.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalValues.class, (Predicate<RelNode>) r -> true,
Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableValuesRule");
}
@@ -673,7 +669,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableAggregateRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalAggregate.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalAggregate.class, (Predicate<RelNode>) r -> true,
Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableAggregateRule");
}
@@ -738,7 +734,7 @@ public class Bindables {
* @param relBuilderFactory Builder for relational expressions
*/
public BindableWindowRule(RelBuilderFactory relBuilderFactory) {
- super(LogicalWindow.class, Predicates.<RelNode>alwaysTrue(),
+ super(LogicalWindow.class, (Predicate<RelNode>) r -> true,
Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory,
"BindableWindowRule");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/InterpretableRel.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/InterpretableRel.java b/core/src/main/java/org/apache/calcite/interpreter/InterpretableRel.java
index 42276ac..2fee43d 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/InterpretableRel.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/InterpretableRel.java
@@ -20,8 +20,8 @@ import org.apache.calcite.DataContext;
import org.apache.calcite.jdbc.CalcitePrepare;
import org.apache.calcite.rel.RelNode;
-import com.google.common.collect.Maps;
-
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -37,10 +37,10 @@ public interface InterpretableRel extends RelNode {
class InterpreterImplementor {
public final Compiler compiler;
public final Map<String, Object> internalParameters =
- Maps.newLinkedHashMap();
+ new LinkedHashMap<>();
public final CalcitePrepare.SparkHandler spark;
public final DataContext dataContext;
- public final Map<RelNode, List<Sink>> relSinks = Maps.newHashMap();
+ public final Map<RelNode, List<Sink>> relSinks = new HashMap<>();
public InterpreterImplementor(Compiler compiler,
CalcitePrepare.SparkHandler spark,