http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/rex/RexUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java index 1e0fb15..29e63f1 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java +++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java @@ -30,7 +30,6 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelDataTypeFamily; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rex.RexTableInputRef.RelTableRef; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.schema.Schemas; import org.apache.calcite.sql.SqlAggFunction; import org.apache.calcite.sql.SqlKind; @@ -46,15 +45,10 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; import org.apache.calcite.util.mapping.Mappings; -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.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import java.util.ArrayList; import java.util.Arrays; @@ -66,6 +60,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; import javax.annotation.Nonnull; /** @@ -73,42 +68,6 @@ import javax.annotation.Nonnull; */ public class RexUtil { - private static final Function<? super RexNode, ? extends RexNode> ADD_NOT = - new Function<RexNode, RexNode>() { - public RexNode apply(RexNode input) { - return new RexCall(input.getType(), SqlStdOperatorTable.NOT, - ImmutableList.of(input)); - } - }; - - private static final Predicate1<RexNode> IS_FLAT_PREDICATE = - new Predicate1<RexNode>() { - public boolean apply(RexNode v1) { - return isFlat(v1); - } - }; - - private static final Function<Object, String> TO_STRING = - new Function<Object, String>() { - public String apply(Object input) { - return input.toString(); - } - }; - - private static final Function<RexNode, RelDataType> TYPE_FN = - new Function<RexNode, RelDataType>() { - public RelDataType apply(RexNode input) { - return input.getType(); - } - }; - - private static final Function<RelDataType, RelDataTypeFamily> FAMILY_FN = - new Function<RelDataType, RelDataTypeFamily>() { - public RelDataTypeFamily apply(RelDataType input) { - return input.getFamily(); - } - }; - /** Executor for a bit of constant reduction. The user can pass in another executor. */ public static final RexExecutor EXECUTOR = new RexExecutorImpl(Schemas.createDataContext(null, null)); @@ -593,7 +552,7 @@ public class RexUtil { } public static List<RexNode> retainDeterministic(List<RexNode> list) { - List<RexNode> conjuctions = Lists.newArrayList(); + List<RexNode> conjuctions = new ArrayList<>(); for (RexNode x : list) { if (isDeterministic(x)) { conjuctions.add(x); @@ -1083,7 +1042,7 @@ public class RexUtil { return ImmutableList.of(); } final ImmutableList.Builder<RexNode> builder = ImmutableList.builder(); - final Set<String> digests = Sets.newHashSet(); // to eliminate duplicates + final Set<String> digests = new HashSet<>(); // to eliminate duplicates for (RexNode node : nodes) { if (node != null) { addAnd(builder, digests, node); @@ -1117,7 +1076,7 @@ public class RexUtil { @Nonnull public static RexNode composeDisjunction(RexBuilder rexBuilder, Iterable<? extends RexNode> nodes) { final RexNode e = composeDisjunction(rexBuilder, nodes, false); - return Preconditions.checkNotNull(e); + return Objects.requireNonNull(e); } /** @@ -1147,7 +1106,7 @@ public class RexUtil { return ImmutableList.of(); } final ImmutableList.Builder<RexNode> builder = ImmutableList.builder(); - final Set<String> digests = Sets.newHashSet(); // to eliminate duplicates + final Set<String> digests = new HashSet<>(); // to eliminate duplicates for (RexNode node : nodes) { addOr(builder, digests, node); } @@ -1279,12 +1238,7 @@ public class RexUtil { public static Iterable<RexNode> apply(Mappings.TargetMapping mapping, Iterable<? extends RexNode> nodes) { final RexPermuteInputsShuttle shuttle = RexPermuteInputsShuttle.of(mapping); - return Iterables.transform( - nodes, new Function<RexNode, RexNode>() { - public RexNode apply(RexNode input) { - return input.accept(shuttle); - } - }); + return Iterables.transform(nodes, e -> e.accept(shuttle)); } /** @@ -1386,12 +1340,7 @@ public class RexUtil { private static boolean isFlat( List<? extends RexNode> exprs, final SqlOperator op) { return !isAssociative(op) - || !exists(exprs, - new Predicate1<RexNode>() { - public boolean apply(RexNode expr) { - return isCallTo(expr, op); - } - }); + || !exists(exprs, (Predicate1<RexNode>) expr -> isCallTo(expr, op)); } /** @@ -1404,7 +1353,7 @@ public class RexUtil { } final RexCall call = (RexCall) expr; return isFlat(call.getOperands(), call.getOperator()) - && all(call.getOperands(), IS_FLAT_PREDICATE); + && all(call.getOperands(), RexUtil::isFlat); } private static void flattenRecurse( @@ -1658,11 +1607,11 @@ public class RexUtil { /** Transforms a list of expressions into a list of their types. */ public static List<RelDataType> types(List<? extends RexNode> nodes) { - return Lists.transform(nodes, TYPE_FN); + return Lists.transform(nodes, RexNode::getType); } public static List<RelDataTypeFamily> families(List<RelDataType> types) { - return Lists.transform(types, FAMILY_FN); + return Lists.transform(types, RelDataType::getFamily); } /** Removes all expressions from a list that are equivalent to a given @@ -1774,11 +1723,15 @@ public class RexUtil { case NOT: return ((RexCall) e).getOperands().get(0); default: - return new RexCall(e.getType(), SqlStdOperatorTable.NOT, - ImmutableList.of(e)); + return addNot(e); } } + private static RexNode addNot(RexNode e) { + return new RexCall(e.getType(), SqlStdOperatorTable.NOT, + ImmutableList.of(e)); + } + static SqlOperator op(SqlKind kind) { switch (kind) { case IS_FALSE: @@ -1903,25 +1856,23 @@ public class RexUtil { final RexCall call = (RexCall) e; if (call.getOperands().get(1) instanceof RexLiteral) { notTerms = Iterables.filter(notTerms, - new PredicateImpl<RexNode>() { - public boolean test(RexNode input) { - switch (input.getKind()) { - case EQUALS: - RexCall call2 = (RexCall) input; - if (call2.getOperands().get(0) - .equals(call.getOperands().get(0)) - && call2.getOperands().get(1) instanceof RexLiteral) { - return false; - } + e2 -> { + switch (e2.getKind()) { + case EQUALS: + RexCall call2 = (RexCall) e2; + if (call2.getOperands().get(0) + .equals(call.getOperands().get(0)) + && call2.getOperands().get(1) instanceof RexLiteral) { + return false; } - return true; } + return true; }); } } return composeConjunction(rexBuilder, Iterables.concat(ImmutableList.of(e), - Iterables.transform(notTerms, notFn(rexBuilder))), + Iterables.transform(notTerms, e2 -> not(rexBuilder, e2))), false); } @@ -1939,19 +1890,25 @@ public class RexUtil { && (call.operands.size() - i) % 2 == 1; } - /** Returns a function that applies NOT to its argument. */ - public static Function<RexNode, RexNode> notFn(final RexBuilder rexBuilder) { - return new Function<RexNode, RexNode>() { - public RexNode apply(RexNode input) { - return input.isAlwaysTrue() - ? rexBuilder.makeLiteral(false) - : input.isAlwaysFalse() - ? rexBuilder.makeLiteral(true) - : input.getKind() == SqlKind.NOT - ? ((RexCall) input).operands.get(0) - : rexBuilder.makeCall(SqlStdOperatorTable.NOT, input); - } - }; + /** Returns a function that applies NOT to its argument. + * + * @deprecated Use {@link #not} */ + @SuppressWarnings("Guava") + @Deprecated // to be removed in 2.0 + public static com.google.common.base.Function<RexNode, RexNode> notFn( + final RexBuilder rexBuilder) { + return e -> not(rexBuilder, e); + } + + /** Applies NOT to an expression. */ + static RexNode not(final RexBuilder rexBuilder, RexNode input) { + return input.isAlwaysTrue() + ? rexBuilder.makeLiteral(false) + : input.isAlwaysFalse() + ? rexBuilder.makeLiteral(true) + : input.getKind() == SqlKind.NOT + ? ((RexCall) input).operands.get(0) + : rexBuilder.makeCall(SqlStdOperatorTable.NOT, input); } /** Returns whether an expression contains a {@link RexCorrelVariable}. */ @@ -2250,7 +2207,7 @@ public class RexUtil { case AND: incrementAndCheck(); operands = flattenAnd(((RexCall) rex).getOperands()); - final List<RexNode> cnfOperands = Lists.newArrayList(); + final List<RexNode> cnfOperands = new ArrayList<>(); for (RexNode node : operands) { RexNode cnf = toCnf2(node); switch (cnf.getKind()) { @@ -2273,7 +2230,7 @@ public class RexUtil { final RexNode tail = or(Util.skip(operands)); final RexNode tailCnf = toCnf2(tail); final List<RexNode> tailCnfs = RelOptUtil.conjunctions(tailCnf); - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (RexNode h : headCnfs) { for (RexNode t : tailCnfs) { list.add(or(ImmutableList.of(h, t))); @@ -2287,10 +2244,12 @@ public class RexUtil { return toCnf2(((RexCall) arg).getOperands().get(0)); case OR: operands = ((RexCall) arg).getOperands(); - return toCnf2(and(Lists.transform(flattenOr(operands), ADD_NOT))); + return toCnf2( + and(Lists.transform(flattenOr(operands), RexUtil::addNot))); case AND: operands = ((RexCall) arg).getOperands(); - return toCnf2(or(Lists.transform(flattenAnd(operands), ADD_NOT))); + return toCnf2( + or(Lists.transform(flattenAnd(operands), RexUtil::addNot))); default: incrementAndCheck(); return rex; @@ -2328,7 +2287,7 @@ public class RexUtil { if (factors.isEmpty()) { return or(operands); } - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (RexNode operand : operands) { list.add(removeFactor(factors, operand)); } @@ -2339,7 +2298,7 @@ public class RexUtil { } private List<RexNode> pullList(List<RexNode> nodes) { - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (RexNode node : nodes) { RexNode pulled = pull(node); switch (pulled.getKind()) { @@ -2354,7 +2313,7 @@ public class RexUtil { } private Map<String, RexNode> commonFactors(List<RexNode> nodes) { - final Map<String, RexNode> map = Maps.newHashMap(); + final Map<String, RexNode> map = new HashMap<>(); int i = 0; for (RexNode node : nodes) { if (i++ == 0) { @@ -2369,7 +2328,7 @@ public class RexUtil { } private RexNode removeFactor(Map<String, RexNode> factors, RexNode node) { - List<RexNode> list = Lists.newArrayList(); + List<RexNode> list = new ArrayList<>(); for (RexNode operand : RelOptUtil.conjunctions(node)) { if (!factors.containsKey(operand.toString())) { list.add(operand); @@ -2389,7 +2348,7 @@ public class RexUtil { /** Transforms a list of expressions to the list of digests. */ public static List<String> strings(List<RexNode> list) { - return Lists.transform(list, TO_STRING); + return Lists.transform(list, Object::toString); } /** Helps {@link org.apache.calcite.rex.RexUtil#toDnf}. */ @@ -2411,7 +2370,7 @@ public class RexUtil { final RexNode tail = and(Util.skip(operands)); final RexNode tailDnf = toDnf(tail); final List<RexNode> tailDnfs = RelOptUtil.disjunctions(tailDnf); - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (RexNode h : headDnfs) { for (RexNode t : tailDnfs) { list.add(and(ImmutableList.of(h, t))); @@ -2428,10 +2387,12 @@ public class RexUtil { return toDnf(((RexCall) arg).getOperands().get(0)); case OR: operands = ((RexCall) arg).getOperands(); - return toDnf(and(Lists.transform(flattenOr(operands), ADD_NOT))); + return toDnf( + and(Lists.transform(flattenOr(operands), RexUtil::addNot))); case AND: operands = ((RexCall) arg).getOperands(); - return toDnf(or(Lists.transform(flattenAnd(operands), ADD_NOT))); + return toDnf( + or(Lists.transform(flattenAnd(operands), RexUtil::addNot))); default: return rex; } @@ -2441,7 +2402,7 @@ public class RexUtil { } private List<RexNode> toDnfs(List<RexNode> nodes) { - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (RexNode node : nodes) { RexNode dnf = toDnf(node); switch (dnf.getKind()) { @@ -2526,51 +2487,57 @@ public class RexUtil { public static class SubQueryFinder extends RexVisitorImpl<Void> { public static final SubQueryFinder INSTANCE = new SubQueryFinder(); - /** Returns whether a {@link Project} contains a sub-query. */ - public static final Predicate<Project> PROJECT_PREDICATE = - new PredicateImpl<Project>() { - public boolean test(Project project) { - for (RexNode node : project.getProjects()) { - try { - node.accept(INSTANCE); - } catch (Util.FoundOne e) { - return true; - } - } - return false; - } - }; + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public static final com.google.common.base.Predicate<Project> PROJECT_PREDICATE = + SubQueryFinder::containsSubQuery; - /** Returns whether a {@link Filter} contains a sub-query. */ + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 public static final Predicate<Filter> FILTER_PREDICATE = - new PredicateImpl<Filter>() { - public boolean test(Filter filter) { - try { - filter.getCondition().accept(INSTANCE); - return false; - } catch (Util.FoundOne e) { - return true; - } - } - }; + SubQueryFinder::containsSubQuery; - /** Returns whether a {@link Join} contains a sub-query. */ - public static final Predicate<Join> JOIN_PREDICATE = - new PredicateImpl<Join>() { - public boolean test(Join join) { - try { - join.getCondition().accept(INSTANCE); - return false; - } catch (Util.FoundOne e) { - return true; - } - } - }; + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public static final com.google.common.base.Predicate<Join> JOIN_PREDICATE = + SubQueryFinder::containsSubQuery; private SubQueryFinder() { super(true); } + /** Returns whether a {@link Project} contains a sub-query. */ + public static boolean containsSubQuery(Project project) { + for (RexNode node : project.getProjects()) { + try { + node.accept(INSTANCE); + } catch (Util.FoundOne e) { + return true; + } + } + return false; + } + + /** Returns whether a {@link Filter} contains a sub-query. */ + public static boolean containsSubQuery(Filter filter) { + try { + filter.getCondition().accept(INSTANCE); + return false; + } catch (Util.FoundOne e) { + return true; + } + } + + /** Returns whether a {@link Join} contains a sub-query. */ + public static boolean containsSubQuery(Join join) { + try { + join.getCondition().accept(INSTANCE); + return false; + } catch (Util.FoundOne e) { + return true; + } + } + @Override public Void visitSubQuery(RexSubQuery subQuery) { throw new Util.FoundOne(subQuery); }
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/BinarySearch.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/BinarySearch.java b/core/src/main/java/org/apache/calcite/runtime/BinarySearch.java index 5311434..f78ffa0 100644 --- a/core/src/main/java/org/apache/calcite/runtime/BinarySearch.java +++ b/core/src/main/java/org/apache/calcite/runtime/BinarySearch.java @@ -49,7 +49,7 @@ public class BinarySearch { */ public static <T> int lowerBound(T[] a, T key, Comparator<T> comparator) { return lowerBound(a, key, 0, a.length - 1, - Functions.<T>identitySelector(), comparator); + Functions.identitySelector(), comparator); } /** @@ -68,7 +68,7 @@ public class BinarySearch { */ public static <T> int upperBound(T[] a, T key, Comparator<T> comparator) { return upperBound(a, key, 0, a.length - 1, - Functions.<T>identitySelector(), comparator); + Functions.identitySelector(), comparator); } /** @@ -136,7 +136,7 @@ public class BinarySearch { public static <T> int lowerBound(T[] a, T key, int imin, int imax, Comparator<T> comparator) { return lowerBound(a, key, imin, imax, - Functions.<T>identitySelector(), comparator); + Functions.identitySelector(), comparator); } /** @@ -158,7 +158,7 @@ public class BinarySearch { public static <T> int upperBound(T[] a, T key, int imin, int imax, Comparator<T> comparator) { return upperBound(a, key, imin, imax, - Functions.<T>identitySelector(), comparator); + Functions.identitySelector(), comparator); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/Enumerables.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/Enumerables.java b/core/src/main/java/org/apache/calcite/runtime/Enumerables.java index 5fbb268..62b7992 100644 --- a/core/src/main/java/org/apache/calcite/runtime/Enumerables.java +++ b/core/src/main/java/org/apache/calcite/runtime/Enumerables.java @@ -20,7 +20,7 @@ import org.apache.calcite.interpreter.Row; import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.function.Function1; -import com.google.common.base.Supplier; +import java.util.function.Supplier; /** * Utilities for processing {@link org.apache.calcite.linq4j.Enumerable} @@ -30,19 +30,6 @@ import com.google.common.base.Supplier; * Methods are subject to removal without notice. */ public class Enumerables { - private static final Function1<?, ?> SLICE = - new Function1<Object[], Object>() { - public Object apply(Object[] a0) { - return a0[0]; - } - }; - - private static final Function1<Object[], Row> ARRAY_TO_ROW = - new Function1<Object[], Row>() { - public Row apply(Object[] a0) { - return Row.asCopy(a0); - } - }; private Enumerables() {} @@ -50,24 +37,27 @@ public class Enumerables { * first elements. */ public static <E> Enumerable<E> slice0(Enumerable<E[]> enumerable) { //noinspection unchecked - return enumerable.select((Function1<E[], E>) SLICE); + return enumerable.select(elements -> elements[0]); } /** Converts an {@link Enumerable} over object arrays into an * {@link Enumerable} over {@link Row} objects. */ public static Enumerable<Row> toRow(final Enumerable<Object[]> enumerable) { - return enumerable.select(ARRAY_TO_ROW); + return enumerable.select((Function1<Object[], Row>) Row::asCopy); } /** Converts a supplier of an {@link Enumerable} over object arrays into a * supplier of an {@link Enumerable} over {@link Row} objects. */ public static Supplier<Enumerable<Row>> toRow( final Supplier<Enumerable<Object[]>> supplier) { - return new Supplier<Enumerable<Row>>() { - public Enumerable<Row> get() { - return toRow(supplier.get()); - } - }; + return () -> toRow(supplier.get()); + } + + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public static com.google.common.base.Supplier<Enumerable<Row>> toRow( + final com.google.common.base.Supplier<Enumerable<Object[]>> supplier) { + return () -> toRow(supplier.get()); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/FlatLists.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java index 94cfce1..d07014a 100644 --- a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java +++ b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java @@ -372,6 +372,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 1) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 1, a.getClass()); + } a[0] = (T2) t0; return a; } @@ -500,6 +504,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 2) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 2, a.getClass()); + } a[0] = (T2) t0; a[1] = (T2) t1; return a; @@ -645,6 +653,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 3) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 3, a.getClass()); + } a[0] = (T2) t0; a[1] = (T2) t1; a[2] = (T2) t2; @@ -809,6 +821,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 4) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 4, a.getClass()); + } a[0] = (T2) t0; a[1] = (T2) t1; a[2] = (T2) t2; @@ -992,6 +1008,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 5) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 5, a.getClass()); + } a[0] = (T2) t0; a[1] = (T2) t1; a[2] = (T2) t2; @@ -1195,6 +1215,10 @@ public class FlatLists { @SuppressWarnings({"unchecked" }) public <T2> T2[] toArray(T2[] a) { + if (a.length < 6) { + // Make a new array of a's runtime type, but my contents: + return (T2[]) Arrays.copyOf(toArray(), 6, a.getClass()); + } a[0] = (T2) t0; a[1] = (T2) t1; a[2] = (T2) t2; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java b/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java index 73884c0..3e258c9 100644 --- a/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java @@ -38,9 +38,8 @@ import com.esri.core.geometry.SpatialReference; import com.esri.core.geometry.WktExportFlags; import com.esri.core.geometry.WktImportFlags; -import com.google.common.base.Preconditions; - import java.math.BigDecimal; +import java.util.Objects; /** * Helper methods to implement Geo-spatial functions in generated code. @@ -574,7 +573,7 @@ public class GeoFunctions { final Geometry g; SimpleGeom(Geometry g) { - this.g = Preconditions.checkNotNull(g); + this.g = Objects.requireNonNull(g); } @Override public String toString() { @@ -606,7 +605,7 @@ public class GeoFunctions { final MapGeometry mg; MapGeom(MapGeometry mg) { - this.mg = Preconditions.checkNotNull(mg); + this.mg = Objects.requireNonNull(mg); } @Override public String toString() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/Hook.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/Hook.java b/core/src/main/java/org/apache/calcite/runtime/Hook.java index 0cfbc01..10d4586 100644 --- a/core/src/main/java/org/apache/calcite/runtime/Hook.java +++ b/core/src/main/java/org/apache/calcite/runtime/Hook.java @@ -18,11 +18,11 @@ package org.apache.calcite.runtime; import org.apache.calcite.util.Holder; -import com.google.common.base.Function; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Consumer; +import java.util.function.Function; /** * Collection of hooks that can be set by observers and are executed at various @@ -88,15 +88,11 @@ public enum Hook { * pipeline expressions (for the MongoDB adapter), et cetera. */ QUERY_PLAN; - private final List<Function<Object, Object>> handlers = + private final List<Consumer<Object>> handlers = new CopyOnWriteArrayList<>(); - private final ThreadLocal<List<Function<Object, Object>>> threadHandlers = - new ThreadLocal<List<Function<Object, Object>>>() { - protected List<Function<Object, Object>> initialValue() { - return new ArrayList<>(); - } - }; + private final ThreadLocal<List<Consumer<Object>>> threadHandlers = + ThreadLocal.withInitial(ArrayList::new); /** Adds a handler for this Hook. * @@ -112,56 +108,70 @@ public enum Hook { * }</pre> * </blockquote> */ - public <T, R> Closeable add(final Function<T, R> handler) { + public <T, R> Closeable add(final Consumer<T> handler) { //noinspection unchecked - handlers.add((Function<Object, Object>) handler); - return new Closeable() { - public void close() { - remove(handler); - } - }; + handlers.add((Consumer<Object>) handler); + return () -> remove(handler); + } + + /** @deprecated Use {@link #addThread(Consumer)}. */ + @SuppressWarnings("Guava") + @Deprecated // to be removed in 2.0 + public <T, R> Closeable add(final Function<T, R> handler) { + return add((Consumer<T>) handler::apply); } /** Removes a handler from this Hook. */ - private boolean remove(Function handler) { + private boolean remove(Consumer handler) { return handlers.remove(handler); } /** Adds a handler for this thread. */ - public <T, R> Closeable addThread(final Function<T, R> handler) { + public <T> Closeable addThread(final Consumer<T> handler) { //noinspection unchecked - threadHandlers.get().add((Function<Object, Object>) handler); - return new Closeable() { - public void close() { - removeThread(handler); - } - }; + threadHandlers.get().add((Consumer<Object>) handler); + return () -> removeThread(handler); + } + + /** @deprecated Use {@link #addThread(Consumer)}. */ + @SuppressWarnings("Guava") + @Deprecated // to be removed in 2.0 + public <T, R> Closeable addThread( + final com.google.common.base.Function<T, R> handler) { + return addThread((Consumer<T>) handler::apply); } /** Removes a thread handler from this Hook. */ - private boolean removeThread(Function handler) { + private boolean removeThread(Consumer handler) { return threadHandlers.get().remove(handler); } + /** @deprecated Use {@link #propertyJ}. */ + @SuppressWarnings("Guava") + @Deprecated // return type will change in 2.0 + public static <V> com.google.common.base.Function<Holder<V>, Void> property(final V v) { + return holder -> { + holder.set(v); + return null; + }; + } + /** Returns a function that, when a hook is called, will "return" a given * value. (Because of the way hooks work, it "returns" the value by writing * into a {@link Holder}. */ - public static <V> Function<Holder<V>, Void> property(final V v) { - return new Function<Holder<V>, Void>() { - public Void apply(Holder<V> holder) { - holder.set(v); - return null; - } + public static <V> Consumer<Holder<V>> propertyJ(final V v) { + return holder -> { + holder.set(v); }; } /** Runs all handlers registered for this Hook, with the given argument. */ public void run(Object arg) { - for (Function<Object, Object> handler : handlers) { - handler.apply(arg); + for (Consumer<Object> handler : handlers) { + handler.accept(arg); } - for (Function<Object, Object> handler : threadHandlers.get()) { - handler.apply(arg); + for (Consumer<Object> handler : threadHandlers.get()) { + handler.accept(arg); } } @@ -176,10 +186,7 @@ public enum Hook { /** Removes a Hook after use. */ public interface Closeable extends AutoCloseable { /** Closeable that does nothing. */ - Closeable EMPTY = - new Closeable() { - public void close() {} - }; + Closeable EMPTY = () -> { }; // override, removing "throws" @Override void close(); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java index bc790d6..783d3bc 100644 --- a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java +++ b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java @@ -27,9 +27,7 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Map; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; /** * Utilities for connecting to REST services such as Splunk via HTTP. @@ -49,12 +47,7 @@ public class HttpUtils { HttpsURLConnection httpsConn = (HttpsURLConnection) httpConn; httpsConn.setSSLSocketFactory( TrustAllSslSocketFactory.createSSLSocketFactory()); - httpsConn.setHostnameVerifier( - new HostnameVerifier() { - public boolean verify(String arg0, SSLSession arg1) { - return true; - } - }); + httpsConn.setHostnameVerifier((arg0, arg1) -> true); } return httpConn; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/PredicateImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/PredicateImpl.java b/core/src/main/java/org/apache/calcite/runtime/PredicateImpl.java index f04737b..33adb54 100644 --- a/core/src/main/java/org/apache/calcite/runtime/PredicateImpl.java +++ b/core/src/main/java/org/apache/calcite/runtime/PredicateImpl.java @@ -30,6 +30,9 @@ import javax.annotation.Nullable; * but still works on JDK 1.7. * * @param <T> the type of the input to the predicate + * + * @deprecated Now Calcite is Java 8 and higher, we recommend that you + * implement {@link java.util.function.Predicate} directly. */ public abstract class PredicateImpl<T> implements Predicate<T> { public final boolean apply(@Nullable T input) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java b/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java index 724bcf1..4724d8c 100644 --- a/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java +++ b/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java @@ -51,51 +51,45 @@ public class ResultSetEnumerable<T> extends AbstractEnumerable<T> { ResultSetEnumerable.class); private static final Function1<ResultSet, Function0<Object>> AUTO_ROW_BUILDER_FACTORY = - new Function1<ResultSet, Function0<Object>>() { - public Function0<Object> apply(final ResultSet resultSet) { - final ResultSetMetaData metaData; - final int columnCount; - try { - metaData = resultSet.getMetaData(); - columnCount = metaData.getColumnCount(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - if (columnCount == 1) { - return new Function0<Object>() { - public Object apply() { - try { - return resultSet.getObject(1); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - }; - } else { - //noinspection unchecked - return (Function0) new Function0<Object[]>() { - public Object[] apply() { - try { - final List<Object> list = new ArrayList<Object>(); - for (int i = 0; i < columnCount; i++) { - if (metaData.getColumnType(i + 1) == Types.TIMESTAMP) { - long v = resultSet.getLong(i + 1); - if (v == 0 && resultSet.wasNull()) { - list.add(null); - } else { - list.add(v); - } - } else { - list.add(resultSet.getObject(i + 1)); - } + resultSet -> { + final ResultSetMetaData metaData; + final int columnCount; + try { + metaData = resultSet.getMetaData(); + columnCount = metaData.getColumnCount(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + if (columnCount == 1) { + return () -> { + try { + return resultSet.getObject(1); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }; + } else { + //noinspection unchecked + return (Function0) () -> { + try { + final List<Object> list = new ArrayList<Object>(); + for (int i = 0; i < columnCount; i++) { + if (metaData.getColumnType(i + 1) == Types.TIMESTAMP) { + long v = resultSet.getLong(i + 1); + if (v == 0 && resultSet.wasNull()) { + list.add(null); + } else { + list.add(v); } - return list.toArray(); - } catch (SQLException e) { - throw new RuntimeException(e); + } else { + list.add(resultSet.getObject(i + 1)); } } - }; - } + return list.toArray(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }; } }; @@ -227,43 +221,37 @@ public class ResultSetEnumerable<T> extends AbstractEnumerable<T> { private static Function1<ResultSet, Function0<Object>> primitiveRowBuilderFactory(final Primitive[] primitives) { - return new Function1<ResultSet, Function0<Object>>() { - public Function0<Object> apply(final ResultSet resultSet) { - final ResultSetMetaData metaData; - final int columnCount; + return resultSet -> { + final ResultSetMetaData metaData; + final int columnCount; + try { + metaData = resultSet.getMetaData(); + columnCount = metaData.getColumnCount(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + assert columnCount == primitives.length; + if (columnCount == 1) { + return () -> { + try { + return resultSet.getObject(1); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }; + } + //noinspection unchecked + return (Function0) () -> { try { - metaData = resultSet.getMetaData(); - columnCount = metaData.getColumnCount(); + final List<Object> list = new ArrayList<Object>(); + for (int i = 0; i < columnCount; i++) { + list.add(primitives[i].jdbcGet(resultSet, i + 1)); + } + return list.toArray(); } catch (SQLException e) { throw new RuntimeException(e); } - assert columnCount == primitives.length; - if (columnCount == 1) { - return new Function0<Object>() { - public Object apply() { - try { - return resultSet.getObject(1); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - }; - } - //noinspection unchecked - return (Function0) new Function0<Object[]>() { - public Object[] apply() { - try { - final List<Object> list = new ArrayList<Object>(); - for (int i = 0; i < columnCount; i++) { - list.add(primitives[i].jdbcGet(resultSet, i + 1)); - } - return list.toArray(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - }; - } + }; }; } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java index 3a95f25..83cc24e 100644 --- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java @@ -79,31 +79,20 @@ public class SqlFunctions { private static final TimeZone LOCAL_TZ = TimeZone.getDefault(); private static final Function1<List<Object>, Enumerable<Object>> LIST_AS_ENUMERABLE = - new Function1<List<Object>, Enumerable<Object>>() { - public Enumerable<Object> apply(List<Object> list) { - return Linq4j.asEnumerable(list); - } - }; + Linq4j::asEnumerable; private static final Function1<Object[], Enumerable<Object[]>> ARRAY_CARTESIAN_PRODUCT = - new Function1<Object[], Enumerable<Object[]>>() { - public Enumerable<Object[]> apply(Object[] lists) { - final List<Enumerator<Object>> enumerators = new ArrayList<>(); - for (Object list : lists) { - enumerators.add(Linq4j.enumerator((List) list)); - } - final Enumerator<List<Object>> product = Linq4j.product(enumerators); - return new AbstractEnumerable<Object[]>() { - public Enumerator<Object[]> enumerator() { - return Linq4j.transform(product, - new Function1<List<Object>, Object[]>() { - public Object[] apply(List<Object> list) { - return list.toArray(); - } - }); - } - }; + lists -> { + final List<Enumerator<Object>> enumerators = new ArrayList<>(); + for (Object list : lists) { + enumerators.add(Linq4j.enumerator((List) list)); } + final Enumerator<List<Object>> product = Linq4j.product(enumerators); + return new AbstractEnumerable<Object[]>() { + public Enumerator<Object[]> enumerator() { + return Linq4j.transform(product, List::toArray); + } + }; }; /** Holds, for each thread, a map from sequence name to sequence current @@ -113,11 +102,7 @@ public class SqlFunctions { * that sequences can be parsed, validated and planned. A real application * will want persistent values for sequences, shared among threads. */ private static final ThreadLocal<Map<String, AtomicLong>> THREAD_SEQUENCES = - new ThreadLocal<Map<String, AtomicLong>>() { - @Override protected Map<String, AtomicLong> initialValue() { - return new HashMap<String, AtomicLong>(); - } - }; + ThreadLocal.withInitial(HashMap::new); private SqlFunctions() { } @@ -2212,20 +2197,12 @@ public class SqlFunctions { //noinspection unchecked return (Function1) LIST_AS_ENUMERABLE; } else { - return new Function1<Object, Enumerable<ComparableList<Comparable>>>() { - public Enumerable<ComparableList<Comparable>> apply(Object row) { - return p2(new Object[] { row }, fieldCounts, withOrdinality, - inputTypes); - } - }; + return row -> p2(new Object[] { row }, fieldCounts, withOrdinality, + inputTypes); } } - return new Function1<Object, Enumerable<FlatLists.ComparableList<Comparable>>>() { - public Enumerable<FlatLists.ComparableList<Comparable>> apply(Object lists) { - return p2((Object[]) lists, fieldCounts, withOrdinality, - inputTypes); - } - }; + return lists -> p2((Object[]) lists, fieldCounts, withOrdinality, + inputTypes); } private static Enumerable<FlatLists.ComparableList<Comparable>> p2( @@ -2243,12 +2220,7 @@ public class SqlFunctions { (List<Comparable>) inputObject; enumerators.add( Linq4j.transform( - Linq4j.enumerator(list), - new Function1<Comparable, List<Comparable>>() { - public List<Comparable> apply(Comparable a0) { - return FlatLists.of(a0); - } - })); + Linq4j.enumerator(list), FlatLists::of)); break; case LIST: @SuppressWarnings("unchecked") List<List<Comparable>> listList = @@ -2262,11 +2234,7 @@ public class SqlFunctions { Linq4j.enumerator(map.entrySet()); Enumerator<List<Comparable>> transformed = Linq4j.transform(enumerator, - new Function1<Entry<Comparable, Comparable>, List<Comparable>>() { - public List<Comparable> apply(Entry<Comparable, Comparable> e) { - return FlatLists.of(e.getKey(), e.getValue()); - } - }); + e -> FlatLists.of(e.getKey(), e.getValue())); enumerators.add(transformed); break; default: http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/FunctionParameter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/FunctionParameter.java b/core/src/main/java/org/apache/calcite/schema/FunctionParameter.java index 3e95628..37af4bd 100644 --- a/core/src/main/java/org/apache/calcite/schema/FunctionParameter.java +++ b/core/src/main/java/org/apache/calcite/schema/FunctionParameter.java @@ -26,14 +26,6 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; * {@link java.lang.reflect.Parameter} was too confusing.</p> */ public interface FunctionParameter { - /** Function to get the name of a parameter. */ - com.google.common.base.Function<FunctionParameter, String> NAME_FN = - new com.google.common.base.Function<FunctionParameter, String>() { - public String apply(FunctionParameter p) { - return p.getName(); - } - }; - /** * Zero-based ordinal of this parameter within the member's parameter * list. http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/Schemas.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/Schemas.java b/core/src/main/java/org/apache/calcite/schema/Schemas.java index b238b3b..b303358 100644 --- a/core/src/main/java/org/apache/calcite/schema/Schemas.java +++ b/core/src/main/java/org/apache/calcite/schema/Schemas.java @@ -35,7 +35,6 @@ import org.apache.calcite.materialize.Lattice; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelProtoDataType; -import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.type.SqlTypeUtil; import org.apache.calcite.tools.RelRunner; import org.apache.calcite.util.BuiltInMethod; @@ -55,34 +54,14 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; + +import static org.apache.calcite.jdbc.CalciteSchema.LatticeEntry; /** * Utility functions for schemas. */ public final class Schemas { - private static final com.google.common.base.Function< - CalciteSchema.LatticeEntry, - CalciteSchema.TableEntry> TO_TABLE_ENTRY = - new com.google.common.base.Function<CalciteSchema.LatticeEntry, - CalciteSchema.TableEntry>() { - public CalciteSchema.TableEntry apply( - CalciteSchema.LatticeEntry entry) { - final CalciteSchema.TableEntry starTable = entry.getStarTable(); - assert starTable.getTable().getJdbcTableType() - == Schema.TableType.STAR; - return entry.getStarTable(); - } - }; - - private static final com.google.common.base.Function< - CalciteSchema.LatticeEntry, - Lattice> TO_LATTICE = - new com.google.common.base.Function<CalciteSchema.LatticeEntry, - Lattice>() { - public Lattice apply(CalciteSchema.LatticeEntry entry) { - return entry.getLattice(); - } - }; private Schemas() { throw new AssertionError("no instances!"); @@ -245,7 +224,7 @@ public final class Schemas { * array. */ public static Enumerable<Object[]> enumerable(final FilterableTable table, final DataContext root) { - return table.scan(root, ImmutableList.<RexNode>of()); + return table.scan(root, ImmutableList.of()); } /** Returns an {@link org.apache.calcite.linq4j.Enumerable} over the rows of @@ -253,7 +232,7 @@ public final class Schemas { * representing each row as an object array. */ public static Enumerable<Object[]> enumerable( final ProjectableFilterableTable table, final DataContext root) { - return table.scan(root, ImmutableList.<RexNode>of(), + return table.scan(root, ImmutableList.of(), identity(table.getRowType(root.getTypeFactory()).getFieldCount())); } @@ -448,22 +427,14 @@ public final class Schemas { * {@link RelProtoDataType} * that asks a given table for its row type with a given type factory. */ public static RelProtoDataType proto(final Table table) { - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - return table.getRowType(typeFactory); - } - }; + return table::getRowType; } /** Returns an implementation of {@link RelProtoDataType} * that asks a given scalar function for its return type with a given type * factory. */ public static RelProtoDataType proto(final ScalarFunction function) { - return new RelProtoDataType() { - public RelDataType apply(RelDataTypeFactory typeFactory) { - return function.getReturnType(typeFactory); - } - }; + return function::getReturnType; } /** Returns the star tables defined in a schema. @@ -472,7 +443,13 @@ public final class Schemas { public static List<CalciteSchema.TableEntry> getStarTables( CalciteSchema schema) { final List<CalciteSchema.LatticeEntry> list = getLatticeEntries(schema); - return Lists.transform(list, TO_TABLE_ENTRY); + return Lists.transform(list, entry -> { + final CalciteSchema.TableEntry starTable = + Objects.requireNonNull(entry).getStarTable(); + assert starTable.getTable().getJdbcTableType() + == Schema.TableType.STAR; + return entry.getStarTable(); + }); } /** Returns the lattices defined in a schema. @@ -480,7 +457,7 @@ public final class Schemas { * @param schema Schema */ public static List<Lattice> getLattices(CalciteSchema schema) { final List<CalciteSchema.LatticeEntry> list = getLatticeEntries(schema); - return Lists.transform(list, TO_LATTICE); + return Lists.transform(list, CalciteSchema.LatticeEntry::getLattice); } /** Returns the lattices defined in a schema. @@ -488,7 +465,7 @@ public final class Schemas { * @param schema Schema */ public static List<CalciteSchema.LatticeEntry> getLatticeEntries( CalciteSchema schema) { - final List<CalciteSchema.LatticeEntry> list = Lists.newArrayList(); + final List<LatticeEntry> list = new ArrayList<>(); gatherLattices(schema, list); return list; } @@ -520,7 +497,7 @@ public final class Schemas { /** Generates a table name that is unique within the given schema. */ public static String uniqueTableName(CalciteSchema schema, String base) { - String t = Preconditions.checkNotNull(base); + String t = Objects.requireNonNull(base); for (int x = 0; schema.getTable(t, true) != null; x++) { t = base + x; } @@ -558,7 +535,7 @@ public final class Schemas { public static Path path(SchemaPlus schema) { List<Pair<String, Schema>> list = new ArrayList<>(); for (SchemaPlus s = schema; s != null; s = s.getParentSchema()) { - list.add(Pair.<String, Schema>of(s.getName(), s)); + list.add(Pair.of(s.getName(), s)); } return new PathImpl(ImmutableList.copyOf(Lists.reverse(list))); } @@ -572,7 +549,7 @@ public final class Schemas { DummyDataContext(CalciteConnection connection, SchemaPlus rootSchema) { this.connection = connection; this.rootSchema = rootSchema; - this.map = ImmutableMap.<String, Object>of(); + this.map = ImmutableMap.of(); } public SchemaPlus getRootSchema() { @@ -598,7 +575,7 @@ public final class Schemas { private final ImmutableList<Pair<String, Schema>> pairs; private static final PathImpl EMPTY = - new PathImpl(ImmutableList.<Pair<String, Schema>>of()); + new PathImpl(ImmutableList.of()); PathImpl(ImmutableList<Pair<String, Schema>> pairs) { this.pairs = pairs; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/Statistics.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/Statistics.java b/core/src/main/java/org/apache/calcite/schema/Statistics.java index d3d4173..0e55140 100644 --- a/core/src/main/java/org/apache/calcite/schema/Statistics.java +++ b/core/src/main/java/org/apache/calcite/schema/Statistics.java @@ -45,7 +45,7 @@ public class Statistics { } public List<RelReferentialConstraint> getReferentialConstraints() { - return ImmutableList.<RelReferentialConstraint>of(); + return ImmutableList.of(); } public List<RelCollation> getCollations() { @@ -59,15 +59,15 @@ public class Statistics { /** Returns a statistic with a given set of referential constraints. */ public static Statistic of(final List<RelReferentialConstraint> referentialConstraints) { - return of(null, ImmutableList.<ImmutableBitSet>of(), - referentialConstraints, ImmutableList.<RelCollation>of()); + return of(null, ImmutableList.of(), + referentialConstraints, ImmutableList.of()); } /** Returns a statistic with a given row count and set of unique keys. */ public static Statistic of(final double rowCount, final List<ImmutableBitSet> keys) { - return of(rowCount, keys, ImmutableList.<RelReferentialConstraint>of(), - ImmutableList.<RelCollation>of()); + return of(rowCount, keys, ImmutableList.of(), + ImmutableList.of()); } /** Returns a statistic with a given row count, set of unique keys, @@ -75,7 +75,7 @@ public class Statistics { public static Statistic of(final double rowCount, final List<ImmutableBitSet> keys, final List<RelCollation> collations) { - return of(rowCount, keys, ImmutableList.<RelReferentialConstraint>of(), collations); + return of(rowCount, keys, ImmutableList.of(), collations); } /** Returns a statistic with a given row count, set of unique keys, http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/Table.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/Table.java b/core/src/main/java/org/apache/calcite/schema/Table.java index 33185db..f3540d1 100644 --- a/core/src/main/java/org/apache/calcite/schema/Table.java +++ b/core/src/main/java/org/apache/calcite/schema/Table.java @@ -77,9 +77,9 @@ public interface Table { * @param parent Parent node of {@code call} in the {@link SqlNode} tree * @param config Config settings. May be null * @return true iff the given aggregate call is valid - * */ - boolean rolledUpColumnValidInsideAgg(String column, SqlCall call, SqlNode parent, - CalciteConnectionConfig config); + */ + boolean rolledUpColumnValidInsideAgg(String column, SqlCall call, + SqlNode parent, CalciteConnectionConfig config); } // End Table.java http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/impl/AbstractSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/impl/AbstractSchema.java b/core/src/main/java/org/apache/calcite/schema/impl/AbstractSchema.java index dc8c25e..c77107b 100644 --- a/core/src/main/java/org/apache/calcite/schema/impl/AbstractSchema.java +++ b/core/src/main/java/org/apache/calcite/schema/impl/AbstractSchema.java @@ -50,10 +50,6 @@ import java.util.Set; * <li>The name and parent schema are as specified in the constructor * arguments.</li> * </ul> - * - * <p>For constructing custom maps and multi-maps, we recommend - * {@link com.google.common.base.Suppliers} and - * {@link com.google.common.collect.Maps}.</p> */ public class AbstractSchema implements Schema { public AbstractSchema() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java b/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java index 69f2269..34644e9 100644 --- a/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java +++ b/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java @@ -25,12 +25,12 @@ import org.apache.calcite.schema.FunctionParameter; import org.apache.calcite.schema.ImplementableAggFunction; import org.apache.calcite.util.ReflectUtil; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.List; +import java.util.Objects; import static org.apache.calcite.util.Static.RESOURCE; @@ -70,8 +70,8 @@ public class AggregateFunctionImpl implements AggregateFunction, this.parameters = params; this.accumulatorType = accumulatorType; this.resultType = resultType; - this.initMethod = Preconditions.checkNotNull(initMethod); - this.addMethod = Preconditions.checkNotNull(addMethod); + this.initMethod = Objects.requireNonNull(initMethod); + this.addMethod = Objects.requireNonNull(addMethod); this.mergeMethod = mergeMethod; this.resultMethod = resultMethod; this.isStatic = Modifier.isStatic(initMethod.getModifiers()); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/impl/MaterializedViewTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/impl/MaterializedViewTable.java b/core/src/main/java/org/apache/calcite/schema/impl/MaterializedViewTable.java index baebab5..5121221 100644 --- a/core/src/main/java/org/apache/calcite/schema/impl/MaterializedViewTable.java +++ b/core/src/main/java/org/apache/calcite/schema/impl/MaterializedViewTable.java @@ -30,12 +30,11 @@ import org.apache.calcite.schema.Schemas; import org.apache.calcite.schema.Table; import org.apache.calcite.schema.TranslatableTable; -import com.google.common.base.Preconditions; - import java.lang.reflect.Type; import java.sql.DriverManager; import java.sql.SQLException; import java.util.List; +import java.util.Objects; /** * Table that is a materialized view. @@ -107,7 +106,7 @@ public class MaterializedViewTable extends ViewTable { super(schema, viewSql, viewSchemaPath != null ? viewSchemaPath : schema.path(null), viewPath, Boolean.TRUE); - this.key = Preconditions.checkNotNull( + this.key = Objects.requireNonNull( MaterializationService.instance().defineMaterialization( schema, null, viewSql, schemaPath, suggestedTableName, true, existing)); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java b/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java index a312188..567b780 100644 --- a/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java +++ b/core/src/main/java/org/apache/calcite/schema/impl/ModifiableViewTable.java @@ -39,10 +39,10 @@ import org.apache.calcite.util.ImmutableIntList; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -186,7 +186,7 @@ public class ModifiableViewTable extends ViewTable private ModifiableViewTableInitializerExpressionFactory() { super(); - final Map<Integer, RexNode> projectMap = Maps.newHashMap(); + final Map<Integer, RexNode> projectMap = new HashMap<>(); final List<RexNode> filters = new ArrayList<>(); RelOptUtil.inferViewPredicates(projectMap, filters, constraint); assert filters.isEmpty(); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java b/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java index 27f3cf8..b0a62a5 100644 --- a/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java +++ b/core/src/main/java/org/apache/calcite/schema/impl/StarTable.java @@ -34,11 +34,11 @@ import org.apache.calcite.schema.TranslatableTable; import org.apache.calcite.util.ImmutableIntList; import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Virtual table that is composed of two or more tables joined together. @@ -63,7 +63,7 @@ public class StarTable extends AbstractTable implements TranslatableTable { /** Creates a StarTable. */ private StarTable(Lattice lattice, ImmutableList<Table> tables) { - this.lattice = Preconditions.checkNotNull(lattice); + this.lattice = Objects.requireNonNull(lattice); this.tables = tables; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java b/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java index bd311f2..d9e0322 100755 --- a/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlBasicCall.java @@ -19,9 +19,8 @@ package org.apache.calcite.sql; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.util.UnmodifiableArrayList; -import com.google.common.base.Preconditions; - import java.util.List; +import java.util.Objects; /** * Implementation of {@link SqlCall} that keeps its operands in an array. @@ -46,7 +45,7 @@ public class SqlBasicCall extends SqlCall { boolean expanded, SqlLiteral functionQualifier) { super(pos); - this.operator = Preconditions.checkNotNull(operator); + this.operator = Objects.requireNonNull(operator); this.operands = operands; this.expanded = expanded; this.functionQuantifier = functionQualifier; @@ -65,7 +64,7 @@ public class SqlBasicCall extends SqlCall { } public void setOperator(SqlOperator operator) { - this.operator = Preconditions.checkNotNull(operator); + this.operator = Objects.requireNonNull(operator); } public SqlOperator getOperator() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java index 71380e1..d9c4ef2 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlBinaryStringLiteral.java @@ -19,9 +19,7 @@ package org.apache.calcite.sql; import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.BitString; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; +import org.apache.calcite.util.Util; import java.util.List; @@ -32,12 +30,6 @@ import java.util.List; * {@link SqlTypeName#BINARY}. */ public class SqlBinaryStringLiteral extends SqlAbstractStringLiteral { - private static final Function<SqlLiteral, BitString> F = - new Function<SqlLiteral, BitString>() { - public BitString apply(SqlLiteral literal) { - return ((SqlBinaryStringLiteral) literal).getBitString(); - } - }; //~ Constructors ----------------------------------------------------------- @@ -70,7 +62,9 @@ public class SqlBinaryStringLiteral extends SqlAbstractStringLiteral { protected SqlAbstractStringLiteral concat1(List<SqlLiteral> literals) { return new SqlBinaryStringLiteral( - BitString.concat(Lists.transform(literals, F)), + BitString.concat( + Util.transform(literals, + literal -> ((SqlBinaryStringLiteral) literal).getBitString())), literals.get(0).getParserPosition()); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlCall.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCall.java b/core/src/main/java/org/apache/calcite/sql/SqlCall.java index 9e50417..aeddb6f 100755 --- a/core/src/main/java/org/apache/calcite/sql/SqlCall.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCall.java @@ -84,7 +84,7 @@ public abstract class SqlCall extends SqlNode { @Override public SqlNode clone(SqlParserPos pos) { final List<SqlNode> operandList = getOperandList(); return getOperator().createCall(getFunctionQuantifier(), pos, - operandList.toArray(new SqlNode[operandList.size()])); + operandList.toArray(new SqlNode[0])); } public void unparse( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java index 002382c..8fe2e82 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java @@ -30,7 +30,6 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.sql.validate.SqlValidatorUtil; import org.apache.calcite.util.NlsString; -import com.google.common.base.Function; import com.google.common.collect.Lists; import java.math.BigDecimal; @@ -154,20 +153,17 @@ public class SqlCallBinding extends SqlOperatorBinding { * formal parameters of the function. */ private List<SqlNode> permutedOperands(final SqlCall call) { final SqlFunction operator = (SqlFunction) call.getOperator(); - return Lists.transform(operator.getParamNames(), - new Function<String, SqlNode>() { - public SqlNode apply(String paramName) { - for (SqlNode operand2 : call.getOperandList()) { - final SqlCall call2 = (SqlCall) operand2; - assert operand2.getKind() == SqlKind.ARGUMENT_ASSIGNMENT; - final SqlIdentifier id = call2.operand(1); - if (id.getSimple().equals(paramName)) { - return call2.operand(0); - } - } - return DEFAULT_CALL; - } - }); + return Lists.transform(operator.getParamNames(), paramName -> { + for (SqlNode operand2 : call.getOperandList()) { + final SqlCall call2 = (SqlCall) operand2; + assert operand2.getKind() == SqlKind.ARGUMENT_ASSIGNMENT; + final SqlIdentifier id = call2.operand(1); + if (id.getSimple().equals(paramName)) { + return call2.operand(0); + } + } + return DEFAULT_CALL; + }); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java index b74176c..c3846f1 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCharStringLiteral.java @@ -22,9 +22,6 @@ import org.apache.calcite.util.Bug; import org.apache.calcite.util.NlsString; import org.apache.calcite.util.Util; -import com.google.common.base.Function; -import com.google.common.collect.Lists; - import java.util.List; /** @@ -34,12 +31,6 @@ import java.util.List; * {@link SqlTypeName#CHAR}. */ public class SqlCharStringLiteral extends SqlAbstractStringLiteral { - private static final Function<SqlLiteral, NlsString> F = - new Function<SqlLiteral, NlsString>() { - public NlsString apply(SqlLiteral literal) { - return ((SqlCharStringLiteral) literal).getNlsString(); - } - }; //~ Constructors ----------------------------------------------------------- @@ -83,7 +74,9 @@ public class SqlCharStringLiteral extends SqlAbstractStringLiteral { protected SqlAbstractStringLiteral concat1(List<SqlLiteral> literals) { return new SqlCharStringLiteral( - NlsString.concat(Lists.transform(literals, F)), + NlsString.concat( + Util.transform(literals, + literal -> ((SqlCharStringLiteral) literal).getNlsString())), literals.get(0).getParserPosition()); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlDataTypeSpec.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDataTypeSpec.java b/core/src/main/java/org/apache/calcite/sql/SqlDataTypeSpec.java index cb921a4..a6238a3 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDataTypeSpec.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDataTypeSpec.java @@ -28,8 +28,6 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import java.nio.charset.Charset; import java.util.Objects; import java.util.TimeZone; @@ -364,7 +362,7 @@ public class SqlDataTypeSpec extends SqlNode { charset = typeFactory.getDefaultCharset(); } else { String javaCharSetName = - Preconditions.checkNotNull( + Objects.requireNonNull( SqlUtil.translateCharacterSetName(charSetName), charSetName); charset = Charset.forName(javaCharSetName); } @@ -378,7 +376,7 @@ public class SqlDataTypeSpec extends SqlNode { if (null != collectionsTypeName) { final String collectionName = collectionsTypeName.getSimple(); final SqlTypeName collectionsSqlTypeName = - Preconditions.checkNotNull(SqlTypeName.get(collectionName), + Objects.requireNonNull(SqlTypeName.get(collectionName), collectionName); switch (collectionsSqlTypeName) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlDdl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDdl.java b/core/src/main/java/org/apache/calcite/sql/SqlDdl.java index c22abb6..671ad7d 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDdl.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDdl.java @@ -18,7 +18,7 @@ package org.apache.calcite.sql; import org.apache.calcite.sql.parser.SqlParserPos; -import com.google.common.base.Preconditions; +import java.util.Objects; /** Base class for CREATE, DROP and other DDL statements. */ public abstract class SqlDdl extends SqlCall { @@ -31,7 +31,7 @@ public abstract class SqlDdl extends SqlCall { /** Creates a SqlDdl. */ public SqlDdl(SqlOperator operator, SqlParserPos pos) { super(pos); - this.operator = Preconditions.checkNotNull(operator); + this.operator = Objects.requireNonNull(operator); } public SqlOperator getOperator() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java b/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java index b6432c7..e9959b0 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java @@ -64,7 +64,7 @@ public class SqlDescribeSchema extends SqlCall { } @Override public List<SqlNode> getOperandList() { - return ImmutableNullableList.<SqlNode>of(schema); + return ImmutableNullableList.of(schema); } public SqlIdentifier getSchema() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java index 025bced..76e088b 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java @@ -75,7 +75,7 @@ public class SqlDescribeTable extends SqlCall { } @Override public List<SqlNode> getOperandList() { - return ImmutableNullableList.<SqlNode>of(table, column); + return ImmutableNullableList.of(table, column); } public SqlIdentifier getTable() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlDialect.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java index 3e679d3..1314656 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java @@ -32,7 +32,6 @@ import org.apache.calcite.sql.type.BasicSqlType; import org.apache.calcite.sql.type.SqlTypeUtil; import com.google.common.base.Preconditions; -import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import org.slf4j.Logger; @@ -44,6 +43,8 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; +import java.util.Objects; +import java.util.function.Supplier; import java.util.regex.Pattern; import javax.annotation.Nonnull; @@ -135,9 +136,9 @@ public class SqlDialect { * @param context All the information necessary to create a dialect */ public SqlDialect(Context context) { - this.nullCollation = Preconditions.checkNotNull(context.nullCollation()); + this.nullCollation = Objects.requireNonNull(context.nullCollation()); this.databaseProduct = - Preconditions.checkNotNull(context.databaseProduct()); + Objects.requireNonNull(context.databaseProduct()); String identifierQuoteString = context.identifierQuoteString(); if (identifierQuoteString != null) { identifierQuoteString = identifierQuoteString.trim(); @@ -897,32 +898,24 @@ public class SqlDialect { */ UNKNOWN("Unknown", "`", NullCollation.HIGH); - private final Supplier<SqlDialect> dialect = - Suppliers.memoize(new Supplier<SqlDialect>() { - public SqlDialect get() { - final SqlDialect dialect = - SqlDialectFactoryImpl.simple(DatabaseProduct.this); - if (dialect != null) { - return dialect; - } - return new SqlDialect(SqlDialect.EMPTY_CONTEXT - .withDatabaseProduct(DatabaseProduct.this) - .withDatabaseProductName(databaseProductName) - .withIdentifierQuoteString(quoteString) - .withNullCollation(nullCollation)); - } - }); - - private String databaseProductName; - private String quoteString; - private final NullCollation nullCollation; + private final Supplier<SqlDialect> dialect; DatabaseProduct(String databaseProductName, String quoteString, NullCollation nullCollation) { - this.databaseProductName = - Preconditions.checkNotNull(databaseProductName); - this.quoteString = quoteString; - this.nullCollation = Preconditions.checkNotNull(nullCollation); + Objects.requireNonNull(databaseProductName); + Objects.requireNonNull(nullCollation); + dialect = Suppliers.memoize(() -> { + final SqlDialect dialect = + SqlDialectFactoryImpl.simple(DatabaseProduct.this); + if (dialect != null) { + return dialect; + } + return new SqlDialect(SqlDialect.EMPTY_CONTEXT + .withDatabaseProduct(DatabaseProduct.this) + .withDatabaseProductName(databaseProductName) + .withIdentifierQuoteString(quoteString) + .withNullCollation(nullCollation)); + })::get; } /** @@ -980,14 +973,14 @@ public class SqlDialect { int databaseMajorVersion, int databaseMinorVersion, String identifierQuoteString, NullCollation nullCollation, JethroDataSqlDialect.JethroInfo jethroInfo) { - this.databaseProduct = Preconditions.checkNotNull(databaseProduct); + this.databaseProduct = Objects.requireNonNull(databaseProduct); this.databaseProductName = databaseProductName; this.databaseVersion = databaseVersion; this.databaseMajorVersion = databaseMajorVersion; this.databaseMinorVersion = databaseMinorVersion; this.identifierQuoteString = identifierQuoteString; - this.nullCollation = Preconditions.checkNotNull(nullCollation); - this.jethroInfo = Preconditions.checkNotNull(jethroInfo); + this.nullCollation = Objects.requireNonNull(nullCollation); + this.jethroInfo = Objects.requireNonNull(jethroInfo); } @Nonnull public DatabaseProduct databaseProduct() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlFunction.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java index e485422..597b7ff 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlFunction.java @@ -16,7 +16,6 @@ */ package org.apache.calcite.sql; -import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.linq4j.function.Functions; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.type.SqlOperandTypeChecker; @@ -26,10 +25,10 @@ import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.Objects; import javax.annotation.Nonnull; import static org.apache.calcite.util.Static.RESOURCE; @@ -39,13 +38,6 @@ import static org.apache.calcite.util.Static.RESOURCE; * function-call syntax. */ public class SqlFunction extends SqlOperator { - /** Function that generates "arg{n}" for the {@code n}th argument name. */ - private static final Function1<Integer, String> ARG_FN = - new Function1<Integer, String>() { - public String apply(Integer a0) { - return "arg" + a0; - } - }; //~ Instance fields -------------------------------------------------------- @@ -123,7 +115,7 @@ public class SqlFunction extends SqlOperator { operandTypeChecker); this.sqlIdentifier = sqlIdentifier; - this.category = Preconditions.checkNotNull(category); + this.category = Objects.requireNonNull(category); this.paramTypes = paramTypes == null ? null : ImmutableList.copyOf(paramTypes); } @@ -161,7 +153,7 @@ public class SqlFunction extends SqlOperator { * <p>The default implementation returns {@code [arg0, arg1, ..., argN]}. */ public List<String> getParamNames() { - return Functions.generate(paramTypes.size(), ARG_FN); + return Functions.generate(paramTypes.size(), i -> "arg" + i); } public void unparse( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java index 4839805..ba6fb0c 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java @@ -26,7 +26,6 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -37,19 +36,6 @@ import java.util.List; * A <code>SqlIdentifier</code> is an identifier, possibly compound. */ public class SqlIdentifier extends SqlNode { - private static final Function<String, String> STAR_TO_EMPTY = - new Function<String, String>() { - public String apply(String s) { - return s.equals("*") ? "" : s; - } - }; - - private static final Function<String, String> EMPTY_TO_STAR = - new Function<String, String>() { - public String apply(String s) { - return s.equals("") ? "*" : s.equals("*") ? "\"*\"" : s; - } - }; //~ Instance fields -------------------------------------------------------- @@ -131,7 +117,8 @@ public class SqlIdentifier extends SqlNode { /** Creates an identifier that ends in a wildcard star. */ public static SqlIdentifier star(List<String> names, SqlParserPos pos, List<SqlParserPos> componentPositions) { - return new SqlIdentifier(Lists.transform(names, STAR_TO_EMPTY), null, pos, + return new SqlIdentifier( + Lists.transform(names, s -> s.equals("*") ? "" : s), null, pos, componentPositions); } @@ -156,7 +143,8 @@ public class SqlIdentifier extends SqlNode { /** Converts empty strings in a list of names to stars. */ public static List<String> toStar(List<String> names) { - return Lists.transform(names, EMPTY_TO_STAR); + return Lists.transform(names, + s -> s.equals("") ? "*" : s.equals("*") ? "\"*\"" : s); } /** @@ -175,7 +163,7 @@ public class SqlIdentifier extends SqlNode { * Does not modify this identifier. */ public SqlIdentifier setName(int i, String name) { if (!names.get(i).equals(name)) { - String[] nameArray = names.toArray(new String[names.size()]); + String[] nameArray = names.toArray(new String[0]); nameArray[i] = name; return new SqlIdentifier(ImmutableList.copyOf(nameArray), collation, pos, componentPositions); @@ -274,8 +262,10 @@ public class SqlIdentifier extends SqlNode { */ public SqlIdentifier plusStar() { final SqlIdentifier id = this.plus("*", SqlParserPos.ZERO); - return new SqlIdentifier(Lists.transform(id.names, STAR_TO_EMPTY), null, id.pos, - id.componentPositions); + return new SqlIdentifier( + id.names.stream().map(s -> s.equals("*") ? "" : s) + .collect(Util.toImmutableList()), + null, id.pos, id.componentPositions); } /** Creates an identifier that consists of all but the last {@code n} http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java b/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java index 2fafec7..a25d93d 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlIntervalQualifier.java @@ -29,9 +29,8 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import java.math.BigDecimal; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -109,7 +108,7 @@ public class SqlIntervalQualifier extends SqlNode { endUnit = null; } this.timeUnitRange = - TimeUnitRange.of(Preconditions.checkNotNull(startUnit), endUnit); + TimeUnitRange.of(Objects.requireNonNull(startUnit), endUnit); this.startPrecision = startPrecision; this.fractionalSecondPrecision = fractionalSecondPrecision; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java index a057697..d84d931 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java @@ -25,10 +25,10 @@ import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorImpl; import org.apache.calcite.sql.validate.SqlValidatorScope; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.Map; +import java.util.Objects; import static org.apache.calcite.util.Static.RESOURCE; @@ -601,7 +601,7 @@ public class SqlJdbcFunctionCall extends SqlFunction { */ PermutingMakeCall(SqlOperator operator, int[] order) { super(operator); - this.order = Preconditions.checkNotNull(order); + this.order = Objects.requireNonNull(order); } @Override public SqlCall createCall(SqlParserPos pos, http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/SqlJoin.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java index 104d315..e533ee9 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java @@ -24,6 +24,7 @@ import org.apache.calcite.util.Util; import com.google.common.base.Preconditions; import java.util.List; +import java.util.Objects; /** * Parse tree node representing a {@code JOIN} clause. @@ -60,15 +61,15 @@ public class SqlJoin extends SqlCall { SqlNode condition) { super(pos); this.left = left; - this.natural = Preconditions.checkNotNull(natural); - this.joinType = Preconditions.checkNotNull(joinType); + this.natural = Objects.requireNonNull(natural); + this.joinType = Objects.requireNonNull(joinType); this.right = right; - this.conditionType = Preconditions.checkNotNull(conditionType); + this.conditionType = Objects.requireNonNull(conditionType); this.condition = condition; Preconditions.checkArgument(natural.getTypeName() == SqlTypeName.BOOLEAN); - Preconditions.checkNotNull(conditionType.symbolValue(JoinConditionType.class)); - Preconditions.checkNotNull(joinType.symbolValue(JoinType.class)); + Objects.requireNonNull(conditionType.symbolValue(JoinConditionType.class)); + Objects.requireNonNull(joinType.symbolValue(JoinType.class)); } //~ Methods ----------------------------------------------------------------
