Skip to content

Commit

Permalink
[CALCITE-6728] Introduce new methods to lookup tables and schemas ins…
Browse files Browse the repository at this point in the history
…ide schemas
  • Loading branch information
kramerul committed Dec 19, 2024
1 parent 6254be3 commit 1e2c85e
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

/**
* This class can be used to cache lookups.
Expand All @@ -42,24 +43,10 @@ public LoadingCacheLookup(Lookup<T> delegate) {
this.delegate = delegate;
this.cache = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.build(
CacheLoader.from(name -> {
T result = delegate.get(name);
if (result != null) {
return result;
}
throw new EntryNotFoundException();
}));
.build(new NullSafeCacheLoader<String, T>(delegate::get));

Check failure on line 46 in core/src/main/java/org/apache/calcite/schema/lookup/LoadingCacheLookup.java

View workflow job for this annotation

GitHub Actions / CheckerFramework (JDK 11)

[Task :core:compileJava] [type.argument.type.incompatible] incompatible type argument for type parameter V1 extends @initialized @nonnull Object of build. .build(new NullSafeCacheLoader<String, T>(delegate::get)); ^ found : T extends @initialized @nullable Object

Check failure on line 46 in core/src/main/java/org/apache/calcite/schema/lookup/LoadingCacheLookup.java

View workflow job for this annotation

GitHub Actions / CheckerFramework (JDK 11, oldest Guava)

[Task :core:compileJava] [type.argument.type.incompatible] incompatible type argument for type parameter V1 extends @initialized @nonnull Object of build. .build(new NullSafeCacheLoader<String, T>(delegate::get)); ^ found : T extends @initialized @nullable Object
this.cacheIgnoreCase = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.build(
CacheLoader.from(name -> {
Named<T> result = delegate.getIgnoreCase(name);
if (result != null) {
return result;
}
throw new EntryNotFoundException();
}));
.build(new NullSafeCacheLoader<>(delegate::getIgnoreCase));
}

@Override public @Nullable T get(String name) {
Expand Down Expand Up @@ -92,4 +79,25 @@ public LoadingCacheLookup(Lookup<T> delegate) {
return delegate.getNames(pattern);
}

/**
* CacheLoader which doesn't return null values.
*
* @param <K> Key
* @param <V> Value
*/
private static class NullSafeCacheLoader<K, V> extends CacheLoader<K, V> {
private final Function<K, @Nullable V> function;

NullSafeCacheLoader(Function<K, @Nullable V> function) {
this.function = function;
}

@Override public V load(final K key) {
V result = function.apply(key);
if (result != null) {
return result;
}
throw new EntryNotFoundException();
}
}
}

0 comments on commit 1e2c85e

Please sign in to comment.