Skip to content

Commit

Permalink
[CALCITE-5763] Increase minimum Guava version to 21.0, maximum versio…
Browse files Browse the repository at this point in the history
…n to 32.1.3-jre, and stop building on Guava 19.0

Calcite previously built on Guava 19.0; after this change,
we build on the latest Guava (32.1.3-jre) and on various
versions including the oldest supported Guava (21.0).

We choose 21.0 as the minimum supported Guava version
because it includes various changes to support JDK 8,
including stream, Supplier, and functions.

Revert [CALCITE-5428] Reduce minimum Guava version to 16.0.1

Code changes that are possible now we are on Guava 21.0:
* Replace Guava Supplier with Java Supplier, and remove
  redundant '::get' calls;
* Replace Util.toImmutableList with
  ImmutableList.toImmutableList;
* Replace Util.throwIfUnchecked with
  Throwables.throwIfUnchecked;
* Replace RangeSetTest.unionRangeSet with
  ImmutableRangetSet.unionOf.

Add an autostyle rule to require a static import of
ImuutableList.toImmutableList.

Cassandra requires Guava 23 or higher, for the method
ImmutableSet.builderWithExpectedSize, so disable the
Cassandra test on lower Guava versions.

Close apache#3470
  • Loading branch information
julianhyde committed Oct 18, 2023
1 parent 5151168 commit c6031ca
Show file tree
Hide file tree
Showing 46 changed files with 148 additions and 154 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ jobs:
linux-jdk8-oldest-guava-tz:
if: github.event.action != 'labeled'
name: 'Linux (JDK 8), Oldest Guava, America/New_York Timezone'
name: 'Linux (JDK 8), oldest Guava, America/New_York Timezone'
runs-on: ubuntu-latest
env:
TZ: 'America/New_York' # flips between −05:00 and −04:00
GUAVA: '16.0.1' # oldest supported Guava version
GUAVA: '21.0' # oldest Guava
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -144,11 +144,11 @@ jobs:

linux-jdk8-latest-guava-tz:
if: github.event.action != 'labeled'
name: 'Linux (JDK 8), Latest Guava, America/New_York Timezone'
name: 'Linux (JDK 8), latest Guava, America/New_York Timezone'
runs-on: ubuntu-latest
env:
TZ: 'America/New_York' # flips between −05:00 and −04:00
GUAVA: '31.1-jre' # latest supported Guava version
GUAVA: '32.1.3-jre' # latest supported Guava version
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
name: 'Linux (JDK 17)'
runs-on: ubuntu-latest
env:
GUAVA: '19.0'
GUAVA: '21.0' # oldest Guava
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -225,7 +225,7 @@ jobs:
name: 'Linux (JDK 19)'
runs-on: ubuntu-latest
env:
GUAVA: '19.0'
GUAVA: '21.0' # oldest Guava
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -324,12 +324,12 @@ jobs:
echo sqlsh
./sqlsh -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20"
errorprone-guava31: # LTS JDK version, don't remove until EOL
errorprone-guava-latest: # LTS JDK version, don't remove until EOL
if: github.event.action != 'labeled'
name: 'Error Prone (JDK 11), Guava 31'
name: 'Error Prone (JDK 11), latest Guava'
runs-on: ubuntu-latest
env:
GUAVA: '31.1-jre' # ErrorProne checks for Beta APIs, so use the newest supported Guava version
GUAVA: '32.1.3-jre' # ErrorProne checks for Beta APIs, so use the latest supported Guava version
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -374,10 +374,10 @@ jobs:
arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes

linux-checkerframework-guava29:
name: 'CheckerFramework (JDK 11), Guava 29'
name: 'CheckerFramework (JDK 11), oldest Guava'
runs-on: ubuntu-latest
env:
GUAVA: '29.0-jre'
GUAVA: '21.0' # oldest Guava
steps:
- uses: actions/checkout@v3
with:
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ allprojects {
replace("hamcrest: sameInstance", "org.hamcrest.core.IsSame.sameInstance", "org.hamcrest.CoreMatchers.sameInstance")
replace("hamcrest: startsWith", "org.hamcrest.core.StringStartsWith.startsWith", "org.hamcrest.CoreMatchers.startsWith")
replaceRegex("hamcrest: size", "\\.size\\(\\), (is|equalTo)\\(", ", hasSize\\(")
replaceRegex("use static import: toImmutableList", "ImmutableList\\.(toImmutableList\\(\\))", "$1")
custom("((() preventer", 1) { contents: String ->
ParenthesisBalancer.apply(contents)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ private static CassandraResource getOrCreate(ExtensionContext context) {
*
* @see <a href="https://issues.apache.org/jira/browse/CASSANDRA-14883">CASSANDRA-14883</a>
*
* <p>Cassandra requires method
* {@link com.google.common.collect.ImmutableSet#builderWithExpectedSize(int)}
* and therefore Guava 23 or higher.
*
* @return {@code true} if test is compatible with current environment,
* {@code false} otherwise
*/
Expand All @@ -125,7 +129,7 @@ private static CassandraResource getOrCreate(ExtensionContext context) {
boolean enabled = CalciteSystemProperty.TEST_CASSANDRA.value();
Bug.upgrade("remove JDK version check once cassandra-unit supports JDK11+");
boolean compatibleJdk = TestUtil.getJavaMajorVersion() < 11;
boolean compatibleGuava = TestUtil.getGuavaMajorVersion() >= 20;
boolean compatibleGuava = TestUtil.getGuavaMajorVersion() >= 23;
Bug.upgrade("remove JVM check once Cassandra supports Eclipse OpenJ9 JVM");
boolean compatibleJVM = !"Eclipse OpenJ9".equals(TestUtil.getJavaVirtualMachineVendor());
if (enabled && compatibleJdk && compatibleGuava && compatibleJVM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Pair;

import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -50,6 +49,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -99,7 +99,6 @@ class ArrayTable extends AbstractQueryableTable implements ScannableTable {
SchemaPlus schema, String tableName) {
return new AbstractTableQueryable<T>(queryProvider, schema, this,
tableName) {
@SuppressWarnings("unchecked")
@Override public Enumerator<T> enumerator() {
final Content content = supplier.get();
return content.enumerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.calcite.sql.SqlDialectFactoryImpl;
import org.apache.calcite.util.BuiltInMethod;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;

Expand All @@ -38,6 +37,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.function.Supplier;
import javax.sql.DataSource;

import static java.util.Objects.requireNonNull;
Expand All @@ -61,7 +61,7 @@ public class JdbcCatalogSchema extends AbstractSchema {
final String catalog;

/** Sub-schemas by name, lazily initialized. */
@SuppressWarnings("method.invocation.invalid")
@SuppressWarnings({"method.invocation.invalid", "Convert2MethodRef"})
final Supplier<SubSchemaMap> subSchemaMapSupplier =
Suppliers.memoize(() -> computeSubSchemaMap());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class JdbcTable extends AbstractQueryableTable
implements TranslatableTable, ScannableTable, ModifiableTable {
@SuppressWarnings("methodref.receiver.bound.invalid")
private final Supplier<RelProtoDataType> protoRowTypeSupplier =
Suppliers.memoize(this::supplyProto)::get;
Suppliers.memoize(this::supplyProto);
public final JdbcSchema jdbcSchema;
public final String jdbcCatalogName;
public final String jdbcSchemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.calcite.config;

import org.apache.calcite.util.Bug;

import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -31,7 +29,8 @@
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;

import static com.google.common.base.MoreObjects.firstNonNull;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -468,21 +467,10 @@ private static CalciteSystemProperty<String> stringProperty(
});
}

private static <T> T firstNonEmpty(@CheckForNull T t0, T t1) {
Bug.upgrade("remove when 18.0 is the minimum Guava version");
if (t0 != null) {
return t0;
}
if (t1 != null) {
return t1;
}
throw new NullPointerException();
}

private static Properties loadProperties() {
Properties saffronProperties = new Properties();
ClassLoader classLoader =
firstNonEmpty(Thread.currentThread().getContextClassLoader(),
firstNonNull(Thread.currentThread().getContextClassLoader(),
CalciteSystemProperty.class.getClassLoader());
// Read properties from the file "saffron.properties", if it exists in classpath
try (InputStream stream = requireNonNull(classLoader, "classLoader")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private ProfilerLatticeStatisticProvider(Lattice lattice) {
return (List<Comparable>) (List) Arrays.asList(values);
});
return profiler.profile(rows, columns, initialGroups);
})::get;
});
}

@Override public double cardinality(List<Lattice.Column> columns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static List<Pair<RelNode, RelOptLattice>> useLattices(
Util.transform(queryTables, RelOptTable::getQualifiedName));
// Remember leaf-join form of root so we convert at most once.
final Supplier<RelNode> leafJoinRoot =
Suppliers.memoize(() -> RelOptMaterialization.toLeafJoinForm(rel))::get;
Suppliers.memoize(() -> RelOptMaterialization.toLeafJoinForm(rel));
for (RelOptLattice lattice : lattices) {
if (queryTableNames.contains(lattice.rootTable().getQualifiedName())) {
RelNode rel2 = lattice.rewrite(leafJoinRoot.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.calcite.plan.volcano.RelSubset;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.util.Util;

import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -55,6 +54,8 @@
import java.util.Objects;
import java.util.Set;

import static com.google.common.collect.ImmutableList.toImmutableList;

import static org.apache.calcite.util.Util.transform;

/**
Expand Down Expand Up @@ -355,7 +356,7 @@ private void addStep(String stepID, @Nullable RelOptRuleCall ruleCall) {
List<String> matchedRels =
Arrays.stream(ruleCall == null ? new RelNode[0] : ruleCall.rels)
.map(RuleMatchVisualizer::key)
.collect(Util.toImmutableList());
.collect(toImmutableList());
this.steps.add(new StepInfo(stepID, nextNodeUpdates, matchedRels));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import java.util.function.Function;
import java.util.function.Predicate;

import static com.google.common.collect.ImmutableList.toImmutableList;

/**
* Implementation of {@link org.apache.calcite.prepare.Prepare.CatalogReader}
* and also {@link org.apache.calcite.sql.SqlOperatorTable} based on tables and
Expand Down Expand Up @@ -305,20 +307,20 @@ private static SqlOperator toOp(SqlIdentifier name,
typeFactory -> function.getParameters()
.stream()
.map(o -> o.getType(typeFactory))
.collect(Util.toImmutableList());
.collect(toImmutableList());
final Function<RelDataTypeFactory, List<SqlTypeFamily>> typeFamiliesFactory =
typeFactory -> argTypesFactory.apply(typeFactory)
.stream()
.map(type ->
Util.first(type.getSqlTypeName().getFamily(),
SqlTypeFamily.ANY))
.collect(Util.toImmutableList());
.collect(toImmutableList());
final Function<RelDataTypeFactory, List<RelDataType>> paramTypesFactory =
typeFactory ->
argTypesFactory.apply(typeFactory)
.stream()
.map(type -> toSql(typeFactory, type))
.collect(Util.toImmutableList());
.collect(toImmutableList());

// Use a short-lived type factory to populate "typeFamilies" and "argTypes".
// SqlOperandMetadata.paramTypes will use the real type factory, during
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.SortedMap;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;

/**
* Definition of metadata.
Expand All @@ -47,7 +48,7 @@ private MetadataDef(Class<M> metadataClass,
this.methods =
Arrays.stream(methods)
.sorted(Comparator.comparing(Method::getName))
.collect(Util.toImmutableList());
.collect(toImmutableList());
final SortedMap<String, Method> handlerMethods =
MetadataHandler.handlerMethods(handlerClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.util.ImmutableBitSet;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand All @@ -40,6 +39,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import static org.apache.calcite.linq4j.Nullness.castNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
import java.util.function.IntFunction;
import java.util.function.Predicate;

import static com.google.common.collect.ImmutableList.toImmutableList;

import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -1372,7 +1374,7 @@ public static SqlNode toSql(@Nullable RexProgram program, RexLiteral literal) {
final List<RexLiteral> list = castNonNull(literal.getValueAs(List.class));
return SqlStdOperatorTable.ROW.createCall(POS,
list.stream().map(e -> toSql(program, e))
.collect(Util.toImmutableList()));
.collect(toImmutableList()));

case SARG:
final Sarg arg = literal.getValueAs(Sarg.class);
Expand All @@ -1397,7 +1399,7 @@ public static SqlNode toSql(RexLiteral literal) {
final List<RexLiteral> list = castNonNull(literal.getValueAs(List.class));
return SqlStdOperatorTable.ROW.createCall(POS,
list.stream().map(e -> toSql(e))
.collect(Util.toImmutableList()));
.collect(toImmutableList()));

case SARG:
final Sarg arg = literal.getValueAs(Sarg.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.function.IntPredicate;
import java.util.stream.Collectors;

import static com.google.common.collect.ImmutableList.toImmutableList;

import static org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.groupValue;
import static org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule.remap;

Expand Down Expand Up @@ -158,7 +160,7 @@ private static boolean hasWithinDistinct(Aggregate aggregate) {
aggregate.getAggCallList()
.stream()
.map(c -> unDistinct(c, aggregate.getInput()::fieldIsNullable))
.collect(Util.toImmutableList());
.collect(toImmutableList());

// Find all within-distinct expressions.
final Multimap<ImmutableBitSet, AggregateCall> argLists =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.mapping.Mapping;
import org.apache.calcite.util.mapping.MappingType;
import org.apache.calcite.util.mapping.Mappings;
Expand All @@ -38,6 +37,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.google.common.collect.ImmutableList.toImmutableList;

/**
* Rule to extract a {@link org.apache.calcite.rel.core.Project}
* from an {@link org.apache.calcite.rel.core.Aggregate}
Expand Down Expand Up @@ -116,11 +117,11 @@ public AggregateExtractProjectRule(RelOptRuleOperand operand,
final List<ImmutableBitSet> newGroupSets =
aggregate.getGroupSets().stream()
.map(bitSet -> Mappings.apply(mapping, bitSet))
.collect(Util.toImmutableList());
.collect(toImmutableList());
final List<RelBuilder.AggCall> newAggCallList =
aggregate.getAggCallList().stream()
.map(aggCall -> relBuilder.aggregateCall(aggCall, mapping))
.collect(Util.toImmutableList());
.collect(toImmutableList());

final RelBuilder.GroupKey groupKey =
relBuilder.groupKey(newGroupSet, newGroupSets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MaterializedViewFilterScanRule
new HepProgramBuilder()
.addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE)
.addRuleInstance(CoreRules.PROJECT_MERGE)
.build())::get;
.build());

//~ Constructors -----------------------------------------------------------

Expand Down
Loading

0 comments on commit c6031ca

Please sign in to comment.