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 32e5c08 commit 4bf9f88
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
* Test for CachedLookup.
*/
class CachedLookupTest {
private final Lookup<String> testee = new CachedLookup<>(new MapLookup("a", "1"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
* Test for ConcatLookup.
*/
class ConcatLookupTest {
private final Lookup<String> testee =
Lookup.concat(new MapLookup("a", "1"), new MapLookup("b", "2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
* Test for IgnoreCaseLookup.
*/
class IgnoreCaseLookupTest {
private final Lookup<String> testee = new IgnoreCaseLookup<String>() {
@Override public @Nullable String get(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> testee =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,36 @@
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<String> {
private final Map<String, String> map;
private final Map<String, Named<String>> 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) {
return map.get(name);
}

@Override public @Nullable Named<String> getIgnoreCase(final String name) {
return ignoreCaseMap.get(name.toLowerCase());
return ignoreCaseMap.get(name.toLowerCase(Locale.ROOT));
}

@Override public Set<String> getNames(final LikePattern pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> testee =
(new MapLookup("a", "1")).map((value, name) -> name + "_" + value);
Expand Down

0 comments on commit 4bf9f88

Please sign in to comment.