This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new c6031ca155 [CALCITE-5763] Increase minimum Guava version to 21.0, 
maximum version to 32.1.3-jre, and stop building on Guava 19.0
c6031ca155 is described below

commit c6031ca15579b88bd392a56f4588fdd9a29d1071
Author: Julian Hyde <[email protected]>
AuthorDate: Sat Oct 14 11:26:36 2023 -0700

    [CALCITE-5763] Increase minimum Guava version to 21.0, maximum version 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/calcite#3470
---
 .github/workflows/main.yml                         | 22 +++++------
 build.gradle.kts                                   |  1 +
 .../apache/calcite/test/CassandraExtension.java    |  6 ++-
 .../apache/calcite/adapter/clone/ArrayTable.java   |  3 +-
 .../calcite/adapter/jdbc/JdbcCatalogSchema.java    |  4 +-
 .../org/apache/calcite/adapter/jdbc/JdbcTable.java |  2 +-
 .../calcite/config/CalciteSystemProperty.java      | 18 ++-------
 .../ProfilerLatticeStatisticProvider.java          |  2 +-
 .../calcite/plan/RelOptMaterializations.java       |  2 +-
 .../plan/visualizer/RuleMatchVisualizer.java       |  5 ++-
 .../calcite/prepare/CalciteCatalogReader.java      |  8 ++--
 .../apache/calcite/rel/metadata/MetadataDef.java   |  3 +-
 .../calcite/rel/metadata/RelMetadataQuery.java     |  2 +-
 .../apache/calcite/rel/rel2sql/SqlImplementor.java |  6 ++-
 .../rules/AggregateExpandWithinDistinctRule.java   |  4 +-
 .../rel/rules/AggregateExtractProjectRule.java     |  7 ++--
 .../rel/rules/MaterializedViewFilterScanRule.java  |  2 +-
 .../calcite/rel/rules/SortRemoveRedundantRule.java |  2 +-
 .../java/org/apache/calcite/rex/RexAnalyzer.java   |  8 ++--
 .../java/org/apache/calcite/rex/RexBuilder.java    |  8 ++--
 .../main/java/org/apache/calcite/rex/RexUtil.java  |  4 +-
 .../apache/calcite/runtime/AutomatonBuilder.java   |  5 ++-
 .../main/java/org/apache/calcite/runtime/Hook.java | 15 +++++++-
 .../java/org/apache/calcite/runtime/PairList.java  |  2 +-
 .../java/org/apache/calcite/sql/SqlDialect.java    |  2 +-
 .../main/java/org/apache/calcite/sql/SqlHint.java  |  5 ++-
 .../java/org/apache/calcite/sql/SqlIdentifier.java |  4 +-
 .../apache/calcite/sql/util/SqlOperatorTables.java |  3 +-
 .../calcite/sql/validate/DelegatingScope.java      |  4 +-
 .../apache/calcite/sql2rel/SqlToRelConverter.java  |  9 +++--
 .../java/org/apache/calcite/tools/Frameworks.java  |  2 +-
 .../java/org/apache/calcite/tools/RelBuilder.java  | 10 +++--
 .../java/org/apache/calcite/util/Compatible.java   | 12 ------
 .../main/java/org/apache/calcite/util/Util.java    | 43 ++++------------------
 .../calcite/materialize/LatticeSuggesterTest.java  |  4 +-
 .../org/apache/calcite/profile/ProfilerTest.java   |  5 ++-
 .../org/apache/calcite/test/RelMetadataTest.java   |  4 +-
 .../java/org/apache/calcite/util/RangeSetTest.java | 18 ++-------
 .../java/org/apache/calcite/util/UtilTest.java     |  2 +-
 gradle.properties                                  |  4 +-
 .../apache/calcite/linq4j/EnumerableDefaults.java  |  2 +-
 site/_docs/history.md                              |  4 +-
 .../apache/calcite/sql/test/SqlTestFactory.java    |  4 +-
 .../org/apache/calcite/test/CalciteAssert.java     | 14 ++++++-
 .../java/org/apache/calcite/test/Matchers.java     |  4 +-
 .../java/org/apache/calcite/util/TestUtil.java     |  2 +-
 46 files changed, 148 insertions(+), 154 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 54258956d9..4c8a54841c 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
diff --git a/build.gradle.kts b/build.gradle.kts
index 90ce625516..9d4a6e8af9 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -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)
                     }
diff --git 
a/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java 
b/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
index 7a55e472da..14b72b6eae 100644
--- a/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
+++ b/cassandra/src/test/java/org/apache/calcite/test/CassandraExtension.java
@@ -117,6 +117,10 @@ class CassandraExtension implements ParameterResolver, 
ExecutionCondition {
    *
    * @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
    */
@@ -125,7 +129,7 @@ class CassandraExtension implements ParameterResolver, 
ExecutionCondition {
     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) {
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java 
b/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
index 1ac4612fa0..8400ac21d6 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
@@ -38,7 +38,6 @@ import org.apache.calcite.schema.impl.AbstractTableQueryable;
 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;
@@ -50,6 +49,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.function.Supplier;
 
 import static java.util.Objects.requireNonNull;
 
@@ -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();
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java 
b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
index cd1e8cf51b..e2e1478d13 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCatalogSchema.java
@@ -28,7 +28,6 @@ import org.apache.calcite.sql.SqlDialectFactory;
 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;
 
@@ -38,6 +37,7 @@ import java.sql.Connection;
 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;
@@ -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());
 
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java 
b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
index 8e9593b632..8d14f95e0e 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcTable.java
@@ -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;
diff --git 
a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java 
b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
index 963626fd10..4db1b306a0 100644
--- a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
+++ b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
@@ -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;
@@ -31,7 +29,8 @@ import java.util.Set;
 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;
 
@@ -468,21 +467,10 @@ public final class CalciteSystemProperty<T> {
     });
   }
 
-  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")
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 1c13aca439..29d3457ae7 100644
--- 
a/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java
+++ 
b/core/src/main/java/org/apache/calcite/materialize/ProfilerLatticeStatisticProvider.java
@@ -79,7 +79,7 @@ class ProfilerLatticeStatisticProvider implements 
LatticeStatisticProvider {
                 return (List<Comparable>) (List) Arrays.asList(values);
               });
       return profiler.profile(rows, columns, initialGroups);
-    })::get;
+    });
   }
 
   @Override public double cardinality(List<Lattice.Column> columns) {
diff --git 
a/core/src/main/java/org/apache/calcite/plan/RelOptMaterializations.java 
b/core/src/main/java/org/apache/calcite/plan/RelOptMaterializations.java
index 9feb6507d0..089fe6191b 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptMaterializations.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptMaterializations.java
@@ -125,7 +125,7 @@ public abstract class RelOptMaterializations {
             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());
diff --git 
a/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
 
b/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
index b1bb04f320..7aa703dca6 100644
--- 
a/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
+++ 
b/core/src/main/java/org/apache/calcite/plan/visualizer/RuleMatchVisualizer.java
@@ -24,7 +24,6 @@ import org.apache.calcite.plan.hep.HepRelVertex;
 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;
 
@@ -55,6 +54,8 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.apache.calcite.util.Util.transform;
 
 /**
@@ -355,7 +356,7 @@ public class RuleMatchVisualizer implements RelOptListener {
     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));
   }
 
diff --git 
a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java 
b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
index 9c60635184..1e4896a2db 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
@@ -77,6 +77,8 @@ import java.util.Objects;
 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
@@ -305,20 +307,20 @@ public class CalciteCatalogReader implements 
Prepare.CatalogReader {
         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
diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/MetadataDef.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/MetadataDef.java
index f85b1b557e..6c029ae14f 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/MetadataDef.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/MetadataDef.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.SortedMap;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.collect.ImmutableList.toImmutableList;
 
 /**
  * Definition of metadata.
@@ -47,7 +48,7 @@ public class MetadataDef<M extends Metadata> {
     this.methods =
         Arrays.stream(methods)
             .sorted(Comparator.comparing(Method::getName))
-            .collect(Util.toImmutableList());
+            .collect(toImmutableList());
     final SortedMap<String, Method> handlerMethods =
         MetadataHandler.handlerMethods(handlerClass);
 
diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
index b1ff4495e7..d2c7b7f265 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
@@ -29,7 +29,6 @@ import org.apache.calcite.rex.RexTableInputRef.RelTableRef;
 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;
@@ -40,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 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;
 
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java 
b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 8ef8c85b23..f7fafd648e 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -129,6 +129,8 @@ import java.util.function.Function;
 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;
@@ -1372,7 +1374,7 @@ public abstract class SqlImplementor {
       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);
@@ -1397,7 +1399,7 @@ public abstract class SqlImplementor {
       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);
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
 
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
index 1089285489..8d2fa99621 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java
@@ -50,6 +50,8 @@ import java.util.TreeSet;
 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;
 
@@ -158,7 +160,7 @@ public class AggregateExpandWithinDistinctRule
         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 =
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExtractProjectRule.java
 
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExtractProjectRule.java
index 28f13e87f3..5024d2e04b 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExtractProjectRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExtractProjectRule.java
@@ -28,7 +28,6 @@ import org.apache.calcite.rex.RexNode;
 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;
@@ -38,6 +37,8 @@ import org.immutables.value.Value;
 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}
@@ -116,11 +117,11 @@ public class AggregateExtractProjectRule
     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);
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/MaterializedViewFilterScanRule.java
 
b/core/src/main/java/org/apache/calcite/rel/rules/MaterializedViewFilterScanRule.java
index d856b52952..bbd40a63a5 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/MaterializedViewFilterScanRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/MaterializedViewFilterScanRule.java
@@ -56,7 +56,7 @@ public class MaterializedViewFilterScanRule
       new HepProgramBuilder()
           .addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE)
           .addRuleInstance(CoreRules.PROJECT_MERGE)
-          .build())::get;
+          .build());
 
   //~ Constructors -----------------------------------------------------------
 
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
index 8dd2e722e2..18b3839163 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
@@ -96,7 +96,7 @@ public class SortRemoveRedundantRule
     }
   }
 
-  private Optional<Double> getSortInputSpecificMaxRowCount(Sort sort) {
+  private static Optional<Double> getSortInputSpecificMaxRowCount(Sort sort) {
     // If the sort is pure limit, the specific max row count is limit's fetch.
     if (RelOptUtil.isPureLimit(sort)) {
       final double limit =
diff --git a/core/src/main/java/org/apache/calcite/rex/RexAnalyzer.java 
b/core/src/main/java/org/apache/calcite/rex/RexAnalyzer.java
index 733288b7d5..a265c264af 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexAnalyzer.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexAnalyzer.java
@@ -19,12 +19,12 @@ package org.apache.calcite.rex;
 import org.apache.calcite.linq4j.Linq4j;
 import org.apache.calcite.plan.RelOptPredicateList;
 import org.apache.calcite.rel.metadata.NullSentinel;
-import org.apache.calcite.util.Compatible;
 import org.apache.calcite.util.NlsString;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 
 import java.math.BigDecimal;
 import java.util.LinkedHashSet;
@@ -32,6 +32,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 /** Analyzes an expression, figures out what are the unbound variables,
  * assigns a variety of values to each unbound variable, and evaluates
  * the expression. */
@@ -56,10 +58,10 @@ public class RexAnalyzer {
   public Iterable<Map<RexNode, Comparable>> assignments() {
     final List<List<Comparable>> generators =
         variables.stream().map(RexAnalyzer::getComparables)
-            .collect(Util.toImmutableList());
+            .collect(toImmutableList());
     final Iterable<List<Comparable>> product = Linq4j.product(generators);
     return Util.transform(product,
-        values -> Compatible.copyOf(Pair.zip(variables, values)));
+        values -> ImmutableMap.copyOf(Pair.zip(variables, values)));
   }
 
   private static List<Comparable> getComparables(RexNode variable) {
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java 
b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index ab96e94011..7d778a399f 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -76,8 +76,10 @@ import java.util.Objects;
 import java.util.function.IntPredicate;
 import java.util.stream.Collectors;
 
+import static com.google.common.base.Verify.verifyNotNull;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
-import static org.apache.calcite.util.Util.verifyNotNull;
 
 import static java.util.Objects.requireNonNull;
 
@@ -360,7 +362,7 @@ public class RexBuilder {
       IntPredicate isNullable) {
     return list0.stream()
         .filter(isNullable::test)
-        .collect(Util.toImmutableList());
+        .collect(toImmutableList());
   }
 
   @Deprecated // to be removed before 2.0
@@ -1391,7 +1393,7 @@ public class RexBuilder {
     }
     return RexUtil.composeDisjunction(this, ranges.stream()
         .map(r -> makeCall(SqlStdOperatorTable.EQUALS, arg, r))
-        .collect(Util.toImmutableList()));
+        .collect(toImmutableList()));
   }
 
   /** Returns whether and argument and bounds are have types that are
diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java 
b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index e0435032da..6077329498 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -70,6 +70,8 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.function.Predicate;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -640,7 +642,7 @@ public class RexUtil {
               rexBuilder.makeCall(SqlStdOperatorTable.NOT_EQUALS, ref,
                   rexBuilder.makeLiteral(range.lowerEndpoint(),
                       type, true, true)))
-          .collect(Util.toImmutableList());
+          .collect(toImmutableList());
       orList.add(composeConjunction(rexBuilder, list));
     } else {
       final RangeSets.Consumer<C> consumer =
diff --git 
a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java 
b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
index 2e0b10c071..0d9a686c53 100644
--- a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
+++ b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java
@@ -20,7 +20,6 @@ import org.apache.calcite.runtime.Automaton.EpsilonTransition;
 import org.apache.calcite.runtime.Automaton.State;
 import org.apache.calcite.runtime.Automaton.SymbolTransition;
 import org.apache.calcite.runtime.Automaton.Transition;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -32,6 +31,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 /** Builds a state-transition graph for deterministic finite automaton. */
 public class AutomatonBuilder {
   private final Map<String, Integer> symbolIds = new HashMap<>();
@@ -112,7 +113,7 @@ public class AutomatonBuilder {
         .stream()
         .sorted(Comparator.comparingInt(Map.Entry::getValue))
         .map(Map.Entry::getKey)
-        .collect(Util.toImmutableList());
+        .collect(toImmutableList());
     return new Automaton(stateList.get(0), endState,
         symbolTransitions.build(), epsilonTransitions.build(), symbolNames);
   }
diff --git a/core/src/main/java/org/apache/calcite/runtime/Hook.java 
b/core/src/main/java/org/apache/calcite/runtime/Hook.java
index b76b94a4ef..98f3cc3fd1 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Hook.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Hook.java
@@ -18,6 +18,7 @@ package org.apache.calcite.runtime;
 
 import org.apache.calcite.rel.RelRoot;
 import org.apache.calcite.util.Holder;
+import org.apache.calcite.util.Util;
 
 import org.apiguardian.api.API;
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -165,7 +166,19 @@ public enum Hook {
   @Deprecated // to be removed before 2.0
   public <T, R> Closeable addThread(
       final com.google.common.base.Function<T, R> handler) {
-    return addThread((Consumer<T>) handler::apply);
+    return addThread(functionConsumer(handler));
+  }
+
+  /** Converts a Guava function into a JDK consumer. */
+  @SuppressWarnings("Guava")
+  private static <T, R> Consumer<T> functionConsumer(
+      com.google.common.base.Function<T, R> handler) {
+    return t -> {
+      // Squash ErrorProne warnings that the return of the function is not
+      // used.
+      R r = handler.apply(t);
+      Util.discard(r);
+    };
   }
 
   /** Removes a thread handler from this Hook. */
diff --git a/core/src/main/java/org/apache/calcite/runtime/PairList.java 
b/core/src/main/java/org/apache/calcite/runtime/PairList.java
index ef5819ebee..d4fa9aaa2b 100644
--- a/core/src/main/java/org/apache/calcite/runtime/PairList.java
+++ b/core/src/main/java/org/apache/calcite/runtime/PairList.java
@@ -57,7 +57,7 @@ public interface PairList<T, U> extends List<Map.Entry<T, U>> 
{
   /** Creates a PairList with one or more entries. */
   static <T, U> PairList<T, U> copyOf(T t, U u, Object... rest) {
     checkArgument(rest.length % 2 == 0, "even number");
-    final List<Object> list = Lists.asList(t, u, rest);
+    final List<@Nullable Object> list = Lists.asList(t, u, rest);
     return new PairLists.MutablePairList<>(new ArrayList<>(list));
   }
 
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java 
b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
index ae07d64cf2..5940485560 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
@@ -1384,7 +1384,7 @@ public class SqlDialect {
             .withDatabaseProductName(databaseProductName)
             .withIdentifierQuoteString(quoteString)
             .withNullCollation(nullCollation));
-      })::get;
+      });
     }
 
     /**
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlHint.java 
b/core/src/main/java/org/apache/calcite/sql/SqlHint.java
index 76741a6bdf..acb41eb6d7 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlHint.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlHint.java
@@ -17,7 +17,6 @@
 package org.apache.calcite.sql;
 
 import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -28,6 +27,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -133,7 +134,7 @@ public class SqlHint extends SqlCall {
             return requireNonNull(literal.toValue(),
                 () -> "null hint literal in " + options);
           })
-          .collect(Util.toImmutableList());
+          .collect(toImmutableList());
     } else {
       return ImmutableList.of();
     }
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java 
b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
index df19846efe..6742057bfb 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java
@@ -34,6 +34,8 @@ import org.checkerframework.dataflow.qual.Pure;
 import java.util.ArrayList;
 import java.util.List;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 /**
  * A <code>SqlIdentifier</code> is an identifier, possibly compound.
  */
@@ -272,7 +274,7 @@ public class SqlIdentifier extends SqlNode {
     final SqlIdentifier id = this.plus("*", SqlParserPos.ZERO);
     return new SqlIdentifier(
         id.names.stream().map(s -> s.equals("*") ? "" : s)
-            .collect(Util.toImmutableList()),
+            .collect(toImmutableList()),
         null, id.pos, id.componentPositions);
   }
 
diff --git 
a/core/src/main/java/org/apache/calcite/sql/util/SqlOperatorTables.java 
b/core/src/main/java/org/apache/calcite/sql/util/SqlOperatorTables.java
index 8e248a1783..26d3fe9a5a 100644
--- a/core/src/main/java/org/apache/calcite/sql/util/SqlOperatorTables.java
+++ b/core/src/main/java/org/apache/calcite/sql/util/SqlOperatorTables.java
@@ -33,9 +33,8 @@ import java.util.function.Supplier;
 public class SqlOperatorTables {
   private SqlOperatorTables() {}
 
-  @SuppressWarnings("FunctionalExpressionCanBeFolded")
   private static final Supplier<SqlOperatorTable> SPATIAL =
-      Suppliers.memoize(SqlSpatialTypeOperatorTable::new)::get;
+      Suppliers.memoize(SqlSpatialTypeOperatorTable::new);
 
   /** Returns the Spatial operator table, creating it if necessary. */
   public static SqlOperatorTable spatialInstance() {
diff --git 
a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java 
b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
index 44d9ec8c13..d1e1970efd 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
@@ -72,9 +72,9 @@ public abstract class DelegatingScope implements 
SqlValidatorScope {
 
   /** Computes and stores information that cannot be computed on construction,
    * but only after sub-queries have been validated. */
-  @SuppressWarnings({"methodref.receiver.bound.invalid", 
"FunctionalExpressionCanBeFolded"})
+  @SuppressWarnings({"methodref.receiver.bound.invalid"})
   public final Supplier<AggregatingSelectScope.Resolved> resolved =
-      Suppliers.memoize(this::resolve)::get;
+      Suppliers.memoize(this::resolve);
 
   /** Use while resolving. */
   SqlValidatorUtil.@Nullable GroupAnalyzer groupAnalyzer;
diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 1a1107b36d..977a986cf4 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -213,6 +213,7 @@ import java.util.function.Supplier;
 import java.util.function.UnaryOperator;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.collect.ImmutableList.toImmutableList;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.runtime.FlatLists.append;
@@ -2707,7 +2708,7 @@ public class SqlToRelConverter {
         valueList.add(
             Pair.of(alias,
                 nodeList.stream().map(bb::convertExpression)
-                    .collect(Util.toImmutableList()))));
+                    .collect(toImmutableList()))));
 
     final RelNode rel =
         relBuilder.pivot(groupKey, aggCalls, axes, valueList.build())
@@ -2726,10 +2727,10 @@ public class SqlToRelConverter {
 
     final List<String> measureNames = unpivot.measureList.stream()
         .map(node -> ((SqlIdentifier) node).getSimple())
-        .collect(Util.toImmutableList());
+        .collect(toImmutableList());
     final List<String> axisNames =  unpivot.axisList.stream()
         .map(node -> ((SqlIdentifier) node).getSimple())
-        .collect(Util.toImmutableList());
+        .collect(toImmutableList());
     final ImmutableList.Builder<Pair<List<RexLiteral>, List<RexNode>>> axisMap 
=
         ImmutableList.builder();
     unpivot.forEachNameValues((nodeList, valueList) -> {
@@ -2748,7 +2749,7 @@ public class SqlToRelConverter {
       });
       final List<RexNode> nodes = nodeList.stream()
           .map(unpivotBb::convertExpression)
-          .collect(Util.toImmutableList());
+          .collect(toImmutableList());
       axisMap.add(Pair.of(literals, nodes));
     });
     relBuilder.unpivot(unpivot.includeNulls, measureNames, axisNames,
diff --git a/core/src/main/java/org/apache/calcite/tools/Frameworks.java 
b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
index 92e0e5c4cd..8ffba396fa 100644
--- a/core/src/main/java/org/apache/calcite/tools/Frameworks.java
+++ b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
@@ -62,7 +62,7 @@ public class Frameworks {
 
   /** Caches an instance of the JDBC driver. */
   private static final Supplier<Driver> DRIVER_SUPPLIER =
-      Suppliers.memoize(Driver::new)::get;
+      Suppliers.memoize(Driver::new);
 
   private Frameworks() {
   }
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java 
b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index a0f4116523..b3eead1cf2 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -157,6 +157,8 @@ import java.util.function.Function;
 import java.util.function.UnaryOperator;
 import java.util.stream.Collectors;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static 
org.apache.calcite.rel.rules.AggregateRemoveRule.canFlattenStatic;
 import static org.apache.calcite.sql.SqlKind.UNION;
@@ -2345,8 +2347,8 @@ public class RelBuilder {
                 new AggCallImpl2(aggregateCall,
                     aggregateCall.getArgList().stream()
                         .map(this::field)
-                        .collect(Util.toImmutableList())))
-            .collect(Util.toImmutableList()));
+                        .collect(toImmutableList())))
+            .collect(toImmutableList()));
   }
 
   /** Creates an {@link Aggregate} with multiple calls. */
@@ -2642,7 +2644,7 @@ public class RelBuilder {
         Aggregate.deriveRowType(getTypeFactory(), peek().getRowType(), false,
             groupSet, groupSets.asList(),
             aggregateCalls.stream().map(AggCallPlus::aggregateCall)
-                .collect(Util.toImmutableList())).getFieldNames();
+                .collect(toImmutableList())).getFieldNames();
 
     // If n duplicates exist for a particular grouping, the {@code GROUP_ID()}
     // function produces values in the range 0 to n-1. For each value,
@@ -4226,7 +4228,7 @@ public class RelBuilder {
       if (aggFunction instanceof SqlCountAggFunction && !distinct) {
         args = args.stream()
             .filter(r::fieldIsNullable)
-            .collect(Util.toImmutableList());
+            .collect(toImmutableList());
       }
 
       return AggregateCall.create(aggFunction, distinct, approximate,
diff --git a/core/src/main/java/org/apache/calcite/util/Compatible.java 
b/core/src/main/java/org/apache/calcite/util/Compatible.java
index 3771080e31..924621d2f9 100644
--- a/core/src/main/java/org/apache/calcite/util/Compatible.java
+++ b/core/src/main/java/org/apache/calcite/util/Compatible.java
@@ -16,14 +16,11 @@
  */
 package org.apache.calcite.util;
 
-import com.google.common.collect.ImmutableMap;
-
 import java.lang.invoke.MethodHandles;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.Map;
 
 import static java.util.Objects.requireNonNull;
 
@@ -39,15 +36,6 @@ public interface Compatible {
    * (On JDK 8, only {@link MethodHandles#lookup()} is available. */
   <T> MethodHandles.Lookup lookupPrivate(Class<T> clazz);
 
-  /** Same behavior as {@link ImmutableMap#copyOf},
-   * available from Guava 19.0. */
-  static <K, V> ImmutableMap<K, V> copyOf(
-      Iterable<? extends Map.Entry<? extends K, ? extends V>> entries) {
-    final ImmutableMap.Builder<K, V> b = ImmutableMap.builder();
-    entries.forEach(b::put);
-    return b.build();
-  }
-
   /** Creates the implementation of Compatible suitable for the
    * current environment. */
   class Factory {
diff --git a/core/src/main/java/org/apache/calcite/util/Util.java 
b/core/src/main/java/org/apache/calcite/util/Util.java
index eb90797400..2beda0a1a4 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -40,7 +40,6 @@ import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
 
 import org.apiguardian.api.API;
 import org.checkerframework.checker.nullness.qual.Nullable;
@@ -925,25 +924,10 @@ public class Util {
     return new AssertionError("Internal error: " + s, e);
   }
 
-  /** Until we upgrade to Guava 19. */
-  @CanIgnoreReturnValue
-  public static <T> T verifyNotNull(@Nullable T reference) {
-    Bug.upgrade("Remove when minimum Guava version is 17");
-    return requireNonNull(reference, "expected a non-null reference");
-  }
-
-  /** As {@link Throwables}{@code .throwIfUnchecked(Throwable)},
-   * which was introduced in Guava 20,
-   * but we don't require Guava version 20 yet. */
+  /** As {@link Throwables#throwIfUnchecked(Throwable)}. */
+  @Deprecated // to be removed before 2.0
   public static void throwIfUnchecked(Throwable throwable) {
-    Bug.upgrade("Remove when minimum Guava version is 20");
-    requireNonNull(throwable, "throwable");
-    if (throwable instanceof RuntimeException) {
-      throw (RuntimeException) throwable;
-    }
-    if (throwable instanceof Error) {
-      throw (Error) throwable;
-    }
+    Throwables.throwIfUnchecked(throwable);
   }
 
   /**
@@ -959,7 +943,7 @@ public class Util {
    */
   @API(since = "1.26", status = API.Status.EXPERIMENTAL)
   public static RuntimeException throwAsRuntime(Throwable throwable) {
-    throwIfUnchecked(throwable);
+    Throwables.throwIfUnchecked(throwable);
     throw new RuntimeException(throwable);
   }
 
@@ -2616,22 +2600,11 @@ public class Util {
    * Returns a {@code Collector} that accumulates the input elements into a
    * Guava {@link ImmutableList} via a {@link ImmutableList.Builder}.
    *
-   * <p>It will be obsolete when we move to {@link Bug#upgrade Guava 28.0-jre}.
-   * Guava 21.0 introduced {@code ImmutableList.toImmutableList()}, but it had
-   * a {@link com.google.common.annotations.Beta} tag until 28.0-jre.
-   *
-   * <p>In {@link Bug#upgrade Guava 21.0}, change this method to call
-   * {@code ImmutableList.toImmutableList()}, ignoring the {@code @Beta} tag.
-   *
-   * @param <T> Type of the input elements
-   *
-   * @return a {@code Collector} that collects all the input elements into an
-   * {@link ImmutableList}, in encounter order
+   * @deprecated Use {@link ImmutableList#toImmutableList()}
    */
-  public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>>
-      toImmutableList() {
-    return Collector.of(ImmutableList::builder, ImmutableList.Builder::add, 
Util::combine,
-        ImmutableList.Builder::build);
+  @Deprecated // to be removed before 2.0
+  public static <T> Collector<T, ?, ImmutableList<T>> toImmutableList() {
+    return ImmutableList./* do not simplify. */toImmutableList();
   }
 
   /** Combines a second immutable list builder into a first. */
diff --git 
a/core/src/test/java/org/apache/calcite/materialize/LatticeSuggesterTest.java 
b/core/src/test/java/org/apache/calcite/materialize/LatticeSuggesterTest.java
index 077d3285b0..db5af56417 100644
--- 
a/core/src/test/java/org/apache/calcite/materialize/LatticeSuggesterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/materialize/LatticeSuggesterTest.java
@@ -55,6 +55,8 @@ import java.util.List;
 import java.util.function.UnaryOperator;
 import java.util.stream.Collectors;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.hamcrest.CoreMatchers.allOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -470,7 +472,7 @@ class LatticeSuggesterTest {
         lattice.tables().stream().map(table ->
             table.t.getQualifiedName())
             .sorted(Comparator.comparing(Object::toString))
-            .collect(Util.toImmutableList());
+            .collect(toImmutableList());
     assertThat(tableNames,
         hasToString("[[foodmart, customer],"
             + " [foodmart, product],"
diff --git a/core/src/test/java/org/apache/calcite/profile/ProfilerTest.java 
b/core/src/test/java/org/apache/calcite/profile/ProfilerTest.java
index 5bafb93fe3..c1504b4820 100644
--- a/core/src/test/java/org/apache/calcite/profile/ProfilerTest.java
+++ b/core/src/test/java/org/apache/calcite/profile/ProfilerTest.java
@@ -24,7 +24,6 @@ import org.apache.calcite.test.Matchers;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.JsonBuilder;
 import org.apache.calcite.util.TestUtil;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
@@ -52,6 +51,8 @@ import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasToString;
@@ -541,7 +542,7 @@ class ProfilerTest {
                   p.profile(rows, columns, initialGroups);
               final List<Profiler.Statistic> statistics =
                   profile.statistics().stream().filter(predicate)
-                      .collect(Util.toImmutableList());
+                      .collect(toImmutableList());
 
               // If no comparator specified, use the function that converts to
               // JSON strings
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 04408f347e..37b0a477fb 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -131,6 +131,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.locks.ReentrantLock;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.apache.calcite.test.Matchers.hasFieldNames;
 import static org.apache.calcite.test.Matchers.isAlmost;
 import static org.apache.calcite.test.Matchers.sortsAs;
@@ -3398,7 +3400,7 @@ public class RelMetadataTest {
   /** Converts a Map to a sorted list of its entries. */
   static <K, V> List<String> toSortedStringList(Map<K, V> map) {
     return map.entrySet().stream().map(Object::toString)
-        .sorted().collect(Util.toImmutableList());
+        .sorted().collect(toImmutableList());
   }
 
   /** Test case for
diff --git a/core/src/test/java/org/apache/calcite/util/RangeSetTest.java 
b/core/src/test/java/org/apache/calcite/util/RangeSetTest.java
index 76dab211a4..9ac799a90f 100644
--- a/core/src/test/java/org/apache/calcite/util/RangeSetTest.java
+++ b/core/src/test/java/org/apache/calcite/util/RangeSetTest.java
@@ -213,11 +213,11 @@ class RangeSetTest {
 
     // Ranges are merged correctly.
     final ImmutableRangeSet<BigDecimal> rangeSet =
-        unionRangeSet(asList(range01point, range12));
+        ImmutableRangeSet.unionOf(asList(range01point, range12));
     final ImmutableRangeSet<BigDecimal> rangeSet2 =
-        unionRangeSet(asList(range01, range12));
+        ImmutableRangeSet.unionOf(asList(range01, range12));
     final ImmutableRangeSet<BigDecimal> rangeSet3 =
-        unionRangeSet(asList(range01, range1point2));
+        ImmutableRangeSet.unionOf(asList(range01, range1point2));
     assertThat(rangeSet.asRanges(), hasSize(1));
     assertThat(rangeSet, is(rangeSet2));
     assertThat(rangeSet, is(rangeSet3));
@@ -262,18 +262,6 @@ class RangeSetTest {
     assertThat(g2.apply(Range.closed(onePoint, two)), 
isRangeSet("[[2.0..4]]"));
   }
 
-  /** Equivalent to {@link ImmutableRangeSet#unionOf(Iterable)}, which was only
-   * added in Guava 21. */
-  @SuppressWarnings("unchecked")
-  private static <C extends Comparable<C>> ImmutableRangeSet<C> unionRangeSet(
-      List<? extends Range<C>> ranges) {
-    final TreeRangeSet<C> treeRangeSet = TreeRangeSet.create();
-    for (Range<C> range : ranges) {
-      treeRangeSet.add(range);
-    }
-    return ImmutableRangeSet.copyOf(treeRangeSet);
-  }
-
   /** Tests {@link RangeSets#isOpenInterval(RangeSet)}. */
   @Test void testRangeSetIsOpenInterval() {
     final RangeSet<Integer> setGt0 = 
ImmutableRangeSet.of(Range.greaterThan(0));
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java 
b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 7ac03ca622..78deae0229 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -1048,7 +1048,7 @@ class UtilTest {
 
     final List<Pair<String, Integer>> pairs =
         Pair.zip(strings, integers, false);
-    final Map<String, Integer> map = Compatible.copyOf(pairs);
+    final Map<String, Integer> map = ImmutableMap.copyOf(pairs);
 
     // shorter list on the right
     final AtomicInteger size = new AtomicInteger();
diff --git a/gradle.properties b/gradle.properties
index f161b2efa2..ed5aae6522 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -79,7 +79,7 @@ errorprone.version=2.5.1
 # The property is used in https://github.com/wildfly/jandex regression 
testing, so avoid renaming
 jandex.version=2.2.3.Final
 
-# We support Guava versions as old as 16.0.1 but prefer more recent versions.
+# We support Guava versions as old as 21.0 but prefer more recent versions.
 # elasticsearch does not like asm:6.2.1+
 aggdesigner-algorithm.version=6.0
 apiguardian-api.version=1.1.2
@@ -110,7 +110,7 @@ foodmart-data-hsqldb.version=0.5
 foodmart-data-json.version=0.4
 foodmart-queries.version=0.4.1
 geode-core.version=1.15.1
-guava.version=19.0
+guava.version=32.1.3-jre
 h2.version=2.1.210
 hadoop.version=2.7.5
 hamcrest-date.version=2.0.4
diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
index 851c0d40d3..3d2c141574 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
@@ -34,7 +34,6 @@ import 
org.apache.calcite.linq4j.function.NullableLongFunction1;
 import org.apache.calcite.linq4j.function.Predicate1;
 import org.apache.calcite.linq4j.function.Predicate2;
 
-import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.HashMultiset;
 import com.google.common.collect.ImmutableList;
@@ -67,6 +66,7 @@ import java.util.Objects;
 import java.util.RandomAccess;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.function.Supplier;
 
 import static org.apache.calcite.linq4j.Linq4j.CollectionEnumerable;
 import static org.apache.calcite.linq4j.Linq4j.ListEnumerable;
diff --git a/site/_docs/history.md b/site/_docs/history.md
index 481bf5a512..8aa9fdbd36 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -45,7 +45,7 @@ z.
 
 Compatibility: This release is tested on Linux, macOS, Microsoft Windows;
 using JDK/OpenJDK versions 8 to 19;
-Guava versions 16.0.1 to 31.1-jre;
+Guava versions 21.0 to 32.1.3-jre;
 other software versions as specified in gradle.properties.
 
 #### New features
@@ -950,7 +950,7 @@ Zhengqiang Duan.
 
 Compatibility: This release is tested on Linux, macOS, Microsoft Windows;
 using JDK/OpenJDK versions 8 to 18;
-Guava versions 19.0 to 31.1-jre;
+Guava versions 16.0.1 to 31.1-jre;
 other software versions as specified in gradle.properties.
 
 #### New features
diff --git 
a/testkit/src/main/java/org/apache/calcite/sql/test/SqlTestFactory.java 
b/testkit/src/main/java/org/apache/calcite/sql/test/SqlTestFactory.java
index 238ace00c0..86476b5ef6 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/test/SqlTestFactory.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/test/SqlTestFactory.java
@@ -120,10 +120,10 @@ public class SqlTestFactory {
     this.typeSystemTransform = typeSystemTransform;
     this.typeFactorySupplier = Suppliers.memoize(() ->
         typeFactoryFactory.create(validatorConfig.conformance(),
-            typeSystemTransform.apply(RelDataTypeSystem.DEFAULT)))::get;
+            typeSystemTransform.apply(RelDataTypeSystem.DEFAULT)));
     this.catalogReaderSupplier = Suppliers.memoize(() ->
         catalogReaderFactory.create(this.typeFactorySupplier.get(),
-            parserConfig.caseSensitive()))::get;
+            parserConfig.caseSensitive()));
     this.parserConfig = parserConfig;
     this.validatorConfig = validatorConfig;
   }
diff --git a/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java 
b/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
index 87a1d75a0b..9e204bcef7 100644
--- a/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
+++ b/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
@@ -1745,7 +1745,19 @@ public class CalciteAssert {
     @Deprecated // to be removed before 2.0
     public final AssertQuery queryContains(
         com.google.common.base.Function<List, Void> predicate1) {
-      return queryContains((Consumer<List>) predicate1::apply);
+      return queryContains(functionConsumer(predicate1));
+    }
+
+    /** Converts a Guava function into a JDK consumer. */
+    @SuppressWarnings("Guava")
+    private static <T, R> Consumer<T> functionConsumer(
+        com.google.common.base.Function<T, R> handler) {
+      return t -> {
+        // Squash ErrorProne warnings that the return of the function is not
+        // used.
+        R r = handler.apply(t);
+        Util.discard(r);
+      };
     }
 
     /** Sets a limit on the number of rows returned. -1 means no limit. */
diff --git a/testkit/src/main/java/org/apache/calcite/test/Matchers.java 
b/testkit/src/main/java/org/apache/calcite/test/Matchers.java
index 3a3648be1a..4a7b448155 100644
--- a/testkit/src/main/java/org/apache/calcite/test/Matchers.java
+++ b/testkit/src/main/java/org/apache/calcite/test/Matchers.java
@@ -49,6 +49,8 @@ import java.util.function.Function;
 import java.util.regex.Pattern;
 import java.util.stream.StreamSupport;
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import static org.hamcrest.CoreMatchers.equalTo;
 
 /**
@@ -137,7 +139,7 @@ public class Matchers {
   private static <E> Iterable<String> toStringList(Iterable<E> items) {
     return StreamSupport.stream(items.spliterator(), false)
         .map(Object::toString)
-        .collect(Util.toImmutableList());
+        .collect(toImmutableList());
   }
 
   /**
diff --git a/testkit/src/main/java/org/apache/calcite/util/TestUtil.java 
b/testkit/src/main/java/org/apache/calcite/util/TestUtil.java
index a313fbd604..a661f8d4d6 100644
--- a/testkit/src/main/java/org/apache/calcite/util/TestUtil.java
+++ b/testkit/src/main/java/org/apache/calcite/util/TestUtil.java
@@ -55,7 +55,7 @@ public abstract class TestUtil {
       System.getProperties().getProperty("java.version");
 
   private static final Supplier<Integer> GUAVA_MAJOR_VERSION =
-      Suppliers.memoize(TestUtil::computeGuavaMajorVersion)::get;
+      Suppliers.memoize(TestUtil::computeGuavaMajorVersion);
 
   /** Matches a number with at least four zeros after the point. */
   private static final Pattern TRAILING_ZERO_PATTERN =

Reply via email to