Skip to content

Commit

Permalink
[CALCITE-4280] Replace Guava's Lists.transform with Util.transform
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Sep 26, 2020
1 parent 3f2372f commit 609612a
Show file tree
Hide file tree
Showing 43 changed files with 92 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.Pair;

import com.google.common.collect.Lists;
import org.apache.calcite.util.Util;

import java.util.AbstractList;
import java.util.ArrayList;
Expand Down Expand Up @@ -143,6 +142,6 @@ private static <T> MethodCallExpression constantArrayList(List<T> values,
/** E.g. {@code constantList("x", "y")} returns
* {@code {ConstantExpression("x"), ConstantExpression("y")}}. */
private static <T> List<Expression> constantList(List<T> values) {
return Lists.transform(values, Expressions::constant);
return Util.transform(values, Expressions::constant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelProtoDataType;

import com.google.common.collect.Lists;
import org.apache.calcite.util.Util;

import java.lang.reflect.Type;
import java.sql.Date;
Expand Down Expand Up @@ -238,15 +237,15 @@ private static List wrap(ColumnMetaData.Rep rep, List list,
switch (rep) {
case OBJECT:
case JAVA_SQL_TIMESTAMP:
return Lists.transform(list,
return Util.transform(list,
(Timestamp t) -> t == null ? null : t.getTime());
}
break;
case TIME:
switch (rep) {
case OBJECT:
case JAVA_SQL_TIME:
return Lists.transform(list, (Time t) -> t == null
return Util.transform(list, (Time t) -> t == null
? null
: (int) (t.getTime() % DateTimeUtils.MILLIS_PER_DAY));
}
Expand All @@ -255,7 +254,7 @@ private static List wrap(ColumnMetaData.Rep rep, List list,
switch (rep) {
case OBJECT:
case JAVA_SQL_DATE:
return Lists.transform(list, (Date d) -> d == null
return Util.transform(list, (Date d) -> d == null
? null
: (int) (d.getTime() / DateTimeUtils.MILLIS_PER_DAY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.calcite.util.Util;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -269,7 +268,7 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

@Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(
final RelTraitSet required) {
final List<RexNode> exps = Lists.transform(program.getProjectList(),
final List<RexNode> exps = Util.transform(program.getProjectList(),
program::expandLocalRef);

return EnumerableTraitsUtils.passThroughTraitsForProject(required, exps,
Expand All @@ -278,7 +277,7 @@ public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

@Override public Pair<RelTraitSet, List<RelTraitSet>> deriveTraits(
final RelTraitSet childTraits, final int childId) {
final List<RexNode> exps = Lists.transform(program.getProjectList(),
final List<RexNode> exps = Util.transform(program.getProjectList(),
program::expandLocalRef);

return EnumerableTraitsUtils.deriveTraitsForProject(childTraits, childId, exps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.logical.LogicalUnion;

import com.google.common.collect.Lists;
import org.apache.calcite.util.Util;

import java.util.List;

Expand All @@ -48,7 +47,7 @@ protected EnumerableUnionRule(Config config) {
final LogicalUnion union = (LogicalUnion) rel;
final EnumerableConvention out = EnumerableConvention.INSTANCE;
final RelTraitSet traitSet = rel.getCluster().traitSet().replace(out);
final List<RelNode> newInputs = Lists.transform(
final List<RelNode> newInputs = Util.transform(
union.getInputs(), n -> convert(n, traitSet));
return new EnumerableUnion(rel.getCluster(), traitSet,
newInputs, union.all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;

import com.google.common.collect.Lists;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -130,7 +128,7 @@ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
private List<Pair<ColumnMetaData.Rep, Integer>> fieldClasses(
final JavaTypeFactory typeFactory) {
final RelDataType rowType = protoRowType.apply(typeFactory);
return Lists.transform(rowType.getFieldList(), f -> {
return Util.transform(rowType.getFieldList(), f -> {
final RelDataType type = f.getType();
final Class clazz = (Class) typeFactory.getJavaClass(type);
final ColumnMetaData.Rep rep =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;

Expand Down Expand Up @@ -391,12 +390,12 @@ static Builder builder(LatticeSpace space, CalciteSchema calciteSchema,
}

public List<Measure> toMeasures(List<AggregateCall> aggCallList) {
return Lists.transform(aggCallList, this::toMeasure);
return Util.transform(aggCallList, this::toMeasure);
}

private Measure toMeasure(AggregateCall aggCall) {
return new Measure(aggCall.getAggregation(), aggCall.isDistinct(),
aggCall.name, Lists.transform(aggCall.getArgList(), columns::get));
aggCall.name, Util.transform(aggCall.getArgList(), columns::get));
}

public Iterable<? extends Tile> computeTiles() {
Expand Down Expand Up @@ -451,7 +450,7 @@ public static double getRowCount(double factCount,
}

public List<String> uniqueColumnNames() {
return Lists.transform(columns, column -> column.alias);
return Util.transform(columns, column -> column.alias);
}

Pair<Path, Integer> columnToPathOffset(BaseColumn c) {
Expand Down Expand Up @@ -610,7 +609,7 @@ public ImmutableBitSet argBitSet() {

/** Returns a list of argument ordinals. */
public List<Integer> argOrdinals() {
return Lists.transform(args, column -> column.ordinal);
return Util.transform(args, column -> column.ordinal);
}

private static int compare(List<Column> list0, List<Column> list1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.calcite.util.mapping.IntPair;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -120,7 +119,7 @@ static List<IntPair> sortUnique(List<IntPair> keys) {
/** Returns a list of {@link IntPair}, transposing source and target fields,
* and ensuring the result is sorted and unique. */
static List<IntPair> swap(List<IntPair> keys) {
return sortUnique(Lists.transform(keys, IntPair.SWAP));
return sortUnique(Util.transform(keys, x -> IntPair.of(x.target, x.source)));
}

Path addPath(List<Step> steps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

import java.util.ArrayList;
Expand Down Expand Up @@ -231,7 +230,7 @@ private void addFrame(Query q, Frame frame, List<Lattice> lattices) {
latticeBuilder.addMeasure(
new Lattice.Measure(measure.aggregate, measure.distinct,
measure.name,
Lists.transform(measure.arguments, colRef -> {
Util.transform(measure.arguments, colRef -> {
final Lattice.Column column;
if (colRef instanceof BaseColRef) {
final BaseColRef baseColRef = (BaseColRef) colRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import java.lang.reflect.Type;
import java.util.ArrayList;
Expand Down Expand Up @@ -371,7 +370,7 @@ public Table createTable(CalciteSchema schema, String viewSql,
return CloneSchema.createCloneTable(connection.getTypeFactory(),
RelDataTypeImpl.proto(calciteSignature.rowType),
calciteSignature.getCollationList(),
Lists.transform(calciteSignature.columns, column -> column.type.rep),
Util.transform(calciteSignature.columns, column -> column.type.rep),
new AbstractQueryable<Object>() {
public Enumerator<Object> enumerator() {
final DataContext dataContext =
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/apache/calcite/plan/RelOptRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.Util;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -632,7 +633,7 @@ public static RelNode convert(RelNode rel, RelTrait toTrait) {
*/
protected static List<RelNode> convertList(List<RelNode> rels,
final RelTrait trait) {
return Lists.transform(rels,
return Util.transform(rels,
rel -> convert(rel, rel.getTraitSet().replace(trait)));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static void go(
* @see org.apache.calcite.rel.type.RelDataType#getFieldNames()
*/
public static List<RelDataType> getFieldTypeList(final RelDataType type) {
return Lists.transform(type.getFieldList(), RelDataTypeField::getType);
return Util.transform(type.getFieldList(), RelDataTypeField::getType);
}

public static boolean areRowTypesEqual(
Expand Down Expand Up @@ -3052,7 +3052,7 @@ public static MultiJoin projectMultiJoin(
multiJoin.isFullOuterJoin(),
multiJoin.getOuterJoinConditions(),
multiJoin.getJoinTypes(),
Lists.transform(newProjFields, ImmutableBitSet::fromBitSet),
Util.transform(newProjFields, ImmutableBitSet::fromBitSet),
multiJoin.getJoinFieldRefCountsMap(),
multiJoin.getPostJoinFilter());
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/calcite/rel/RelCollations.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.calcite.util.mapping.Mappings;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -147,7 +146,7 @@ public static List<Integer> ordinals(RelCollation collation) {
/** Returns the indexes of the fields in a list of field collations. */
public static List<Integer> ordinals(
List<RelFieldCollation> fieldCollations) {
return Lists.transform(fieldCollations, RelFieldCollation::getFieldIndex);
return Util.transform(fieldCollations, RelFieldCollation::getFieldIndex);
}

/** Returns whether a collation indicates that the collection is sorted on
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/calcite/rel/core/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.apache.calcite.util.mapping.Mappings;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import org.apiguardian.api.API;

Expand Down Expand Up @@ -222,7 +221,7 @@ public boolean isValid(Litmus litmus, Context context) {
return litmus.fail("field names not distinct: {}", rowType);
}
//CHECKSTYLE: IGNORE 1
if (false && !Util.isDistinct(Lists.transform(exps, RexNode::toString))) {
if (false && !Util.isDistinct(Util.transform(exps, RexNode::toString))) {
// Projecting the same expression twice is usually a bad idea,
// because it may create expressions downstream which are equivalent
// but which look different. We can't ban duplicate projects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.util.Util;

import com.google.common.collect.Lists;

import java.util.List;

/**
Expand Down Expand Up @@ -99,7 +97,7 @@ public RelNode getIterativeRel() {

@Override protected RelDataType deriveRowType() {
final List<RelDataType> inputRowTypes =
Lists.transform(getInputs(), RelNode::getRowType);
Util.transform(getInputs(), RelNode::getRowType);
final RelDataType rowType =
getCluster().getTypeFactory().leastRestrictive(inputRowTypes);
if (rowType == null) {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/calcite/rel/core/SetOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

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;
Expand Down Expand Up @@ -102,7 +101,7 @@ public abstract SetOp copy(

@Override protected RelDataType deriveRowType() {
final List<RelDataType> inputRowTypes =
Lists.transform(inputs, RelNode::getRowType);
Util.transform(inputs, RelNode::getRowType);
final RelDataType rowType =
getCluster().getTypeFactory().leastRestrictive(inputRowTypes);
if (rowType == null) {
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/org/apache/calcite/rel/core/Sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.util.Util;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -171,7 +169,7 @@ public RelCollation getCollation() {
/** Returns the sort expressions. */
public List<RexNode> getSortExps() {
//noinspection StaticPseudoFunctionalStyleMethod
return Lists.transform(collation.getFieldCollations(), field ->
return Util.transform(collation.getFieldCollations(), field ->
getCluster().getRexBuilder().makeInputRef(input,
Objects.requireNonNull(field).getFieldIndex()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -219,7 +219,7 @@ public Boolean areColumnsUnique(Calc rel, RelMetadataQuery mq,
RexProgram program = rel.getProgram();

return areProjectColumnsUnique(rel, mq, columns, ignoreNulls,
Lists.transform(program.getProjectList(), program::expandLocalRef));
Util.transform(program.getProjectList(), program::expandLocalRef));
}

private Boolean areProjectColumnsUnique(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Permutation;
import org.apache.calcite.util.Util;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.HashSet;
Expand Down Expand Up @@ -101,7 +101,7 @@ public Set<ImmutableBitSet> getUniqueKeys(Calc rel, RelMetadataQuery mq,
RexProgram program = rel.getProgram();
Permutation permutation = program.getPermutation();
return getProjectUniqueKeys(rel, mq, ignoreNulls,
Lists.transform(program.getProjectList(), program::expandLocalRef));
Util.transform(program.getProjectList(), program::expandLocalRef));
}

private Set<ImmutableBitSet> getProjectUniqueKeys(SingleRel rel, RelMetadataQuery mq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.rel.type.RelDataType;

import com.google.common.collect.Lists;
import org.apache.calcite.util.Util;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -58,6 +57,6 @@ protected MutableMultiRel(RelOptCluster cluster,
}

protected List<MutableRel> cloneChildren() {
return Lists.transform(inputs, MutableRel::clone);
return Util.transform(inputs, MutableRel::clone);
}
}
Loading

0 comments on commit 609612a

Please sign in to comment.