http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java index 6096630..2bff11c 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java +++ b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java @@ -46,7 +46,6 @@ import org.apache.calcite.util.ReflectiveVisitDispatcher; import org.apache.calcite.util.ReflectiveVisitor; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -65,6 +64,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; /** * Interpreter. @@ -81,7 +81,7 @@ public class Interpreter extends AbstractEnumerable<Object[]> /** Creates an Interpreter. */ public Interpreter(DataContext dataContext, RelNode rootRel) { - this.dataContext = Preconditions.checkNotNull(dataContext); + this.dataContext = Objects.requireNonNull(dataContext); final RelNode rel = optimize(rootRel); final CompilerImpl compiler = new Nodes.CoreCompiler(this, rootRel.getCluster()); @@ -266,7 +266,7 @@ public class Interpreter extends AbstractEnumerable<Object[]> private final Enumerator<Row> enumerator; EnumeratorSource(final Enumerator<Row> enumerator) { - this.enumerator = Preconditions.checkNotNull(enumerator); + this.enumerator = Objects.requireNonNull(enumerator); } @Override public Row receive() {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java index e4cf9e6..7b2ddca 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java +++ b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java @@ -17,7 +17,6 @@ package org.apache.calcite.interpreter; import org.apache.calcite.adapter.enumerable.JavaRowFormat; -import org.apache.calcite.adapter.enumerable.PhysType; import org.apache.calcite.adapter.enumerable.PhysTypeImpl; import org.apache.calcite.adapter.enumerable.RexToLixTranslator; import org.apache.calcite.jdbc.JavaTypeFactoryImpl; @@ -40,7 +39,6 @@ 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 org.codehaus.commons.compiler.CompileException; import org.codehaus.commons.compiler.CompilerFactoryFactory; @@ -50,7 +48,7 @@ import org.codehaus.commons.compiler.ICompilerFactory; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Modifier; -import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; /** @@ -85,17 +83,14 @@ public class JaninoRexCompiler implements Interpreter.ScalarCompiler { final RexToLixTranslator.InputGetter inputGetter = new RexToLixTranslator.InputGetterImpl( ImmutableList.of( - Pair.<Expression, PhysType>of( + Pair.of( Expressions.field(context_, BuiltInMethod.CONTEXT_VALUES.field), PhysTypeImpl.of(javaTypeFactory, inputRowType, JavaRowFormat.ARRAY, false)))); - final Function1<String, RexToLixTranslator.InputGetter> correlates = - new Function1<String, RexToLixTranslator.InputGetter>() { - public RexToLixTranslator.InputGetter apply(String a0) { - throw new UnsupportedOperationException(); - } - }; + final Function1<String, RexToLixTranslator.InputGetter> correlates = a0 -> { + throw new UnsupportedOperationException(); + }; final Expression root = Expressions.field(context_, BuiltInMethod.CONTEXT_ROOT.field); final List<Expression> list = @@ -117,7 +112,7 @@ public class JaninoRexCompiler implements Interpreter.ScalarCompiler { * compiles. */ static Scalar baz(ParameterExpression context_, ParameterExpression outputValues_, BlockStatement block) { - final List<MemberDeclaration> declarations = Lists.newArrayList(); + final List<MemberDeclaration> declarations = new ArrayList<>(); // public void execute(Context, Object[] outputValues) declarations.add( @@ -145,7 +140,7 @@ public class JaninoRexCompiler implements Interpreter.ScalarCompiler { final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, "Buzz", null, - ImmutableList.<Type>of(Scalar.class), declarations); + ImmutableList.of(Scalar.class), declarations); String s = Expressions.toString(declarations, "\n", false); if (CalcitePrepareImpl.DEBUG) { Util.debugCode(System.out, s); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/JoinNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/JoinNode.java b/core/src/main/java/org/apache/calcite/interpreter/JoinNode.java index 349e26f..a167254 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/JoinNode.java +++ b/core/src/main/java/org/apache/calcite/interpreter/JoinNode.java @@ -19,8 +19,8 @@ package org.apache.calcite.interpreter; import org.apache.calcite.rel.core.Join; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.List; /** @@ -56,7 +56,7 @@ public class JoinNode implements Node { while ((left = leftSource.receive()) != null) { System.arraycopy(left.getValues(), 0, context.values, 0, leftCount); if (rightList == null) { - rightList = Lists.newArrayList(); + rightList = new ArrayList<>(); while ((right = rightSource.receive()) != null) { rightList.add(right); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/NoneToBindableConverterRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/NoneToBindableConverterRule.java b/core/src/main/java/org/apache/calcite/interpreter/NoneToBindableConverterRule.java index e352ca1..233b2ed 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/NoneToBindableConverterRule.java +++ b/core/src/main/java/org/apache/calcite/interpreter/NoneToBindableConverterRule.java @@ -23,7 +23,7 @@ import org.apache.calcite.rel.convert.ConverterRule; import org.apache.calcite.rel.core.RelFactories; import org.apache.calcite.tools.RelBuilderFactory; -import com.google.common.base.Predicates; +import java.util.function.Predicate; /** * Rule to convert a relational expression from @@ -40,7 +40,7 @@ public class NoneToBindableConverterRule extends ConverterRule { * @param relBuilderFactory Builder for relational expressions */ public NoneToBindableConverterRule(RelBuilderFactory relBuilderFactory) { - super(RelNode.class, Predicates.<RelNode>alwaysTrue(), Convention.NONE, + super(RelNode.class, (Predicate<RelNode>) r -> true, Convention.NONE, BindableConvention.INSTANCE, relBuilderFactory, "NoneToBindableConverterRule"); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/SortNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/SortNode.java b/core/src/main/java/org/apache/calcite/interpreter/SortNode.java index 04c95bf..210a530 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/SortNode.java +++ b/core/src/main/java/org/apache/calcite/interpreter/SortNode.java @@ -20,12 +20,10 @@ import org.apache.calcite.rel.RelFieldCollation; import org.apache.calcite.rel.core.Sort; import org.apache.calcite.rex.RexLiteral; -import com.google.common.base.Function; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Ordering; -import java.util.Collections; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -68,11 +66,11 @@ public class SortNode extends AbstractSingleNode<Sort> { } } else { // Build a sorted collection. - final List<Row> list = Lists.newArrayList(); + final List<Row> list = new ArrayList<>(); while ((row = source.receive()) != null) { list.add(row); } - Collections.sort(list, comparator()); + list.sort(comparator()); final int end = fetch < 0 || offset + fetch > list.size() ? list.size() : offset + fetch; @@ -89,11 +87,7 @@ public class SortNode extends AbstractSingleNode<Sort> { } return Ordering.compound( Iterables.transform(rel.getCollation().getFieldCollations(), - new Function<RelFieldCollation, Comparator<Row>>() { - public Comparator<Row> apply(RelFieldCollation input) { - return comparator(input); - } - })); + this::comparator)); } private Comparator<Row> comparator(RelFieldCollation fieldCollation) { @@ -101,20 +95,16 @@ public class SortNode extends AbstractSingleNode<Sort> { final int x = fieldCollation.getFieldIndex(); switch (fieldCollation.direction) { case ASCENDING: - return new Comparator<Row>() { - public int compare(Row o1, Row o2) { - final Comparable c1 = (Comparable) o1.getValues()[x]; - final Comparable c2 = (Comparable) o2.getValues()[x]; - return RelFieldCollation.compare(c1, c2, nullComparison); - } + return (o1, o2) -> { + final Comparable c1 = (Comparable) o1.getValues()[x]; + final Comparable c2 = (Comparable) o2.getValues()[x]; + return RelFieldCollation.compare(c1, c2, nullComparison); }; default: - return new Comparator<Row>() { - public int compare(Row o1, Row o2) { - final Comparable c1 = (Comparable) o1.getValues()[x]; - final Comparable c2 = (Comparable) o2.getValues()[x]; - return RelFieldCollation.compare(c2, c1, -nullComparison); - } + return (o1, o2) -> { + final Comparable c1 = (Comparable) o1.getValues()[x]; + final Comparable c2 = (Comparable) o2.getValues()[x]; + return RelFieldCollation.compare(c2, c1, -nullComparison); }; } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java b/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java index 9c8124e..54217c9 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java +++ b/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java @@ -20,7 +20,6 @@ import org.apache.calcite.DataContext; import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.Queryable; import org.apache.calcite.linq4j.function.Function1; -import org.apache.calcite.linq4j.function.Predicate1; import org.apache.calcite.plan.RelOptTable; import org.apache.calcite.plan.RelOptUtil; import org.apache.calcite.rel.core.TableScan; @@ -144,21 +143,18 @@ public class TableScanNode implements Node { } } final List<Field> fields = fieldBuilder.build(); - rowEnumerable = queryable.select( - new Function1<Object, Row>() { - public Row apply(Object o) { - final Object[] values = new Object[fields.size()]; - for (int i = 0; i < fields.size(); i++) { - Field field = fields.get(i); - try { - values[i] = field.get(o); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - return new Row(values); - } - }); + rowEnumerable = queryable.select(o -> { + final Object[] values = new Object[fields.size()]; + for (int i = 0; i < fields.size(); i++) { + Field field = fields.get(i); + try { + values[i] = field.get(o); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + return new Row(values); + }); } else { rowEnumerable = Schemas.queryable(root, Row.class, relOptTable.getQualifiedName()); @@ -270,14 +266,11 @@ public class TableScanNode implements Node { final Scalar condition = compiler.compile(ImmutableList.of(filter2), inputRowType); final Context context = compiler.createContext(); - enumerable = enumerable.where( - new Predicate1<Row>() { - @Override public boolean apply(Row row) { - context.values = row.getValues(); - Boolean b = (Boolean) condition.execute(context); - return b != null && b; - } - }); + enumerable = enumerable.where(row -> { + context.values = row.getValues(); + Boolean b = (Boolean) condition.execute(context); + return b != null && b; + }); } if (rejectedProjects != null) { enumerable = enumerable.select( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/UnionNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/UnionNode.java b/core/src/main/java/org/apache/calcite/interpreter/UnionNode.java index 0f6fe4f..98d5c52 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/UnionNode.java +++ b/core/src/main/java/org/apache/calcite/interpreter/UnionNode.java @@ -19,8 +19,8 @@ package org.apache.calcite.interpreter; import org.apache.calcite.rel.core.Union; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; +import java.util.HashSet; import java.util.Set; /** @@ -43,7 +43,7 @@ public class UnionNode implements Node { } public void run() throws InterruptedException { - final Set<Row> rows = rel.all ? null : Sets.<Row>newHashSet(); + final Set<Row> rows = rel.all ? null : new HashSet<>(); for (Source source : sources) { Row row; while ((row = source.receive()) != null) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/interpreter/ValuesNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/interpreter/ValuesNode.java b/core/src/main/java/org/apache/calcite/interpreter/ValuesNode.java index 1c6f255..83a510d 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/ValuesNode.java +++ b/core/src/main/java/org/apache/calcite/interpreter/ValuesNode.java @@ -21,8 +21,8 @@ import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.rex.RexNode; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.List; /** @@ -42,7 +42,7 @@ public class ValuesNode implements Node { private ImmutableList<Row> createRows(Compiler compiler, ImmutableList<ImmutableList<RexLiteral>> tuples) { - final List<RexNode> nodes = Lists.newArrayList(); + final List<RexNode> nodes = new ArrayList<>(); for (ImmutableList<RexLiteral> tuple : tuples) { nodes.addAll(tuple); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java index ec5d610..5db3421 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java @@ -44,7 +44,6 @@ import org.apache.calcite.linq4j.tree.Expressions; import org.apache.calcite.materialize.Lattice; import org.apache.calcite.materialize.MaterializationService; import org.apache.calcite.prepare.CalciteCatalogReader; -import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.type.DelegatingTypeSystem; import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.runtime.Hook; @@ -67,16 +66,17 @@ import org.apache.calcite.util.Holder; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import java.io.Serializable; import java.lang.reflect.Type; -import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.TimeZone; import java.util.concurrent.atomic.AtomicBoolean; @@ -135,7 +135,7 @@ abstract class CalciteConnectionImpl this.typeFactory = new JavaTypeFactoryImpl(typeSystem); } this.rootSchema = - Preconditions.checkNotNull(rootSchema != null + Objects.requireNonNull(rootSchema != null ? rootSchema : CalciteSchema.createRootSchema(true)); Preconditions.checkArgument(this.rootSchema.isRoot(), "must be root schema"); @@ -172,18 +172,15 @@ abstract class CalciteConnectionImpl @Override public <T> T unwrap(Class<T> iface) throws SQLException { if (iface == RelRunner.class) { - return iface.cast( - new RelRunner() { - public PreparedStatement prepare(RelNode rel) { - try { - return prepareStatement_(CalcitePrepare.Query.of(rel), - ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - getHoldability()); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - }); + return iface.cast((RelRunner) rel -> { + try { + return prepareStatement_(CalcitePrepare.Query.of(rel), + ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + getHoldability()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); } return super.unwrap(iface); } @@ -288,7 +285,7 @@ abstract class CalciteConnectionImpl public <T> Enumerable<T> enumerable(Meta.StatementHandle handle, CalcitePrepare.CalciteSignature<T> signature) throws SQLException { - Map<String, Object> map = Maps.newLinkedHashMap(); + Map<String, Object> map = new LinkedHashMap<>(); AvaticaStatement statement = lookupStatement(handle); final List<TypedValue> parameterValues = TROJAN.getParameterValues(statement); @@ -346,7 +343,7 @@ abstract class CalciteConnectionImpl /** Implementation of Server. */ private static class CalciteServerImpl implements CalciteServer { - final Map<Integer, CalciteServerStatement> statementMap = Maps.newHashMap(); + final Map<Integer, CalciteServerStatement> statementMap = new HashMap<>(); public void removeStatement(Meta.StatementHandle h) { statementMap.remove(h.id); @@ -455,7 +452,7 @@ abstract class CalciteConnectionImpl } final List<String> schemaPath = schemaName == null - ? ImmutableList.<String>of() + ? ImmutableList.of() : ImmutableList.of(schemaName); final SqlValidatorWithHints validator = new SqlAdvisorValidator(SqlStdOperatorTable.instance(), @@ -485,7 +482,7 @@ abstract class CalciteConnectionImpl private final CalciteSchema rootSchema; ContextImpl(CalciteConnectionImpl connection) { - this.connection = Preconditions.checkNotNull(connection); + this.connection = Objects.requireNonNull(connection); long now = System.currentTimeMillis(); SchemaVersion schemaVersion = new LongSchemaVersion(now); this.mutableRootSchema = connection.rootSchema; @@ -512,7 +509,7 @@ abstract class CalciteConnectionImpl throw new RuntimeException(e); } return schemaName == null - ? ImmutableList.<String>of() + ? ImmutableList.of() : ImmutableList.of(schemaName); } @@ -525,7 +522,7 @@ abstract class CalciteConnectionImpl } public DataContext getDataContext() { - return connection.createDataContext(ImmutableMap.<String, Object>of(), + return connection.createDataContext(ImmutableMap.of(), rootSchema); } @@ -577,7 +574,7 @@ abstract class CalciteConnectionImpl private final AtomicBoolean cancelFlag = new AtomicBoolean(); CalciteServerStatementImpl(CalciteConnectionImpl connection) { - this.connection = Preconditions.checkNotNull(connection); + this.connection = Objects.requireNonNull(connection); } public Context createPrepareContext() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java index 837aece..0e9457b 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java @@ -19,7 +19,6 @@ package org.apache.calcite.jdbc; import org.apache.calcite.DataContext; import org.apache.calcite.adapter.java.AbstractQueryableTable; import org.apache.calcite.adapter.java.JavaTypeFactory; -import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.AvaticaStatement; import org.apache.calcite.avatica.AvaticaUtils; import org.apache.calcite.avatica.ColumnMetaData; @@ -37,11 +36,9 @@ import org.apache.calcite.linq4j.Queryable; import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.linq4j.function.Functions; import org.apache.calcite.linq4j.function.Predicate1; -import org.apache.calcite.rel.RelCollation; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelDataTypeFactoryImpl; -import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.runtime.FlatLists; import org.apache.calcite.runtime.Hook; @@ -60,7 +57,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.primitives.Ints; @@ -75,6 +71,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; /** @@ -98,11 +95,7 @@ public class CalciteMetaImpl extends MetaImpl { return Functions.truePredicate1(); } final Pattern regex = likeToRegex(pattern); - return new Predicate1<T>() { - public boolean apply(T v1) { - return regex.matcher(v1.getName()).matches(); - } - }; + return v1 -> regex.matcher(v1.getName()).matches(); } static Predicate1<String> matcher(final Pat pattern) { @@ -110,11 +103,7 @@ public class CalciteMetaImpl extends MetaImpl { return Functions.truePredicate1(); } final Pattern regex = likeToRegex(pattern); - return new Predicate1<String>() { - public boolean apply(String v1) { - return regex.matcher(v1).matches(); - } - }; + return v1 -> regex.matcher(v1).matches(); } /** Converts a LIKE-style pattern (where '%' represents a wild-card, escaped @@ -190,7 +179,7 @@ public class CalciteMetaImpl extends MetaImpl { } //noinspection unchecked final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable; - return createResultSet(Collections.<String, Object>emptyMap(), + return createResultSet(Collections.emptyMap(), columns, CursorFactory.record(clazz, fields, fieldNames), new Frame(0, true, iterable)); } @@ -199,7 +188,7 @@ public class CalciteMetaImpl extends MetaImpl { createEmptyResultSet(final Class<E> clazz) { final List<ColumnMetaData> columns = fieldMetaData(clazz).columns; final CursorFactory cursorFactory = CursorFactory.deduce(columns, clazz); - return createResultSet(Collections.<String, Object>emptyMap(), columns, + return createResultSet(Collections.emptyMap(), columns, cursorFactory, Frame.EMPTY); } @@ -211,8 +200,8 @@ public class CalciteMetaImpl extends MetaImpl { final AvaticaStatement statement = connection.createStatement(); final CalcitePrepare.CalciteSignature<Object> signature = new CalcitePrepare.CalciteSignature<Object>("", - ImmutableList.<AvaticaParameter>of(), internalParameters, null, - columns, cursorFactory, null, ImmutableList.<RelCollation>of(), -1, + ImmutableList.of(), internalParameters, null, + columns, cursorFactory, null, ImmutableList.of(), -1, null, Meta.StatementType.SELECT) { @Override public Enumerable<Object> enumerable( DataContext dataContext) { @@ -268,21 +257,12 @@ public class CalciteMetaImpl extends MetaImpl { if (typeList == null) { typeFilter = Functions.truePredicate1(); } else { - typeFilter = new Predicate1<MetaTable>() { - public boolean apply(MetaTable v1) { - return typeList.contains(v1.tableType); - } - }; + typeFilter = v1 -> typeList.contains(v1.tableType); } final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern); return createResultSet(schemas(catalog) .where(schemaMatcher) - .selectMany( - new Function1<MetaSchema, Enumerable<MetaTable>>() { - public Enumerable<MetaTable> apply(MetaSchema schema) { - return tables(schema, matcher(tableNamePattern)); - } - }) + .selectMany(schema -> tables(schema, matcher(tableNamePattern))) .where(typeFilter), MetaTable.class, "TABLE_CAT", @@ -331,18 +311,8 @@ public class CalciteMetaImpl extends MetaImpl { namedMatcher(columnNamePattern); return createResultSet(schemas(catalog) .where(schemaMatcher) - .selectMany( - new Function1<MetaSchema, Enumerable<MetaTable>>() { - public Enumerable<MetaTable> apply(MetaSchema schema) { - return tables(schema, tableNameMatcher); - } - }) - .selectMany( - new Function1<MetaTable, Enumerable<MetaColumn>>() { - public Enumerable<MetaColumn> apply(MetaTable schema) { - return columns(schema); - } - }) + .selectMany(schema -> tables(schema, tableNameMatcher)) + .selectMany(this::columns) .where(columnMatcher), MetaColumn.class, "TABLE_CAT", @@ -391,75 +361,49 @@ public class CalciteMetaImpl extends MetaImpl { Enumerable<MetaSchema> schemas(final String catalog) { return Linq4j.asEnumerable( getConnection().rootSchema.getSubSchemaMap().values()) - .select( - new Function1<CalciteSchema, MetaSchema>() { - public MetaSchema apply(CalciteSchema calciteSchema) { - return new CalciteMetaSchema( - calciteSchema, - catalog, - calciteSchema.getName()); - } - }) - .orderBy( - new Function1<MetaSchema, Comparable>() { - public Comparable apply(MetaSchema metaSchema) { - return (Comparable) FlatLists.of( - Util.first(metaSchema.tableCatalog, ""), - metaSchema.tableSchem); - } - }); + .select((Function1<CalciteSchema, MetaSchema>) calciteSchema -> + new CalciteMetaSchema(calciteSchema, catalog, + calciteSchema.getName())) + .orderBy((Function1<MetaSchema, Comparable>) metaSchema -> + (Comparable) FlatLists.of(Util.first(metaSchema.tableCatalog, ""), + metaSchema.tableSchem)); } Enumerable<MetaTable> tables(String catalog) { return schemas(catalog) - .selectMany( - new Function1<MetaSchema, Enumerable<MetaTable>>() { - public Enumerable<MetaTable> apply(MetaSchema schema) { - return tables(schema, Functions.<String>truePredicate1()); - } - }); + .selectMany(schema -> + tables(schema, Functions.<String>truePredicate1())); } Enumerable<MetaTable> tables(final MetaSchema schema_) { final CalciteMetaSchema schema = (CalciteMetaSchema) schema_; return Linq4j.asEnumerable(schema.calciteSchema.getTableNames()) - .select( - new Function1<String, MetaTable>() { - public MetaTable apply(String name) { - final Table table = - schema.calciteSchema.getTable(name, true).getTable(); - return new CalciteMetaTable(table, - schema.tableCatalog, - schema.tableSchem, - name); - } - }) + .select((Function1<String, MetaTable>) name -> { + final Table table = + schema.calciteSchema.getTable(name, true).getTable(); + return new CalciteMetaTable(table, + schema.tableCatalog, + schema.tableSchem, + name); + }) .concat( Linq4j.asEnumerable( schema.calciteSchema.getTablesBasedOnNullaryFunctions() .entrySet()) - .select( - new Function1<Map.Entry<String, Table>, MetaTable>() { - public MetaTable apply(Map.Entry<String, Table> pair) { - final Table table = pair.getValue(); - return new CalciteMetaTable(table, - schema.tableCatalog, - schema.tableSchem, - pair.getKey()); - } - })); + .select(pair -> { + final Table table = pair.getValue(); + return new CalciteMetaTable(table, + schema.tableCatalog, + schema.tableSchem, + pair.getKey()); + })); } Enumerable<MetaTable> tables( final MetaSchema schema, final Predicate1<String> matcher) { return tables(schema) - .where( - new Predicate1<MetaTable>() { - public boolean apply(MetaTable v1) { - return matcher.apply(v1.getName()); - } - }); + .where(v1 -> matcher.apply(v1.getName())); } private ImmutableList<MetaTypeInfo> getAllDefaultType() { @@ -499,35 +443,32 @@ public class CalciteMetaImpl extends MetaImpl { final RelDataType rowType = table.calciteTable.getRowType(getConnection().typeFactory); return Linq4j.asEnumerable(rowType.getFieldList()) - .select( - new Function1<RelDataTypeField, MetaColumn>() { - public MetaColumn apply(RelDataTypeField field) { - final int precision = - field.getType().getSqlTypeName().allowsPrec() - && !(field.getType() - instanceof RelDataTypeFactoryImpl.JavaType) - ? field.getType().getPrecision() - : -1; - return new MetaColumn( - table.tableCat, - table.tableSchem, - table.tableName, - field.getName(), - field.getType().getSqlTypeName().getJdbcOrdinal(), - field.getType().getFullTypeString(), - precision, - field.getType().getSqlTypeName().allowsScale() - ? field.getType().getScale() - : null, - 10, - field.getType().isNullable() - ? DatabaseMetaData.columnNullable - : DatabaseMetaData.columnNoNulls, - precision, - field.getIndex() + 1, - field.getType().isNullable() ? "YES" : "NO"); - } - }); + .select(field -> { + final int precision = + field.getType().getSqlTypeName().allowsPrec() + && !(field.getType() + instanceof RelDataTypeFactoryImpl.JavaType) + ? field.getType().getPrecision() + : -1; + return new MetaColumn( + table.tableCat, + table.tableSchem, + table.tableName, + field.getName(), + field.getType().getSqlTypeName().getJdbcOrdinal(), + field.getType().getFullTypeString(), + precision, + field.getType().getSqlTypeName().allowsScale() + ? field.getType().getScale() + : null, + 10, + field.getType().isNullable() + ? DatabaseMetaData.columnNullable + : DatabaseMetaData.columnNoNulls, + precision, + field.getIndex() + 1, + field.getType().isNullable() ? "YES" : "NO"); + }); } public MetaResultSet getSchemas(ConnectionHandle ch, String catalog, Pat schemaPattern) { @@ -745,7 +686,7 @@ public class CalciteMetaImpl extends MetaImpl { public void execute() throws SQLException { if (signature.statementType.canUpdate()) { final Iterable<Object> iterable = - _createIterable(h, signature, ImmutableList.<TypedValue>of(), + _createIterable(h, signature, ImmutableList.of(), null); final Iterator<Object> iterator = iterable.iterator(); updateCount = ((Number) iterator.next()).longValue(); @@ -763,7 +704,7 @@ public class CalciteMetaImpl extends MetaImpl { @VisibleForTesting public static DataContext createDataContext(CalciteConnection connection) { return ((CalciteConnectionImpl) connection) - .createDataContext(ImmutableMap.<String, Object>of(), + .createDataContext(ImmutableMap.of(), CalciteSchema.from(connection.getRootSchema())); } @@ -796,7 +737,7 @@ public class CalciteMetaImpl extends MetaImpl { String tableSchem, String tableName) { super(tableCat, tableSchem, tableName, calciteTable.getJdbcTableType().jdbcName); - this.calciteTable = Preconditions.checkNotNull(calciteTable); + this.calciteTable = Objects.requireNonNull(calciteTable); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java b/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java index e0be075..f33d066 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java @@ -63,18 +63,9 @@ import java.util.Map; * API for a service that prepares statements for execution. */ public interface CalcitePrepare { - Function0<CalcitePrepare> DEFAULT_FACTORY = - new Function0<CalcitePrepare>() { - public CalcitePrepare apply() { - return new CalcitePrepareImpl(); - } - }; + Function0<CalcitePrepare> DEFAULT_FACTORY = CalcitePrepareImpl::new; ThreadLocal<Deque<Context>> THREAD_CONTEXT_STACK = - new ThreadLocal<Deque<Context>>() { - @Override protected Deque<Context> initialValue() { - return new ArrayDeque<>(); - } - }; + ThreadLocal.withInitial(ArrayDeque::new); ParseResult parse(Context context, String sql); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java index a8e2ecf..62e2249 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java @@ -25,7 +25,6 @@ import org.apache.calcite.avatica.Meta; import org.apache.calcite.avatica.util.Cursor; import org.apache.calcite.linq4j.Enumerator; import org.apache.calcite.linq4j.Linq4j; -import org.apache.calcite.rel.RelCollation; import org.apache.calcite.runtime.ArrayEnumeratorCursor; import org.apache.calcite.runtime.ObjectEnumeratorCursor; @@ -57,9 +56,7 @@ public class CalciteResultSet extends AvaticaResultSet { final boolean autoTemp = connection.config().autoTemp(); Handler.ResultSink resultSink = null; if (autoTemp) { - resultSink = new Handler.ResultSink() { - public void toBeCompleted() { - } + resultSink = () -> { }; } connection.getDriver().handler.onStatementExecute(statement, resultSink); @@ -83,7 +80,7 @@ public class CalciteResultSet extends AvaticaResultSet { new CalcitePrepare.CalciteSignature<>(signature.sql, signature.parameters, signature.internalParameters, signature.rowType, columnMetaDataList, Meta.CursorFactory.ARRAY, - signature.rootSchema, ImmutableList.<RelCollation>of(), -1, null, + signature.rootSchema, ImmutableList.of(), -1, null, statement.getStatementType()); ResultSetMetaData subResultSetMetaData = new AvaticaResultSetMetaData(statement, null, newSignature); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java index badf781..2cba4be 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java @@ -47,6 +47,7 @@ import java.util.Locale; import java.util.Map; import java.util.NavigableMap; import java.util.NavigableSet; +import java.util.Objects; import java.util.Set; /** @@ -82,17 +83,17 @@ public abstract class CalciteSchema { if (tableMap == null) { this.tableMap = new NameMap<>(); } else { - this.tableMap = Preconditions.checkNotNull(tableMap); + this.tableMap = Objects.requireNonNull(tableMap); } if (latticeMap == null) { this.latticeMap = new NameMap<>(); } else { - this.latticeMap = Preconditions.checkNotNull(latticeMap); + this.latticeMap = Objects.requireNonNull(latticeMap); } if (subSchemaMap == null) { this.subSchemaMap = new NameMap<>(); } else { - this.subSchemaMap = Preconditions.checkNotNull(subSchemaMap); + this.subSchemaMap = Objects.requireNonNull(subSchemaMap); } if (functionMap == null) { this.functionMap = new NameMultimap<>(); @@ -101,14 +102,14 @@ public abstract class CalciteSchema { } else { // If you specify functionMap, you must also specify functionNames and // nullaryFunctionMap. - this.functionMap = Preconditions.checkNotNull(functionMap); - this.functionNames = Preconditions.checkNotNull(functionNames); - this.nullaryFunctionMap = Preconditions.checkNotNull(nullaryFunctionMap); + this.functionMap = Objects.requireNonNull(functionMap); + this.functionNames = Objects.requireNonNull(functionNames); + this.nullaryFunctionMap = Objects.requireNonNull(nullaryFunctionMap); } if (typeMap == null) { this.typeMap = new NameMap<>(); } else { - this.typeMap = Preconditions.checkNotNull(typeMap); + this.typeMap = Objects.requireNonNull(typeMap); } this.path = path; } @@ -172,7 +173,7 @@ public abstract class CalciteSchema { /** Creates a TableEntryImpl with no SQLs. */ protected TableEntryImpl tableEntry(String name, Table table) { - return new TableEntryImpl(this, name, table, ImmutableList.<String>of()); + return new TableEntryImpl(this, name, table, ImmutableList.of()); } /** Creates a TableEntryImpl with no SQLs. */ @@ -182,7 +183,7 @@ public abstract class CalciteSchema { /** Defines a table within this schema. */ public TableEntry add(String tableName, Table table) { - return add(tableName, table, ImmutableList.<String>of()); + return add(tableName, table, ImmutableList.of()); } /** Defines a table within this schema. */ @@ -552,8 +553,8 @@ public abstract class CalciteSchema { public final String name; public Entry(CalciteSchema schema, String name) { - this.schema = Preconditions.checkNotNull(schema); - this.name = Preconditions.checkNotNull(name); + this.schema = Objects.requireNonNull(schema); + this.name = Objects.requireNonNull(name); } /** Returns this object's path. For example ["hr", "emps"]. */ @@ -569,7 +570,7 @@ public abstract class CalciteSchema { public TableEntry(CalciteSchema schema, String name, ImmutableList<String> sqls) { super(schema, name); - this.sqls = Preconditions.checkNotNull(sqls); + this.sqls = Objects.requireNonNull(sqls); } public abstract Table getTable(); @@ -730,7 +731,7 @@ public abstract class CalciteSchema { ImmutableList<String> sqls) { super(schema, name, sqls); assert table != null; - this.table = Preconditions.checkNotNull(table); + this.table = Objects.requireNonNull(table); } public Table getTable() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java b/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java index 831d696..7ef3439 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java +++ b/core/src/main/java/org/apache/calcite/jdbc/JavaRecordType.java @@ -19,8 +19,6 @@ package org.apache.calcite.jdbc; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rel.type.RelRecordType; -import com.google.common.base.Preconditions; - import java.util.List; import java.util.Objects; @@ -36,7 +34,7 @@ public class JavaRecordType extends RelRecordType { public JavaRecordType(List<RelDataTypeField> fields, Class clazz) { super(fields); - this.clazz = Preconditions.checkNotNull(clazz); + this.clazz = Objects.requireNonNull(clazz); } @Override public boolean equals(Object obj) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java index 8999f44..59805fe 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java @@ -37,8 +37,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import java.lang.reflect.Field; @@ -50,6 +48,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Implementation of {@link JavaTypeFactory}. @@ -245,11 +244,7 @@ public class JavaTypeFactoryImpl if (type instanceof RelRecordType) { return typeFactory.createStructType( Lists.transform(type.getFieldList(), - new Function<RelDataTypeField, RelDataType>() { - public RelDataType apply(RelDataTypeField a0) { - return toSql(typeFactory, a0.getType()); - } - }), + field -> toSql(typeFactory, field.getType())), type.getFieldNames()); } if (type instanceof JavaType) { @@ -367,9 +362,9 @@ public class JavaTypeFactoryImpl Type type, boolean nullable, int modifiers) { - this.syntheticType = Preconditions.checkNotNull(syntheticType); - this.name = Preconditions.checkNotNull(name); - this.type = Preconditions.checkNotNull(type); + this.syntheticType = Objects.requireNonNull(syntheticType); + this.name = Objects.requireNonNull(name); + this.type = Objects.requireNonNull(type); this.nullable = nullable; this.modifiers = modifiers; assert !(nullable && Primitive.is(type)) http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java b/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java index 5fb2e89..c11ccea 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java +++ b/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java @@ -16,9 +16,7 @@ */ package org.apache.calcite.jdbc; -import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.Enumerator; -import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.schema.Schema; import org.apache.calcite.schema.Table; import org.apache.calcite.schema.impl.AbstractSchema; @@ -34,7 +32,7 @@ import static org.apache.calcite.jdbc.CalciteMetaImpl.MetaTable; /** Schema that contains metadata tables such as "TABLES" and "COLUMNS". */ class MetadataSchema extends AbstractSchema { private static final Map<String, Table> TABLE_MAP = - ImmutableMap.<String, Table>of( + ImmutableMap.of( "COLUMNS", new CalciteMetaImpl.MetadataTable<MetaColumn>(MetaColumn.class) { public Enumerator<MetaColumn> enumerator( @@ -45,12 +43,8 @@ class MetadataSchema extends AbstractSchema { } catch (SQLException e) { throw new RuntimeException(e); } - return meta.tables(catalog).selectMany( - new Function1<MetaTable, Enumerable<MetaColumn>>() { - public Enumerable<MetaColumn> apply(MetaTable table) { - return meta.columns(table); - } - }).enumerator(); + return meta.tables(catalog) + .selectMany(meta::columns).enumerator(); } }, "TABLES", http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java index 21c6fed..fb102d7 100644 --- a/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java +++ b/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java @@ -27,7 +27,6 @@ import com.google.common.util.concurrent.UncheckedExecutionException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; -import javax.annotation.Nonnull; /** * Implementation of {@link LatticeStatisticProvider} that caches single-column @@ -41,13 +40,8 @@ class CachingLatticeStatisticProvider implements LatticeStatisticProvider { CachingLatticeStatisticProvider(final Lattice lattice, final LatticeStatisticProvider provider) { this.lattice = lattice; - cache = CacheBuilder.<Lattice.Column>newBuilder() - .build( - new CacheLoader<Lattice.Column, Double>() { - public Double load(@Nonnull Lattice.Column key) throws Exception { - return provider.cardinality(ImmutableList.of(key)); - } - }); + cache = CacheBuilder.<Lattice.Column>newBuilder().build( + CacheLoader.from(key -> provider.cardinality(ImmutableList.of(key)))); } public double cardinality(List<Lattice.Column> columns) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/Lattice.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/Lattice.java b/core/src/main/java/org/apache/calcite/materialize/Lattice.java index 3828416..0e09f63 100644 --- a/core/src/main/java/org/apache/calcite/materialize/Lattice.java +++ b/core/src/main/java/org/apache/calcite/materialize/Lattice.java @@ -52,16 +52,15 @@ import org.apache.calcite.util.graph.DirectedGraph; import org.apache.calcite.util.graph.TopologicalOrderIterator; import org.apache.calcite.util.mapping.IntPair; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Ordering; -import com.google.common.collect.Sets; import java.util.ArrayList; +import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -72,20 +71,6 @@ import java.util.Set; * recognized and recommended. */ public class Lattice { - private static final Function<Column, String> GET_ALIAS = - new Function<Column, String>() { - public String apply(Column input) { - return input.alias; - } - }; - - private static final Function<Column, Integer> GET_ORDINAL = - new Function<Column, Integer>() { - public Integer apply(Column input) { - return input.ordinal; - } - }; - public final CalciteSchema rootSchema; public final ImmutableList<Node> nodes; public final ImmutableList<Column> columns; @@ -98,33 +83,19 @@ public class Lattice { public final ImmutableList<String> uniqueColumnNames; public final LatticeStatisticProvider statisticProvider; - private final Function<Integer, Column> toColumnFunction = - new Function<Integer, Column>() { - public Column apply(Integer input) { - return columns.get(input); - } - }; - private final Function<AggregateCall, Measure> toMeasureFunction = - new Function<AggregateCall, Measure>() { - public Measure apply(AggregateCall input) { - return new Measure(input.getAggregation(), - Lists.transform(input.getArgList(), toColumnFunction)); - } - }; - private Lattice(CalciteSchema rootSchema, ImmutableList<Node> nodes, boolean auto, boolean algorithm, long algorithmMaxMillis, LatticeStatisticProvider.Factory statisticProviderFactory, Double rowCountEstimate, ImmutableList<Column> columns, ImmutableList<Measure> defaultMeasures, ImmutableList<Tile> tiles) { this.rootSchema = rootSchema; - this.nodes = Preconditions.checkNotNull(nodes); - this.columns = Preconditions.checkNotNull(columns); + this.nodes = Objects.requireNonNull(nodes); + this.columns = Objects.requireNonNull(columns); this.auto = auto; this.algorithm = algorithm; this.algorithmMaxMillis = algorithmMaxMillis; - this.defaultMeasures = Preconditions.checkNotNull(defaultMeasures); - this.tiles = Preconditions.checkNotNull(tiles); + this.defaultMeasures = Objects.requireNonNull(defaultMeasures); + this.tiles = Objects.requireNonNull(tiles); // Validate that nodes form a tree; each node except the first references // a predecessor. @@ -137,13 +108,14 @@ public class Lattice { } } - List<String> nameList = Lists.newArrayList(); + List<String> nameList = new ArrayList<>(); for (Column column : columns) { nameList.add(column.alias); } uniqueColumnNames = ImmutableList.copyOf( - SqlValidatorUtil.uniquify(Lists.transform(columns, GET_ALIAS), true)); + SqlValidatorUtil.uniquify( + Lists.transform(columns, input -> input.alias), true)); if (rowCountEstimate == null) { // We could improve this when we fix // [CALCITE-429] Add statistics SPI for lattice optimization algorithm @@ -152,7 +124,7 @@ public class Lattice { Preconditions.checkArgument(rowCountEstimate > 0d); this.rowCountEstimate = rowCountEstimate; this.statisticProvider = - Preconditions.checkNotNull(statisticProviderFactory.apply(this)); + Objects.requireNonNull(statisticProviderFactory.apply(this)); } /** Creates a Lattice. */ @@ -274,7 +246,7 @@ public class Lattice { final StringBuilder buf = new StringBuilder("SELECT "); final StringBuilder groupBuf = new StringBuilder("\nGROUP BY "); int k = 0; - final Set<String> columnNames = Sets.newHashSet(); + final Set<String> columnNames = new HashSet<>(); if (groupSet != null) { for (int i : groupSet) { if (k++ > 0) { @@ -359,7 +331,7 @@ public class Lattice { * attributes given in {@code groupSet}. */ public String countSql(ImmutableBitSet groupSet) { return "select count(*) as c from (" - + sql(groupSet, ImmutableList.<Measure>of()) + + sql(groupSet, ImmutableList.of()) + ")"; } @@ -373,7 +345,7 @@ public class Lattice { } public StarTable createStarTable() { - final List<Table> tables = Lists.newArrayList(); + final List<Table> tables = new ArrayList<>(); for (Node node : nodes) { tables.add(node.scan.getTable().unwrap(Table.class)); } @@ -385,7 +357,9 @@ public class Lattice { } public List<Measure> toMeasures(List<AggregateCall> aggCallList) { - return Lists.transform(aggCallList, toMeasureFunction); + return Lists.transform(aggCallList, + call -> new Measure(call.getAggregation(), + Lists.transform(call.getArgList(), columns::get))); } public Iterable<? extends Tile> computeTiles() { @@ -454,7 +428,7 @@ public class Lattice { public Node(TableScan scan, Node parent, List<IntPair> link, int startCol, int endCol, String alias) { - this.scan = Preconditions.checkNotNull(scan); + this.scan = Objects.requireNonNull(scan); this.parent = parent; this.link = link == null ? null : ImmutableList.copyOf(link); assert (parent == null) == (link == null); @@ -469,13 +443,9 @@ public class Lattice { /** Edge in the temporary graph. */ private static class Edge extends DefaultEdge { public static final DirectedGraph.EdgeFactory<RelNode, Edge> FACTORY = - new DirectedGraph.EdgeFactory<RelNode, Edge>() { - public Edge createEdge(RelNode source, RelNode target) { - return new Edge(source, target); - } - }; + Edge::new; - final List<IntPair> pairs = Lists.newArrayList(); + final List<IntPair> pairs = new ArrayList<>(); Edge(RelNode source, RelNode target) { super(source, target); @@ -496,7 +466,7 @@ public class Lattice { public final ImmutableList<Column> args; public Measure(SqlAggFunction agg, Iterable<Column> args) { - this.agg = Preconditions.checkNotNull(agg); + this.agg = Objects.requireNonNull(agg); this.args = ImmutableList.copyOf(args); } @@ -534,7 +504,7 @@ public class Lattice { /** Returns a list of argument ordinals. */ public List<Integer> argOrdinals() { - return Lists.transform(args, GET_ORDINAL); + return Lists.transform(args, input -> input.ordinal); } private static int compare(List<Column> list0, List<Column> list1) { @@ -562,9 +532,9 @@ public class Lattice { private Column(int ordinal, String table, String column, String alias) { this.ordinal = ordinal; - this.table = Preconditions.checkNotNull(table); - this.column = Preconditions.checkNotNull(column); - this.alias = Preconditions.checkNotNull(alias); + this.table = Objects.requireNonNull(table); + this.column = Objects.requireNonNull(column); + this.alias = Objects.requireNonNull(alias); } /** Converts a list of columns to a bit set of their ordinals. */ @@ -601,7 +571,7 @@ public class Lattice { /** Lattice builder. */ public static class Builder { - private final List<Node> nodes = Lists.newArrayList(); + private final List<Node> nodes = new ArrayList<>(); private final ImmutableList<Column> columns; private final ImmutableListMultimap<String, Column> columnsByAlias; private final ImmutableList.Builder<Measure> defaultMeasureListBuilder = @@ -616,19 +586,19 @@ public class Lattice { private String statisticProvider; public Builder(CalciteSchema schema, String sql) { - this.rootSchema = Preconditions.checkNotNull(schema.root()); + this.rootSchema = Objects.requireNonNull(schema.root()); Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); CalcitePrepare.ConvertResult parsed = Schemas.convert(MaterializedViewTable.MATERIALIZATION_CONNECTION, schema, schema.path(null), sql); // Walk the join tree. - List<RelNode> relNodes = Lists.newArrayList(); - List<int[][]> tempLinks = Lists.newArrayList(); + List<RelNode> relNodes = new ArrayList<>(); + List<int[][]> tempLinks = new ArrayList<>(); populate(relNodes, tempLinks, parsed.root.rel); // Get aliases. - List<String> aliases = Lists.newArrayList(); + List<String> aliases = new ArrayList<>(); populateAliases(((SqlSelect) parsed.sqlNode).getFrom(), aliases, null); // Build a graph. @@ -650,7 +620,7 @@ public class Lattice { // Convert the graph into a tree of nodes, each connected to a parent and // with a join condition to that parent. Node previous = null; - final Map<RelNode, Node> map = Maps.newIdentityHashMap(); + final Map<RelNode, Node> map = new IdentityHashMap<>(); int previousColumn = 0; for (RelNode relNode : TopologicalOrderIterator.of(graph)) { final List<Edge> edges = graph.getInwardEdges(relNode); @@ -857,8 +827,8 @@ public class Lattice { public Tile(ImmutableList<Measure> measures, ImmutableList<Column> dimensions) { - this.measures = Preconditions.checkNotNull(measures); - this.dimensions = Preconditions.checkNotNull(dimensions); + this.measures = Objects.requireNonNull(measures); + this.dimensions = Objects.requireNonNull(dimensions); assert Ordering.natural().isStrictlyOrdered(dimensions); assert Ordering.natural().isStrictlyOrdered(measures); bitSet = Column.toBitSet(dimensions); @@ -875,8 +845,8 @@ public class Lattice { /** Tile builder. */ public static class TileBuilder { - private final List<Measure> measureBuilder = Lists.newArrayList(); - private final List<Column> dimensionListBuilder = Lists.newArrayList(); + private final List<Measure> measureBuilder = new ArrayList<>(); + private final List<Column> dimensionListBuilder = new ArrayList<>(); public Tile build() { return new Tile( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/LatticeStatisticProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/LatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/LatticeStatisticProvider.java index d16e903..d191f8b 100644 --- a/core/src/main/java/org/apache/calcite/materialize/LatticeStatisticProvider.java +++ b/core/src/main/java/org/apache/calcite/materialize/LatticeStatisticProvider.java @@ -16,9 +16,8 @@ */ package org.apache.calcite.materialize; -import com.google.common.base.Function; - import java.util.List; +import java.util.function.Function; /** * Estimates row counts for a lattice and its attributes. http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java index 4564478..f01b9af 100644 --- a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java +++ b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java @@ -21,9 +21,9 @@ import org.apache.calcite.rel.type.RelDataType; import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -35,11 +35,11 @@ class MaterializationActor { // Not an actor yet -- TODO make members private and add request/response // queues - final Map<MaterializationKey, Materialization> keyMap = Maps.newHashMap(); + final Map<MaterializationKey, Materialization> keyMap = new HashMap<>(); - final Map<QueryKey, MaterializationKey> keyBySql = Maps.newHashMap(); + final Map<QueryKey, MaterializationKey> keyBySql = new HashMap<>(); - final Map<TileKey, MaterializationKey> keyByTile = Maps.newHashMap(); + final Map<TileKey, MaterializationKey> keyByTile = new HashMap<>(); /** Tiles grouped by dimensionality. We use a * {@link TileKey} with no measures to represent a @@ -75,7 +75,7 @@ class MaterializationActor { RelDataType rowType, List<String> viewSchemaPath) { this.key = key; - this.rootSchema = Preconditions.checkNotNull(rootSchema); + this.rootSchema = Objects.requireNonNull(rootSchema); Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); this.materializedTable = materializedTable; // may be null this.sql = sql; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java b/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java index 39a077f..e013d08 100644 --- a/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java +++ b/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java @@ -18,7 +18,6 @@ package org.apache.calcite.materialize; import org.apache.calcite.DataContext; import org.apache.calcite.adapter.clone.CloneSchema; -import org.apache.calcite.avatica.ColumnMetaData; import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.jdbc.CalciteConnection; import org.apache.calcite.jdbc.CalciteMetaImpl; @@ -38,11 +37,9 @@ 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 com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.lang.reflect.Type; import java.util.ArrayList; @@ -52,6 +49,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.PriorityQueue; +import java.util.Set; /** * Manages the collection of materialized tables known to the system, @@ -63,27 +61,20 @@ public class MaterializationService { /** For testing. */ private static final ThreadLocal<MaterializationService> THREAD_INSTANCE = - new ThreadLocal<MaterializationService>() { - @Override protected MaterializationService initialValue() { - return new MaterializationService(); - } - }; + ThreadLocal.withInitial(MaterializationService::new); private static final Comparator<Pair<CalciteSchema.TableEntry, TileKey>> C = - new Comparator<Pair<CalciteSchema.TableEntry, TileKey>>() { - public int compare(Pair<CalciteSchema.TableEntry, TileKey> o0, - Pair<CalciteSchema.TableEntry, TileKey> o1) { - // We prefer rolling up from the table with the fewest rows. - final Table t0 = o0.left.getTable(); - final Table t1 = o1.left.getTable(); - int c = Double.compare(t0.getStatistic().getRowCount(), - t1.getStatistic().getRowCount()); - if (c != 0) { - return c; - } - // Tie-break based on table name. - return o0.left.name.compareTo(o1.left.name); + (o0, o1) -> { + // We prefer rolling up from the table with the fewest rows. + final Table t0 = o0.left.getTable(); + final Table t1 = o1.left.getTable(); + int c = Double.compare(t0.getStatistic().getRowCount(), + t1.getStatistic().getRowCount()); + if (c != 0) { + return c; } + // Tie-break based on table name. + return o0.left.name.compareTo(o1.left.name); }; private final MaterializationActor actor = new MaterializationActor(); @@ -207,7 +198,7 @@ public class MaterializationService { // Step 2. Look for a match of the tile with the same dimensionality and an // acceptable list of measures. final TileKey tileKey0 = - new TileKey(lattice, groupSet, ImmutableList.<Lattice.Measure>of()); + new TileKey(lattice, groupSet, ImmutableList.of()); for (TileKey tileKey1 : actor.tilesByDimensionality.get(tileKey0)) { assert tileKey1.dimensions.equals(groupSet); if (allSatisfiable(measureList, tileKey1)) { @@ -267,8 +258,8 @@ public class MaterializationService { // whether they were current, create a wider tile that contains their // measures plus the currently requested measures. Then we can obsolete all // other tiles. - final List<TileKey> obsolete = Lists.newArrayList(); - final LinkedHashSet<Lattice.Measure> measureSet = Sets.newLinkedHashSet(); + final List<TileKey> obsolete = new ArrayList<>(); + final Set<Lattice.Measure> measureSet = new LinkedHashSet<>(); for (TileKey tileKey1 : actor.tilesByDimensionality.get(tileKey0)) { measureSet.addAll(tileKey1.measures); obsolete.add(tileKey1); @@ -380,12 +371,7 @@ public class MaterializationService { return CloneSchema.createCloneTable(connection.getTypeFactory(), RelDataTypeImpl.proto(calciteSignature.rowType), calciteSignature.getCollationList(), - Lists.transform(calciteSignature.columns, - new Function<ColumnMetaData, ColumnMetaData.Rep>() { - public ColumnMetaData.Rep apply(ColumnMetaData column) { - return column.type.rep; - } - }), + Lists.transform(calciteSignature.columns, column -> column.type.rep), new AbstractQueryable<Object>() { public Enumerator<Object> enumerator() { final DataContext dataContext = http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java index 39e0b29..3653b46 100644 --- a/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java +++ b/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java @@ -17,7 +17,6 @@ package org.apache.calcite.materialize; import org.apache.calcite.linq4j.Enumerable; -import org.apache.calcite.linq4j.function.Function1; import org.apache.calcite.profile.Profiler; import org.apache.calcite.profile.ProfilerImpl; import org.apache.calcite.rel.metadata.NullSentinel; @@ -25,73 +24,58 @@ import org.apache.calcite.schema.ScannableTable; import org.apache.calcite.schema.Table; import org.apache.calcite.util.ImmutableBitSet; -import com.google.common.base.Preconditions; -import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.function.Supplier; /** * Implementation of {@link LatticeStatisticProvider} that uses a * {@link org.apache.calcite.profile.Profiler}. */ class ProfilerLatticeStatisticProvider implements LatticeStatisticProvider { - static final Factory FACTORY = - new Factory() { - public LatticeStatisticProvider apply(Lattice lattice) { - return new ProfilerLatticeStatisticProvider(lattice); - } - }; + static final Factory FACTORY = ProfilerLatticeStatisticProvider::new; - /** Converts an array of values to a list of {@link Comparable} values, - * converting null values to sentinels. */ - private static final Function1<Object[], List<Comparable>> TO_LIST = - new Function1<Object[], List<Comparable>>() { - public List<Comparable> apply(Object[] values) { - for (int i = 0; i < values.length; i++) { - if (values[i] == null) { - values[i] = NullSentinel.INSTANCE; - } - } - //noinspection unchecked - return (List) Arrays.asList(values); - } - }; - - private final Lattice lattice; - private final Supplier<Profiler.Profile> profile = - Suppliers.memoize(new Supplier<Profiler.Profile>() { - public Profiler.Profile get() { - final ProfilerImpl profiler = - ProfilerImpl.builder() - .withPassSize(200) - .withMinimumSurprise(0.3D) - .build(); - final List<Profiler.Column> columns = new ArrayList<>(); - for (Lattice.Column column : lattice.columns) { - columns.add(new Profiler.Column(column.ordinal, column.alias)); - } - final String sql = - lattice.sql(ImmutableBitSet.range(lattice.columns.size()), - false, ImmutableList.<Lattice.Measure>of()); - final Table table = - new MaterializationService.DefaultTableFactory() - .createTable(lattice.rootSchema, sql, - ImmutableList.<String>of()); - final ImmutableList<ImmutableBitSet> initialGroups = - ImmutableList.of(); - final Enumerable<List<Comparable>> rows = - ((ScannableTable) table).scan(null).select(TO_LIST); - return profiler.profile(rows, columns, initialGroups); - } - }); + private final Supplier<Profiler.Profile> profile; /** Creates a ProfilerLatticeStatisticProvider. */ private ProfilerLatticeStatisticProvider(Lattice lattice) { - this.lattice = Preconditions.checkNotNull(lattice); + Objects.requireNonNull(lattice); + this.profile = Suppliers.memoize(() -> { + final ProfilerImpl profiler = + ProfilerImpl.builder() + .withPassSize(200) + .withMinimumSurprise(0.3D) + .build(); + final List<Profiler.Column> columns = new ArrayList<>(); + for (Lattice.Column column : lattice.columns) { + columns.add(new Profiler.Column(column.ordinal, column.alias)); + } + final String sql = + lattice.sql(ImmutableBitSet.range(lattice.columns.size()), + false, ImmutableList.of()); + final Table table = + new MaterializationService.DefaultTableFactory() + .createTable(lattice.rootSchema, sql, ImmutableList.of()); + final ImmutableList<ImmutableBitSet> initialGroups = + ImmutableList.of(); + final Enumerable<List<Comparable>> rows = + ((ScannableTable) table).scan(null) + .select(values -> { + for (int i = 0; i < values.length; i++) { + if (values[i] == null) { + values[i] = NullSentinel.INSTANCE; + } + } + //noinspection unchecked + return (List<Comparable>) (List) Arrays.asList(values); + }); + return profiler.profile(rows, columns, initialGroups); + })::get; } public double cardinality(List<Lattice.Column> columns) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/SqlLatticeStatisticProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/SqlLatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/SqlLatticeStatisticProvider.java index 8e5b19d..28d804c 100644 --- a/core/src/main/java/org/apache/calcite/materialize/SqlLatticeStatisticProvider.java +++ b/core/src/main/java/org/apache/calcite/materialize/SqlLatticeStatisticProvider.java @@ -20,38 +20,30 @@ import org.apache.calcite.schema.ScannableTable; import org.apache.calcite.schema.Table; import org.apache.calcite.util.ImmutableBitSet; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Implementation of {@link LatticeStatisticProvider} that gets statistics by * executing "SELECT COUNT(DISTINCT ...) ..." SQL queries. */ class SqlLatticeStatisticProvider implements LatticeStatisticProvider { - static final Factory FACTORY = - new LatticeStatisticProvider.Factory() { - public LatticeStatisticProvider apply(Lattice lattice) { - return new SqlLatticeStatisticProvider(lattice); - } - }; + static final Factory FACTORY = SqlLatticeStatisticProvider::new; - static final Factory CACHED_FACTORY = - new LatticeStatisticProvider.Factory() { - public LatticeStatisticProvider apply(Lattice lattice) { - LatticeStatisticProvider provider = FACTORY.apply(lattice); - return new CachingLatticeStatisticProvider(lattice, provider); - } - }; + static final Factory CACHED_FACTORY = lattice -> { + LatticeStatisticProvider provider = FACTORY.apply(lattice); + return new CachingLatticeStatisticProvider(lattice, provider); + }; private final Lattice lattice; /** Creates a SqlLatticeStatisticProvider. */ private SqlLatticeStatisticProvider(Lattice lattice) { - this.lattice = Preconditions.checkNotNull(lattice); + this.lattice = Objects.requireNonNull(lattice); } public double cardinality(List<Lattice.Column> columns) { @@ -66,7 +58,7 @@ class SqlLatticeStatisticProvider implements LatticeStatisticProvider { final String sql = lattice.countSql(ImmutableBitSet.of(column.ordinal)); final Table table = new MaterializationService.DefaultTableFactory() - .createTable(lattice.rootSchema, sql, ImmutableList.<String>of()); + .createTable(lattice.rootSchema, sql, ImmutableList.of()); final Object[] values = Iterables.getOnlyElement(((ScannableTable) table).scan(null)); return ((Number) values[0]).doubleValue(); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java b/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java index bc98d94..64cf736 100644 --- a/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java +++ b/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java @@ -18,10 +18,8 @@ package org.apache.calcite.materialize; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; import org.pentaho.aggdes.algorithm.Algorithm; import org.pentaho.aggdes.algorithm.Progress; @@ -46,13 +44,6 @@ import java.util.List; * for a given lattice. */ public class TileSuggester { - private static final Function<Attribute, Lattice.Column> TO_COLUMN = - new Function<Attribute, Lattice.Column>() { - public Lattice.Column apply(Attribute input) { - return ((AttributeImpl) input).column; - } - }; - private final Lattice lattice; public TileSuggester(Lattice lattice) { @@ -206,7 +197,8 @@ public class TileSuggester { } public double getRowCount(List<Attribute> attributes) { - return lattice.getRowCount(Lists.transform(attributes, TO_COLUMN)); + return lattice.getRowCount( + Util.transform(attributes, input -> ((AttributeImpl) input).column)); } public double getSpace(List<Attribute> attributes) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java index 81a297b..06306d5 100644 --- a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java +++ b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java @@ -21,7 +21,6 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.metadata.RelMetadataProvider; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rex.RexExecutor; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.util.CancelFlag; import com.google.common.collect.ImmutableList; @@ -38,7 +37,6 @@ import java.util.regex.Pattern; import static org.apache.calcite.util.Static.RESOURCE; - /** * Abstract base for implementations of the {@link RelOptPlanner} interface. */ @@ -417,12 +415,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner { /** Returns sub-classes of relational expression. */ public Iterable<Class<? extends RelNode>> subClasses( final Class<? extends RelNode> clazz) { - return Iterables.filter(classes, - new PredicateImpl<Class<? extends RelNode>>() { - public boolean test(Class<? extends RelNode> input) { - return clazz.isAssignableFrom(input); - } - }); + return Iterables.filter(classes, clazz::isAssignableFrom); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/plan/Contexts.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/plan/Contexts.java b/core/src/main/java/org/apache/calcite/plan/Contexts.java index 2aad6b1..adc13da 100644 --- a/core/src/main/java/org/apache/calcite/plan/Contexts.java +++ b/core/src/main/java/org/apache/calcite/plan/Contexts.java @@ -18,12 +18,11 @@ package org.apache.calcite.plan; import org.apache.calcite.config.CalciteConnectionConfig; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Utilities for {@link Context}. @@ -82,7 +81,7 @@ public class Contexts { private static Context chain(Iterable<? extends Context> contexts) { // Flatten any chain contexts in the list, and remove duplicates - final List<Context> list = Lists.newArrayList(); + final List<Context> list = new ArrayList<>(); for (Context context : contexts) { build(list, context); } @@ -116,7 +115,7 @@ public class Contexts { final Object target; WrapContext(Object target) { - this.target = Preconditions.checkNotNull(target); + this.target = Objects.requireNonNull(target); } public <T> T unwrap(Class<T> clazz) { @@ -139,7 +138,7 @@ public class Contexts { final ImmutableList<Context> contexts; ChainContext(ImmutableList<Context> contexts) { - this.contexts = Preconditions.checkNotNull(contexts); + this.contexts = Objects.requireNonNull(contexts); for (Context context : contexts) { assert !(context instanceof ChainContext) : "must be flat"; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java b/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java index a0b7e37..ff9de80 100644 --- a/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java +++ b/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java @@ -32,7 +32,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import java.util.List; -import javax.annotation.Nonnull; /** * Definition of the the convention trait. @@ -59,12 +58,8 @@ public class ConventionTraitDef extends RelTraitDef<Convention> { * the planner goes away, so does the cache entry. */ private final LoadingCache<RelOptPlanner, ConversionData> conversionCache = - CacheBuilder.newBuilder().weakKeys().build( - new CacheLoader<RelOptPlanner, ConversionData>() { - public ConversionData load(@Nonnull RelOptPlanner key) { - return new ConversionData(); - } - }); + CacheBuilder.newBuilder().weakKeys() + .build(CacheLoader.from(ConversionData::new)); //~ Constructors ----------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java index a7d1b00..b2a4ffc 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java +++ b/core/src/main/java/org/apache/calcite/plan/RelCompositeTrait.java @@ -16,12 +16,12 @@ */ package org.apache.calcite.plan; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A trait that consists of a list of traits, all of the same type. @@ -40,7 +40,7 @@ class RelCompositeTrait<T extends RelMultipleTrait> implements RelTrait { // Must remain private. Does not copy the array. private RelCompositeTrait(RelTraitDef traitDef, T[] traits) { this.traitDef = traitDef; - this.traits = Preconditions.checkNotNull(traits); + this.traits = Objects.requireNonNull(traits); //noinspection unchecked assert Ordering.natural() .isStrictlyOrdered(Arrays.asList((Comparable[]) traits)) @@ -59,7 +59,7 @@ class RelCompositeTrait<T extends RelMultipleTrait> implements RelTrait { compositeTrait = new EmptyCompositeTrait<T>(def); } else { final RelMultipleTrait[] traits = - traitList.toArray(new RelMultipleTrait[traitList.size()]); + traitList.toArray(new RelMultipleTrait[0]); for (int i = 0; i < traits.length; i++) { traits[i] = (T) def.canonize(traits[i]); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java b/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java index bce405c..c853eb8 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java +++ b/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java @@ -27,10 +27,9 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexNode; -import com.google.common.base.Preconditions; - import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /** @@ -76,8 +75,8 @@ public class RelOptCluster { Map<String, RelNode> mapCorrelToRel) { this.nextCorrel = nextCorrel; this.mapCorrelToRel = mapCorrelToRel; - this.planner = Preconditions.checkNotNull(planner); - this.typeFactory = Preconditions.checkNotNull(typeFactory); + this.planner = Objects.requireNonNull(planner); + this.typeFactory = Objects.requireNonNull(typeFactory); this.rexBuilder = rexBuilder; this.originalExpression = rexBuilder.makeLiteral("?");
