From 4bf9f8822276604ccd0f98a3ed09861a6c8a89dc Mon Sep 17 00:00:00 2001 From: Ulrich Kramer Date: Thu, 19 Dec 2024 10:06:54 +0100 Subject: [PATCH] [CALCITE-6728] Introduce new methods to lookup tables and schemas inside schemas --- .../calcite/schema/lookup/CachedLookupTest.java | 3 +++ .../calcite/schema/lookup/ConcatLookupTest.java | 3 +++ .../calcite/schema/lookup/IgnoreCaseLookupTest.java | 3 +++ .../schema/lookup/LoadingCacheLookupTest.java | 3 +++ .../org/apache/calcite/schema/lookup/MapLookup.java | 13 +++++++++---- .../calcite/schema/lookup/MappedLookupTest.java | 4 +++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/CachedLookupTest.java b/core/src/test/java/org/apache/calcite/schema/lookup/CachedLookupTest.java index 36fe73986a39..ec7f8d3f5e09 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/CachedLookupTest.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/CachedLookupTest.java @@ -22,6 +22,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +/** + * Test for CachedLookup. + */ class CachedLookupTest { private final Lookup testee = new CachedLookup<>(new MapLookup("a", "1")); diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/ConcatLookupTest.java b/core/src/test/java/org/apache/calcite/schema/lookup/ConcatLookupTest.java index 1d52e68fb251..e84ea3f8b3fa 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/ConcatLookupTest.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/ConcatLookupTest.java @@ -22,6 +22,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +/** + * Test for ConcatLookup. + */ class ConcatLookupTest { private final Lookup testee = Lookup.concat(new MapLookup("a", "1"), new MapLookup("b", "2")); diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/IgnoreCaseLookupTest.java b/core/src/test/java/org/apache/calcite/schema/lookup/IgnoreCaseLookupTest.java index d754b2e6576f..95aef8473888 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/IgnoreCaseLookupTest.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/IgnoreCaseLookupTest.java @@ -26,6 +26,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +/** + * Test for IgnoreCaseLookup. + */ class IgnoreCaseLookupTest { private final Lookup testee = new IgnoreCaseLookup() { @Override public @Nullable String get(final String name) { diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/LoadingCacheLookupTest.java b/core/src/test/java/org/apache/calcite/schema/lookup/LoadingCacheLookupTest.java index 8e3c896f0bdf..0d5e6f1e146e 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/LoadingCacheLookupTest.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/LoadingCacheLookupTest.java @@ -22,6 +22,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +/** + * Test for LoadingCacheLookup. + */ public class LoadingCacheLookupTest { private final Lookup testee = diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/MapLookup.java b/core/src/test/java/org/apache/calcite/schema/lookup/MapLookup.java index adc6f523f65e..5150c429a8ba 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/MapLookup.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/MapLookup.java @@ -19,23 +19,28 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +/** + * Simple test class for Lookup. + */ class MapLookup implements Lookup { private final Map map; private final Map> ignoreCaseMap; - public MapLookup(String... keyAndValues) { + MapLookup(String... keyAndValues) { this.map = new HashMap<>(); for (int i = 0; i < keyAndValues.length - 1; i += 2) { map.put(keyAndValues[i], keyAndValues[i + 1]); } this.ignoreCaseMap = this.map.entrySet().stream() .collect( - Collectors.toMap(entry -> entry.getKey().toLowerCase(), - entry -> new Named<>(entry.getKey(), entry.getValue()))); + Collectors.toMap( + entry -> entry.getKey().toLowerCase(Locale.ROOT), + entry -> new Named<>(entry.getKey(), entry.getValue()))); } @Override public @Nullable String get(final String name) { @@ -43,7 +48,7 @@ public MapLookup(String... keyAndValues) { } @Override public @Nullable Named getIgnoreCase(final String name) { - return ignoreCaseMap.get(name.toLowerCase()); + return ignoreCaseMap.get(name.toLowerCase(Locale.ROOT)); } @Override public Set getNames(final LikePattern pattern) { diff --git a/core/src/test/java/org/apache/calcite/schema/lookup/MappedLookupTest.java b/core/src/test/java/org/apache/calcite/schema/lookup/MappedLookupTest.java index dbb1d53f3b66..f68407d0c35f 100644 --- a/core/src/test/java/org/apache/calcite/schema/lookup/MappedLookupTest.java +++ b/core/src/test/java/org/apache/calcite/schema/lookup/MappedLookupTest.java @@ -21,8 +21,10 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.jupiter.api.Assertions.*; +/** + * Test for MappedLookup. + */ class MappedLookupTest { private final Lookup testee = (new MapLookup("a", "1")).map((value, name) -> name + "_" + value);