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 f903143af1 [CALCITE-5428] Drop minimum Guava version to 16.0.1
f903143af1 is described below
commit f903143af16f6e1ef26641e5f1d801c8aa8e4589
Author: Gian Merlino <[email protected]>
AuthorDate: Fri Dec 9 13:24:07 2022 -0800
[CALCITE-5428] Drop minimum Guava version to 16.0.1
Close apache/calcite#2999
Co-authored-by: Julian Hyde <[email protected]>
---
.github/workflows/main.yml | 2 +-
.../org/apache/calcite/config/CalciteSystemProperty.java | 15 +++++++++++++--
.../src/main/java/org/apache/calcite/rex/RexAnalyzer.java | 4 ++--
core/src/main/java/org/apache/calcite/rex/RexBuilder.java | 3 +--
.../src/main/java/org/apache/calcite/util/Compatible.java | 12 ++++++++++++
core/src/main/java/org/apache/calcite/util/Util.java | 14 ++++++++++++--
core/src/test/java/org/apache/calcite/util/UtilTest.java | 2 +-
gradle.properties | 2 +-
site/_docs/history.md | 2 +-
9 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 6f0f9f4844..abb8e43527 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -119,7 +119,7 @@ jobs:
runs-on: ubuntu-latest
env:
TZ: 'America/New_York' # flips between −05:00 and −04:00
- GUAVA: '19.0' # oldest supported Guava version
+ GUAVA: '16.0.1' # oldest supported Guava version
steps:
- uses: actions/checkout@v3
with:
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 0b92204247..5426980c11 100644
--- a/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
+++ b/core/src/main/java/org/apache/calcite/config/CalciteSystemProperty.java
@@ -16,7 +16,6 @@
*/
package org.apache.calcite.config;
-import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -30,6 +29,7 @@ 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 java.util.Objects.requireNonNull;
@@ -425,9 +425,20 @@ 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 = MoreObjects.firstNonNull(
+ ClassLoader classLoader = firstNonEmpty(
Thread.currentThread().getContextClassLoader(),
CalciteSystemProperty.class.getClassLoader());
// Read properties from the file "saffron.properties", if it exists in
classpath
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 9d46f83da4..733288b7d5 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;
@@ -59,7 +59,7 @@ public class RexAnalyzer {
.collect(Util.toImmutableList());
final Iterable<List<Comparable>> product = Linq4j.product(generators);
return Util.transform(product,
- values -> ImmutableMap.copyOf(Pair.zip(variables, values)));
+ values -> Compatible.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 b8a961d9ba..c780e344f3 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -75,9 +75,8 @@ import java.util.Objects;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
-import static com.google.common.base.Verify.verifyNotNull;
-
import static org.apache.calcite.linq4j.Nullness.castNonNull;
+import static org.apache.calcite.util.Util.verifyNotNull;
/**
* Factory for row expressions.
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 924621d2f9..3771080e31 100644
--- a/core/src/main/java/org/apache/calcite/util/Compatible.java
+++ b/core/src/main/java/org/apache/calcite/util/Compatible.java
@@ -16,11 +16,14 @@
*/
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;
@@ -36,6 +39,15 @@ 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 fe771cb2c5..a50dfd861d 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -40,6 +40,7 @@ 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;
@@ -114,6 +115,8 @@ import java.util.stream.Collector;
import static org.apache.calcite.linq4j.Nullness.castNonNull;
+import static java.util.Objects.requireNonNull;
+
/**
* Miscellaneous utility functions.
*/
@@ -919,12 +922,19 @@ 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. */
public static void throwIfUnchecked(Throwable throwable) {
Bug.upgrade("Remove when minimum Guava version is 20");
- Objects.requireNonNull(throwable, "throwable");
+ requireNonNull(throwable, "throwable");
if (throwable instanceof RuntimeException) {
throw (RuntimeException) throwable;
}
@@ -1560,7 +1570,7 @@ public class Util {
}
private static int groupAsInt(Matcher matcher, int index) {
- String value = Objects.requireNonNull(
+ String value = requireNonNull(
matcher.group(index),
() -> "no group for index " + index + ", matcher " + matcher);
return Integer.parseInt(value);
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 f4ac8e0db4..ffef53867f 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -986,7 +986,7 @@ class UtilTest {
final List<Pair<String, Integer>> pairs =
Pair.zip(strings, integers, false);
- final Map<String, Integer> map = ImmutableMap.copyOf(pairs);
+ final Map<String, Integer> map = Compatible.copyOf(pairs);
// shorter list on the right
final AtomicInteger size = new AtomicInteger();
diff --git a/gradle.properties b/gradle.properties
index 6fa238f5c0..b8de08d7be 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -74,7 +74,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 19.0 but prefer more recent versions.
+# We support Guava versions as old as 16.0.1 but prefer more recent versions.
# elasticsearch does not like asm:6.2.1+
aggdesigner-algorithm.version=6.0
apiguardian-api.version=1.1.2
diff --git a/site/_docs/history.md b/site/_docs/history.md
index 7f88f7b7fb..586abb1d33 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -50,7 +50,7 @@ z.
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