http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/Matchers.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/Matchers.java b/core/src/test/java/org/apache/calcite/test/Matchers.java index 5ea3a4e..0b5e6bd 100644 --- a/core/src/test/java/org/apache/calcite/test/Matchers.java +++ b/core/src/test/java/org/apache/calcite/test/Matchers.java @@ -20,10 +20,7 @@ import org.apache.calcite.plan.RelOptUtil; import org.apache.calcite.rel.RelNode; import org.apache.calcite.util.Util; -import com.google.common.base.Function; -import com.google.common.base.Functions; import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import org.hamcrest.BaseMatcher; @@ -37,9 +34,12 @@ import org.hamcrest.core.Is; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.function.Function; +import java.util.stream.StreamSupport; /** * Matchers for testing SQL queries. @@ -74,7 +74,7 @@ public class Matchers { } protected boolean matchesSafely(ResultSet resultSet) { - final List<String> actualList = Lists.newArrayList(); + final List<String> actualList = new ArrayList<>(); try { CalciteAssert.toStringList(resultSet, actualList); resultSet.close(); @@ -119,7 +119,9 @@ public class Matchers { } private static <E> Iterable<String> toStringList(Iterable<E> items) { - return Iterables.transform(items, Functions.toStringFunction()); + return StreamSupport.stream(items.spliterator(), false) + .map(Object::toString) + .collect(Util.toImmutableList()); } /** @@ -156,12 +158,7 @@ public class Matchers { */ @Factory public static Matcher<String> isLinux(final String value) { - return compose(Is.is(value), - new Function<String, String>() { - public String apply(String input) { - return input == null ? null : Util.toLinux(input); - } - }); + return compose(Is.is(value), input -> input == null ? null : Util.toLinux(input)); } /** @@ -171,13 +168,10 @@ public class Matchers { */ @Factory public static Matcher<RelNode> hasTree(final String value) { - return compose(Is.is(value), - new Function<RelNode, String>() { - public String apply(RelNode input) { - // Convert RelNode to a string with Linux line-endings - return Util.toLinux(RelOptUtil.toString(input)); - } - }); + return compose(Is.is(value), input -> { + // Convert RelNode to a string with Linux line-endings + return Util.toLinux(RelOptUtil.toString(input)); + }); } /** @@ -198,12 +192,7 @@ public class Matchers { */ @Factory public static Matcher<String> containsStringLinux(String value) { - return compose(CoreMatchers.containsString(value), - new Function<String, String>() { - public String apply(String input) { - return Util.toLinux(input); - } - }); + return compose(CoreMatchers.containsString(value), Util::toLinux); } /**
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/MaterializationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java index e1b314c..b32ec74 100644 --- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java +++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java @@ -54,7 +54,6 @@ import org.apache.calcite.util.Smalls; import org.apache.calcite.util.TryThreadLocal; import org.apache.calcite.util.mapping.IntPair; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; @@ -69,6 +68,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -84,11 +84,11 @@ import static org.junit.Assert.assertTrue; * and checks that the materialization is used. */ public class MaterializationTest { - private static final Function<ResultSet, Void> CONTAINS_M0 = + private static final Consumer<ResultSet> CONTAINS_M0 = CalciteAssert.checkResultContains( "EnumerableTableScan(table=[[hr, m0]])"); - private static final Function<ResultSet, Void> CONTAINS_LOCATIONS = + private static final Consumer<ResultSet> CONTAINS_LOCATIONS = CalciteAssert.checkResultContains( "EnumerableTableScan(table=[[hr, locations]])"); @@ -184,7 +184,7 @@ public class MaterializationTest { * definition. */ private void checkMaterialize(String materialize, String query) { checkMaterialize(materialize, query, HR_FKUK_MODEL, CONTAINS_M0, - RuleSets.ofList(ImmutableList.<RelOptRule>of())); + RuleSets.ofList(ImmutableList.of())); } /** Checks that a given query can use a materialized view with a given @@ -196,14 +196,14 @@ public class MaterializationTest { /** Checks that a given query can use a materialized view with a given * definition. */ private void checkMaterialize(String materialize, String query, String model, - Function<ResultSet, Void> explainChecker) { + Consumer<ResultSet> explainChecker) { checkMaterialize(materialize, query, model, explainChecker, - RuleSets.ofList(ImmutableList.<RelOptRule>of())); + RuleSets.ofList(ImmutableList.of())); } private void checkMaterialize(String materialize, String query, String model, - Function<ResultSet, Void> explainChecker, final RuleSet rules) { + Consumer<ResultSet> explainChecker, final RuleSet rules) { checkThatMaterialize(materialize, query, "m0", false, model, explainChecker, rules).sameResultWithMaterializationsDisabled(); } @@ -212,7 +212,7 @@ public class MaterializationTest { * definition. */ private CalciteAssert.AssertQuery checkThatMaterialize(String materialize, String query, String name, boolean existing, String model, - Function<ResultSet, Void> explainChecker, final RuleSet rules) { + Consumer<ResultSet> explainChecker, final RuleSet rules) { try (final TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) { MaterializationService.setThreadLocal(); CalciteAssert.AssertQuery that = CalciteAssert.that() @@ -222,12 +222,9 @@ public class MaterializationTest { // Add any additional rules required for the test if (rules.iterator().hasNext()) { - that.withHook(Hook.PLANNER, new Function<RelOptPlanner, Void>() { - public Void apply(RelOptPlanner planner) { - for (RelOptRule rule : rules) { - planner.addRule(rule); - } - return null; + that.withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> { + for (RelOptRule rule : rules) { + planner.addRule(rule); } }); } @@ -1955,7 +1952,7 @@ public class MaterializationTest { HR_FKUK_MODEL, CalciteAssert.checkResultContains( "EnumerableValues(tuples=[[{ 'noname' }]])"), - RuleSets.ofList(ImmutableList.<RelOptRule>of())) + RuleSets.ofList(ImmutableList.of())) .returnsValue("noname"); } @@ -1984,13 +1981,8 @@ public class MaterializationTest { .withMaterializations(HR_FKUK_MODEL, "m0", m) .query(q) - .withHook(Hook.SUB, - new Function<RelNode, Void>() { - public Void apply(RelNode input) { - substitutedNames.add(new TableNameVisitor().run(input)); - return null; - } - }) + .withHook(Hook.SUB, (Consumer<RelNode>) r -> + substitutedNames.add(new TableNameVisitor().run(r))) .enableMaterializations(true) .explainContains("hr, m0"); } catch (Exception e) { @@ -2008,17 +2000,14 @@ public class MaterializationTest { MaterializationService.setThreadLocal(); CalciteAssert.that() .withMaterializations( - HR_FKUK_MODEL, - new Function<JsonBuilder, List<Object>>() { - public List<Object> apply(JsonBuilder builder) { - final Map<String, Object> map = builder.map(); - map.put("table", "locations"); - String sql = "select `deptno` as `empid`, '' as `name`\n" - + "from `emps`"; - final String sql2 = sql.replaceAll("`", "\""); - map.put("sql", sql2); - return ImmutableList.<Object>of(map); - } + HR_FKUK_MODEL, builder -> { + final Map<String, Object> map = builder.map(); + map.put("table", "locations"); + String sql = "select `deptno` as `empid`, '' as `name`\n" + + "from `emps`"; + final String sql2 = sql.replaceAll("`", "\""); + map.put("sql", sql2); + return ImmutableList.of(map); }) .query(q) .enableMaterializations(true) @@ -2228,16 +2217,11 @@ public class MaterializationTest { "m0", "select * from \"emps\" where \"empid\" < 300", "m1", "select * from \"emps\" where \"empid\" < 600") .query(q) - .withHook(Hook.SUB, - new Function<RelNode, Void>() { - public Void apply(RelNode input) { - substitutedNames.add(new TableNameVisitor().run(input)); - return null; - } - }) + .withHook(Hook.SUB, (Consumer<RelNode>) r -> + substitutedNames.add(new TableNameVisitor().run(r))) .enableMaterializations(true) .sameResultWithMaterializationsDisabled(); - Collections.sort(substitutedNames, CASE_INSENSITIVE_LIST_LIST_COMPARATOR); + substitutedNames.sort(CASE_INSENSITIVE_LIST_LIST_COMPARATOR); assertThat(substitutedNames, is(list3(expectedNames))); } } @@ -2273,16 +2257,11 @@ public class MaterializationTest { "m1", "select * from \"emps\" where \"empid\" < 600", "m2", "select * from \"m1\"") .query(q) - .withHook(Hook.SUB, - new Function<RelNode, Void>() { - public Void apply(RelNode input) { - substitutedNames.add(new TableNameVisitor().run(input)); - return null; - } - }) + .withHook(Hook.SUB, (Consumer<RelNode>) r -> + substitutedNames.add(new TableNameVisitor().run(r))) .enableMaterializations(true) .sameResultWithMaterializationsDisabled(); - Collections.sort(substitutedNames, CASE_INSENSITIVE_LIST_LIST_COMPARATOR); + substitutedNames.sort(CASE_INSENSITIVE_LIST_LIST_COMPARATOR); assertThat(substitutedNames, is(list3(expectedNames))); } } @@ -2342,7 +2321,7 @@ public class MaterializationTest { public final Department[] depts = { new Department(10, "Sales", Arrays.asList(emps[0], emps[2], emps[3]), new Location(-122, 38)), - new Department(30, "Marketing", Collections.<Employee>emptyList(), + new Department(30, "Marketing", ImmutableList.of(), new Location(0, 52)), new Department(20, "HR", Collections.singletonList(emps[1]), null), }; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java index df1bffe..663a98e 100644 --- a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java +++ b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java @@ -99,9 +99,6 @@ import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -110,12 +107,10 @@ import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -149,7 +144,7 @@ public class MockCatalogReader extends CalciteCatalogReader { boolean caseSensitive) { super(CalciteSchema.createRootSchema(false, true, DEFAULT_CATALOG), SqlNameMatchers.withCaseSensitive(caseSensitive), - ImmutableList.of(PREFIX, ImmutableList.<String>of()), + ImmutableList.of(PREFIX, ImmutableList.of()), typeFactory, null); } @@ -677,7 +672,7 @@ public class MockCatalogReader extends CalciteCatalogReader { private static List<RelCollation> deduceMonotonicity( Prepare.PreparingTable table) { - final List<RelCollation> collationList = Lists.newArrayList(); + final List<RelCollation> collationList = new ArrayList<>(); // Deduce which fields the table is sorted on. int i = -1; @@ -708,7 +703,7 @@ public class MockCatalogReader extends CalciteCatalogReader { /** Mock schema. */ public static class MockSchema { - private final List<String> tableNames = Lists.newArrayList(); + private final List<String> tableNames = new ArrayList<>(); private String name; public MockSchema(String name) { @@ -744,7 +739,7 @@ public class MockCatalogReader extends CalciteCatalogReader { protected RelDataType rowType; protected List<RelCollation> collationList; protected final List<String> names; - protected final Set<String> monotonicColumnSet = Sets.newHashSet(); + protected final Set<String> monotonicColumnSet = new HashSet<>(); protected StructKind kind = StructKind.FULLY_QUALIFIED; protected final ColumnResolver resolver; protected final InitializerExpressionFactory initializerFactory; @@ -1149,7 +1144,7 @@ public class MockCatalogReader extends CalciteCatalogReader { final ImmutableList.Builder<Pair<String, Schema>> builder = ImmutableList.builder(); for (String name : fromTable.names) { - builder.add(Pair.<String, Schema>of(name, null)); + builder.add(Pair.of(name, null)); } return Schemas.path(builder.build()); } @@ -1404,8 +1399,8 @@ public class MockCatalogReader extends CalciteCatalogReader { /** ColumnResolver implementation that resolves CompoundNameColumn by simulating * Phoenix behaviors. */ private static final class CompoundNameColumnResolver implements ColumnResolver { - private final Map<String, Integer> nameMap = Maps.newHashMap(); - private final Map<String, Map<String, Integer>> groupMap = Maps.newHashMap(); + private final Map<String, Integer> nameMap = new HashMap<>(); + private final Map<String, Map<String, Integer>> groupMap = new HashMap<>(); private final String defaultColumnGroup; CompoundNameColumnResolver( @@ -1415,7 +1410,7 @@ public class MockCatalogReader extends CalciteCatalogReader { nameMap.put(column.e.getName(), column.i); Map<String, Integer> subMap = groupMap.get(column.e.first); if (subMap == null) { - subMap = Maps.newHashMap(); + subMap = new HashMap<>(); groupMap.put(column.e.first, subMap); } subMap.put(column.e.second, column.i); @@ -1478,14 +1473,7 @@ public class MockCatalogReader extends CalciteCatalogReader { if (subMap != null) { List<Map.Entry<String, Integer>> entries = new ArrayList<>(subMap.entrySet()); - Collections.sort( - entries, - new Comparator<Map.Entry<String, Integer>>() { - @Override public int compare( - Entry<String, Integer> o1, Entry<String, Integer> o2) { - return o1.getValue() - o2.getValue(); - } - }); + entries.sort((o1, o2) -> o1.getValue() - o2.getValue()); ret.add( new Pair<RelDataTypeField, List<String>>( new RelDataTypeFieldImpl( @@ -1575,8 +1563,7 @@ public class MockCatalogReader extends CalciteCatalogReader { } @Override public boolean rolledUpColumnValidInsideAgg(String column, - SqlCall call, SqlNode parent, - CalciteConnectionConfig config) { + SqlCall call, SqlNode parent, CalciteConnectionConfig config) { // For testing return call.getKind() != SqlKind.MAX && (parent.getKind() == SqlKind.SELECT || parent.getKind() == SqlKind.FILTER); @@ -1723,11 +1710,7 @@ public class MockCatalogReader extends CalciteCatalogReader { * value. */ public static class CountingFactory extends NullInitializerExpressionFactory { static final ThreadLocal<AtomicInteger> THREAD_CALL_COUNT = - new ThreadLocal<AtomicInteger>() { - protected AtomicInteger initialValue() { - return new AtomicInteger(); - } - }; + ThreadLocal.withInitial(AtomicInteger::new); private final List<String> defaultColumns; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java b/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java index d35c019..77c8427 100644 --- a/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java +++ b/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java @@ -76,7 +76,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner { public List<RelOptRule> getRules() { return rule == null - ? ImmutableList.<RelOptRule>of() : ImmutableList.of(rule); + ? ImmutableList.of() : ImmutableList.of(rule); } public boolean addRule(RelOptRule rule) { @@ -126,7 +126,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner { new MockRuleCall( this, rule.getOperand(), - bindings.toArray(new RelNode[bindings.size()])); + bindings.toArray(new RelNode[0])); if (rule.matches(call)) { rule.onMatch(call); } @@ -229,7 +229,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner { planner, operand, rels, - Collections.<RelNode, List<RelNode>>emptyMap()); + Collections.emptyMap()); } // implement RelOptRuleCall http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java b/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java index a97b1f9..e9c2795 100644 --- a/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java +++ b/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java @@ -32,6 +32,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import javax.sql.DataSource; @@ -159,7 +160,7 @@ public class MultiJdbcSchemaJoinTest { // Run the actual query rs = stmt.executeQuery(query); - Set<Integer> ids = Sets.newHashSet(); + Set<Integer> ids = new HashSet<>(); while (rs.next()) { ids.add(rs.getInt(1)); } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/MutableRelTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/MutableRelTest.java b/core/src/test/java/org/apache/calcite/test/MutableRelTest.java index f99d8c1..a2158f0 100644 --- a/core/src/test/java/org/apache/calcite/test/MutableRelTest.java +++ b/core/src/test/java/org/apache/calcite/test/MutableRelTest.java @@ -77,7 +77,7 @@ public class MutableRelTest { "Calc", "select * from emp where ename = 'DUMMY'", false, - ImmutableList.<RelOptRule>of(FilterToCalcRule.INSTANCE)); + ImmutableList.of(FilterToCalcRule.INSTANCE)); } @Test public void testConvertWindow() { @@ -85,7 +85,7 @@ public class MutableRelTest { "Window", "select sal, avg(sal) over (partition by deptno) from emp", false, - ImmutableList.<RelOptRule>of(ProjectToWindowRule.PROJECT)); + ImmutableList.of(ProjectToWindowRule.PROJECT)); } @Test public void testConvertCollect() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/QuidemTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/QuidemTest.java b/core/src/test/java/org/apache/calcite/test/QuidemTest.java index 20e47b3..e70c7e9 100644 --- a/core/src/test/java/org/apache/calcite/test/QuidemTest.java +++ b/core/src/test/java/org/apache/calcite/test/QuidemTest.java @@ -32,7 +32,6 @@ import org.apache.calcite.util.Bug; import org.apache.calcite.util.Closer; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.io.PatternFilenameFilter; @@ -53,6 +52,7 @@ import java.sql.DriverManager; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.function.Function; import static org.junit.Assert.fail; @@ -70,6 +70,26 @@ public abstract class QuidemTest { this.method = findMethod(path); } + private static Object getEnv(String varName) { + switch (varName) { + case "jdk18": + return System.getProperty("java.version").startsWith("1.8"); + case "fixed": + // Quidem requires a Guava function + return (com.google.common.base.Function<String, Object>) v -> { + switch (v) { + case "calcite1045": + return Bug.CALCITE_1045_FIXED; + case "calcite1048": + return Bug.CALCITE_1048_FIXED; + } + return null; + }; + default: + return null; + } + } + private Method findMethod(String path) { // E.g. path "sql/agg.iq" gives method "testSqlAgg" String methodName = @@ -103,11 +123,7 @@ public abstract class QuidemTest { : "f: " + f.getAbsolutePath() + "; base: " + base; paths.add(f.getAbsolutePath().substring(base.length())); } - return Lists.transform(paths, new Function<String, Object[]>() { - public Object[] apply(String path) { - return new Object[] {path}; - } - }); + return Lists.transform(paths, path -> new Object[] {path}); } protected void checkRun(String path) throws Exception { @@ -136,19 +152,17 @@ public abstract class QuidemTest { try (final Reader reader = Util.reader(inFile); final Writer writer = Util.printWriter(outFile); final Closer closer = new Closer()) { - new Quidem(reader, writer, env(), createConnectionFactory()) - .withPropertyHandler(new Quidem.PropertyHandler() { - public void onSet(String propertyName, Object value) { - if (propertyName.equals("bindable")) { - final boolean b = value instanceof Boolean - && (Boolean) value; - closer.add(Hook.ENABLE_BINDABLE.addThread(Hook.property(b))); - } - if (propertyName.equals("expand")) { - final boolean b = value instanceof Boolean - && (Boolean) value; - closer.add(Prepare.THREAD_EXPAND.push(b)); - } + new Quidem(reader, writer, QuidemTest::getEnv, createConnectionFactory()) + .withPropertyHandler((propertyName, value) -> { + if (propertyName.equals("bindable")) { + final boolean b = value instanceof Boolean + && (Boolean) value; + closer.add(Hook.ENABLE_BINDABLE.addThread(Hook.propertyJ(b))); + } + if (propertyName.equals("expand")) { + final boolean b = value instanceof Boolean + && (Boolean) value; + closer.add(Prepare.THREAD_EXPAND.push(b)); } }) .execute(); @@ -179,31 +193,6 @@ public abstract class QuidemTest { : s; } - private Function<String, Object> env() { - return new Function<String, Object>() { - public Object apply(String varName) { - switch (varName) { - case "jdk18": - return System.getProperty("java.version").startsWith("1.8"); - case "fixed": - return new Function<String, Object>() { - public Object apply(String v) { - switch (v) { - case "calcite1045": - return Bug.CALCITE_1045_FIXED; - case "calcite1048": - return Bug.CALCITE_1048_FIXED; - } - return null; - } - }; - default: - return null; - } - } - }; - } - @Test public void test() throws Exception { if (method != null) { method.invoke(this); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java index b5a256b..824276b 100644 --- a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java +++ b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java @@ -25,7 +25,6 @@ import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.Linq4j; import org.apache.calcite.linq4j.QueryProvider; import org.apache.calcite.linq4j.function.Function1; -import org.apache.calcite.linq4j.function.Predicate1; import org.apache.calcite.linq4j.tree.Expressions; import org.apache.calcite.linq4j.tree.ParameterExpression; import org.apache.calcite.linq4j.tree.Primitive; @@ -37,7 +36,6 @@ import org.apache.calcite.schema.impl.ViewTable; import org.apache.calcite.util.Smalls; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import org.junit.Assert; @@ -104,14 +102,14 @@ public class ReflectiveSchemaTest { "asQueryable"), Employee.class) .where( - Expressions.<Predicate1<Employee>>lambda( + Expressions.lambda( Expressions.lessThan( Expressions.field( e, "empid"), Expressions.constant(160)), e)) .where( - Expressions.<Predicate1<Employee>>lambda( + Expressions.lambda( Expressions.greaterThan( Expressions.field( e, "empid"), @@ -339,105 +337,99 @@ public class ReflectiveSchemaTest { "select " + fn + "(\"" + field.getName() + "\") as c\n" + "from \"s\".\"everyTypes\"") .returns( - new Function<ResultSet, Void>() { - public Void apply(ResultSet input) { - int n = 0; - try { - while (input.next()) { - final Object o = get(input); - Util.discard(o); - ++n; - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - assertThat(n, equalTo(1)); - return null; - } - - private Object get(ResultSet input) throws SQLException { - final int type = input.getMetaData().getColumnType(1); - switch (type) { - case java.sql.Types.BOOLEAN: - return input.getBoolean(1); - case java.sql.Types.TINYINT: - return input.getByte(1); - case java.sql.Types.SMALLINT: - return input.getShort(1); - case java.sql.Types.INTEGER: - return input.getInt(1); - case java.sql.Types.BIGINT: - return input.getLong(1); - case java.sql.Types.REAL: - return input.getFloat(1); - case java.sql.Types.DOUBLE: - return input.getDouble(1); - case java.sql.Types.CHAR: - case java.sql.Types.VARCHAR: - return input.getString(1); - case java.sql.Types.DATE: - return input.getDate(1); - case java.sql.Types.TIME: - return input.getTime(1); - case java.sql.Types.TIMESTAMP: - return input.getTimestamp(1); - default: - throw new AssertionError(type); + input -> { + int n = 0; + try { + while (input.next()) { + final Object o = get(input); + Util.discard(o); + ++n; } + } catch (SQLException e) { + throw new RuntimeException(e); } + assertThat(n, equalTo(1)); }); } } + private Object get(ResultSet input) throws SQLException { + final int type = input.getMetaData().getColumnType(1); + switch (type) { + case java.sql.Types.BOOLEAN: + return input.getBoolean(1); + case java.sql.Types.TINYINT: + return input.getByte(1); + case java.sql.Types.SMALLINT: + return input.getShort(1); + case java.sql.Types.INTEGER: + return input.getInt(1); + case java.sql.Types.BIGINT: + return input.getLong(1); + case java.sql.Types.REAL: + return input.getFloat(1); + case java.sql.Types.DOUBLE: + return input.getDouble(1); + case java.sql.Types.CHAR: + case java.sql.Types.VARCHAR: + return input.getString(1); + case java.sql.Types.DATE: + return input.getDate(1); + case java.sql.Types.TIME: + return input.getTime(1); + case java.sql.Types.TIMESTAMP: + return input.getTimestamp(1); + default: + throw new AssertionError(type); + } + } + @Test public void testClassNames() throws Exception { CalciteAssert.that() .withSchema("s", CATCHALL).query("select * from \"s\".\"everyTypes\"") .returns( - new Function<ResultSet, Void>() { - public Void apply(ResultSet input) { - try { - final ResultSetMetaData metaData = input.getMetaData(); - check(metaData, "primitiveBoolean", Boolean.class); - check(metaData, "primitiveByte", Byte.class); - check(metaData, "primitiveChar", String.class); - check(metaData, "primitiveShort", Short.class); - check(metaData, "primitiveInt", Integer.class); - check(metaData, "primitiveLong", Long.class); - check(metaData, "primitiveFloat", Float.class); - check(metaData, "primitiveDouble", Double.class); - check(metaData, "wrapperBoolean", Boolean.class); - check(metaData, "wrapperByte", Byte.class); - check(metaData, "wrapperCharacter", String.class); - check(metaData, "wrapperShort", Short.class); - check(metaData, "wrapperInteger", Integer.class); - check(metaData, "wrapperLong", Long.class); - check(metaData, "wrapperFloat", Float.class); - check(metaData, "wrapperDouble", Double.class); - check(metaData, "sqlDate", java.sql.Date.class); - check(metaData, "sqlTime", Time.class); - check(metaData, "sqlTimestamp", Timestamp.class); - check(metaData, "utilDate", Timestamp.class); - check(metaData, "string", String.class); - return null; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - private void check(ResultSetMetaData metaData, String columnName, - Class expectedType) throws SQLException { - for (int i = 1; i <= metaData.getColumnCount(); i++) { - if (metaData.getColumnName(i).equals(columnName)) { - assertThat(metaData.getColumnClassName(i), - equalTo(expectedType.getName())); - return; - } - } - Assert.fail("column not found: " + columnName); + resultSet -> { + try { + final ResultSetMetaData metaData = resultSet.getMetaData(); + check(metaData, "primitiveBoolean", Boolean.class); + check(metaData, "primitiveByte", Byte.class); + check(metaData, "primitiveChar", String.class); + check(metaData, "primitiveShort", Short.class); + check(metaData, "primitiveInt", Integer.class); + check(metaData, "primitiveLong", Long.class); + check(metaData, "primitiveFloat", Float.class); + check(metaData, "primitiveDouble", Double.class); + check(metaData, "wrapperBoolean", Boolean.class); + check(metaData, "wrapperByte", Byte.class); + check(metaData, "wrapperCharacter", String.class); + check(metaData, "wrapperShort", Short.class); + check(metaData, "wrapperInteger", Integer.class); + check(metaData, "wrapperLong", Long.class); + check(metaData, "wrapperFloat", Float.class); + check(metaData, "wrapperDouble", Double.class); + check(metaData, "sqlDate", java.sql.Date.class); + check(metaData, "sqlTime", Time.class); + check(metaData, "sqlTimestamp", Timestamp.class); + check(metaData, "utilDate", Timestamp.class); + check(metaData, "string", String.class); + } catch (SQLException e) { + throw new RuntimeException(e); } }); } + private void check(ResultSetMetaData metaData, String columnName, + Class expectedType) throws SQLException { + for (int i = 1; i <= metaData.getColumnCount(); i++) { + if (metaData.getColumnName(i).equals(columnName)) { + assertThat(metaData.getColumnClassName(i), + equalTo(expectedType.getName())); + return; + } + } + Assert.fail("column not found: " + columnName); + } + @Test public void testJavaBoolean() throws Exception { final CalciteAssert.AssertThat with = CalciteAssert.that().withSchema("s", CATCHALL); @@ -553,7 +545,7 @@ public class ReflectiveSchemaTest { + " " + fn + " " + name2 + " as c\n" + "from \"s\".\"everyTypes\"\n" + "where " + name + " <> 0") - .returns(CalciteAssert.<ResultSet, Void>constantNull()); + .returns(resultSet -> { }); } } } @@ -571,23 +563,19 @@ public class ReflectiveSchemaTest { @Test public void testAvgInt() throws Exception { CalciteAssert.that().withSchema("s", CATCHALL).with(Lex.JAVA) .query("select primitiveLong, avg(primitiveInt)\n" - + "from s.everyTypes\n" - + "group by primitiveLong order by primitiveLong") - .returns( - new Function<ResultSet, Void>() { - public Void apply(ResultSet input) { - StringBuilder buf = new StringBuilder(); - try { - while (input.next()) { - buf.append(input.getInt(2)).append("\n"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - assertThat(buf.toString(), equalTo("0\n2147483647\n")); - return null; - } - }); + + "from s.everyTypes\n" + + "group by primitiveLong order by primitiveLong") + .returns(input -> { + StringBuilder buf = new StringBuilder(); + try { + while (input.next()) { + buf.append(input.getInt(2)).append("\n"); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + assertThat(buf.toString(), equalTo("0\n2147483647\n")); + }); } private static boolean isNumeric(Class type) { @@ -836,12 +824,7 @@ public class ReflectiveSchemaTest { static Enumerable<Field> numericFields() { return fields() - .where( - new Predicate1<Field>() { - public boolean apply(Field v1) { - return isNumeric(v1.getType()); - } - }); + .where(v1 -> isNumeric(v1.getType())); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java index 1f166f2..cb87d19 100644 --- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java @@ -1724,7 +1724,7 @@ public class RelBuilderTest { final RelBuilder builder = RelBuilder.create(config().build()); final RelNode root = builder.scan("EMP") - .sortLimit(0, -1, ImmutableList.<RexNode>of()) + .sortLimit(0, -1, ImmutableList.of()) .build(); final String expected = "LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java ---------------------------------------------------------------------- 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 9da50f2..7b090d5 100644 --- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java @@ -21,7 +21,6 @@ import org.apache.calcite.linq4j.tree.Types; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptPlanner; import org.apache.calcite.plan.RelOptPredicateList; -import org.apache.calcite.plan.RelOptSchema; import org.apache.calcite.plan.RelOptTable; import org.apache.calcite.rel.InvalidRelException; import org.apache.calcite.rel.RelCollation; @@ -35,7 +34,6 @@ import org.apache.calcite.rel.RelRoot; import org.apache.calcite.rel.core.Aggregate; import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.Correlate; -import org.apache.calcite.rel.core.CorrelationId; import org.apache.calcite.rel.core.Filter; import org.apache.calcite.rel.core.Join; import org.apache.calcite.rel.core.JoinRelType; @@ -78,7 +76,6 @@ import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexTableInputRef; import org.apache.calcite.rex.RexTableInputRef.RelTableRef; -import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.SqlSpecialOperator; @@ -93,11 +90,9 @@ import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.ImmutableIntList; import org.apache.calcite.util.SaffronProperties; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; @@ -899,7 +894,7 @@ public class RelMetadataTest extends SqlToRelTestBase { final RelMetadataQuery mq = RelMetadataQuery.instance(); Set<ImmutableBitSet> result = mq.getUniqueKeys(rel); assertThat(result, - CoreMatchers.<Set<ImmutableBitSet>>equalTo( + CoreMatchers.equalTo( ImmutableSet.of(ImmutableBitSet.of()))); assertUniqueConsistent(rel); } @@ -909,7 +904,7 @@ public class RelMetadataTest extends SqlToRelTestBase { final RelMetadataQuery mq = RelMetadataQuery.instance(); final Set<ImmutableBitSet> result = mq.getUniqueKeys(rel); assertThat(result, - CoreMatchers.<Set<ImmutableBitSet>>equalTo( + CoreMatchers.equalTo( ImmutableSet.of(ImmutableBitSet.of()))); assertUniqueConsistent(rel); } @@ -920,7 +915,7 @@ public class RelMetadataTest extends SqlToRelTestBase { final RelMetadataQuery mq = RelMetadataQuery.instance(); final Set<ImmutableBitSet> result = mq.getUniqueKeys(rel); assertThat(result, - CoreMatchers.<Set<ImmutableBitSet>>equalTo( + CoreMatchers.equalTo( ImmutableSet.of(ImmutableBitSet.of(0)))); assertUniqueConsistent(rel); } @@ -932,28 +927,25 @@ public class RelMetadataTest extends SqlToRelTestBase { final RelMetadataQuery mq = RelMetadataQuery.instance(); final Set<ImmutableBitSet> result = mq.getUniqueKeys(rel); assertThat(result, - CoreMatchers.<Set<ImmutableBitSet>>equalTo( + CoreMatchers.equalTo( ImmutableSet.of(ImmutableBitSet.of(0)))); assertUniqueConsistent(rel); } @Test public void testBrokenCustomProvider() { - final List<String> buf = Lists.newArrayList(); + final List<String> buf = new ArrayList<>(); ColTypeImpl.THREAD_LIST.set(buf); final String sql = "select deptno, count(*) from emp where deptno > 10 " + "group by deptno having count(*) = 0"; final RelRoot root = tester - .withClusterFactory( - new Function<RelOptCluster, RelOptCluster>() { - public RelOptCluster apply(RelOptCluster cluster) { - cluster.setMetadataProvider( - ChainedRelMetadataProvider.of( - ImmutableList.of(BrokenColTypeImpl.SOURCE, - cluster.getMetadataProvider()))); - return cluster; - } - }) + .withClusterFactory(cluster -> { + cluster.setMetadataProvider( + ChainedRelMetadataProvider.of( + ImmutableList.of(BrokenColTypeImpl.SOURCE, + cluster.getMetadataProvider()))); + return cluster; + }) .convertSqlToRel(sql); final RelNode rel = root.rel; @@ -981,25 +973,22 @@ public class RelMetadataTest extends SqlToRelTestBase { } @Test public void testCustomProvider() { - final List<String> buf = Lists.newArrayList(); + final List<String> buf = new ArrayList<>(); ColTypeImpl.THREAD_LIST.set(buf); final String sql = "select deptno, count(*) from emp where deptno > 10 " + "group by deptno having count(*) = 0"; final RelRoot root = tester - .withClusterFactory( - new Function<RelOptCluster, RelOptCluster>() { - public RelOptCluster apply(RelOptCluster cluster) { - // Create a custom provider that includes ColType. - // Include the same provider twice just to be devious. - final ImmutableList<RelMetadataProvider> list = - ImmutableList.of(ColTypeImpl.SOURCE, ColTypeImpl.SOURCE, - cluster.getMetadataProvider()); - cluster.setMetadataProvider( - ChainedRelMetadataProvider.of(list)); - return cluster; - } - }) + .withClusterFactory(cluster -> { + // Create a custom provider that includes ColType. + // Include the same provider twice just to be devious. + final ImmutableList<RelMetadataProvider> list = + ImmutableList.of(ColTypeImpl.SOURCE, ColTypeImpl.SOURCE, + cluster.getMetadataProvider()); + cluster.setMetadataProvider( + ChainedRelMetadataProvider.of(list)); + return cluster; + }) .convertSqlToRel(sql); final RelNode rel = root.rel; @@ -1056,15 +1045,10 @@ public class RelMetadataTest extends SqlToRelTestBase { final Join join = (Join) rel.getInput(); final RelOptTable empTable = join.getInput(0).getTable(); final RelOptTable deptTable = join.getInput(1).getTable(); - Frameworks.withPlanner( - new Frameworks.PlannerAction<Void>() { - public Void apply(RelOptCluster cluster, - RelOptSchema relOptSchema, - SchemaPlus rootSchema) { - checkCollation(cluster, empTable, deptTable); - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + checkCollation(cluster, empTable, deptTable); + return null; + }); } private void checkCollation(RelOptCluster cluster, RelOptTable empTable, @@ -1130,7 +1114,7 @@ public class RelMetadataTest extends SqlToRelTestBase { // Values (empty) collations = RelMdCollation.values(mq, empTable.getRowType(), - ImmutableList.<ImmutableList<RexLiteral>>of()); + ImmutableList.of()); assertThat(collations.toString(), equalTo("[[0, 1, 2, 3, 4, 5, 6, 7, 8], " + "[1, 2, 3, 4, 5, 6, 7, 8], " @@ -1175,54 +1159,50 @@ public class RelMetadataTest extends SqlToRelTestBase { * {@link org.apache.calcite.rel.metadata.RelMdColumnUniqueness#areColumnsUnique} * applied to {@link Values}. */ @Test public void testColumnUniquenessForValues() { - Frameworks.withPlanner( - new Frameworks.PlannerAction<Void>() { - public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema, - SchemaPlus rootSchema) { - final RexBuilder rexBuilder = cluster.getRexBuilder(); - final RelMetadataQuery mq = RelMetadataQuery.instance(); - final RelDataType rowType = cluster.getTypeFactory().builder() - .add("a", SqlTypeName.INTEGER) - .add("b", SqlTypeName.VARCHAR) - .build(); - final ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = - ImmutableList.builder(); - addRow(tuples, rexBuilder, 1, "X"); - addRow(tuples, rexBuilder, 2, "Y"); - addRow(tuples, rexBuilder, 3, "X"); - addRow(tuples, rexBuilder, 4, "X"); - - final LogicalValues values = - LogicalValues.create(cluster, rowType, tuples.build()); - - final ImmutableBitSet colNone = ImmutableBitSet.of(); - final ImmutableBitSet col0 = ImmutableBitSet.of(0); - final ImmutableBitSet col1 = ImmutableBitSet.of(1); - final ImmutableBitSet colAll = ImmutableBitSet.of(0, 1); - - assertThat(mq.areColumnsUnique(values, col0), is(true)); - assertThat(mq.areColumnsUnique(values, col1), is(false)); - assertThat(mq.areColumnsUnique(values, colAll), is(true)); - assertThat(mq.areColumnsUnique(values, colNone), is(false)); - - // Repeat the above tests directly against the handler. - final RelMdColumnUniqueness handler = - (RelMdColumnUniqueness) RelMdColumnUniqueness.SOURCE - .handlers(BuiltInMetadata.ColumnUniqueness.DEF) - .get(BuiltInMethod.COLUMN_UNIQUENESS.method) - .iterator().next(); - assertThat(handler.areColumnsUnique(values, mq, col0, false), - is(true)); - assertThat(handler.areColumnsUnique(values, mq, col1, false), - is(false)); - assertThat(handler.areColumnsUnique(values, mq, colAll, false), - is(true)); - assertThat(handler.areColumnsUnique(values, mq, colNone, false), - is(false)); - - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + final RexBuilder rexBuilder = cluster.getRexBuilder(); + final RelMetadataQuery mq = RelMetadataQuery.instance(); + final RelDataType rowType = cluster.getTypeFactory().builder() + .add("a", SqlTypeName.INTEGER) + .add("b", SqlTypeName.VARCHAR) + .build(); + final ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = + ImmutableList.builder(); + addRow(tuples, rexBuilder, 1, "X"); + addRow(tuples, rexBuilder, 2, "Y"); + addRow(tuples, rexBuilder, 3, "X"); + addRow(tuples, rexBuilder, 4, "X"); + + final LogicalValues values = + LogicalValues.create(cluster, rowType, tuples.build()); + + final ImmutableBitSet colNone = ImmutableBitSet.of(); + final ImmutableBitSet col0 = ImmutableBitSet.of(0); + final ImmutableBitSet col1 = ImmutableBitSet.of(1); + final ImmutableBitSet colAll = ImmutableBitSet.of(0, 1); + + assertThat(mq.areColumnsUnique(values, col0), is(true)); + assertThat(mq.areColumnsUnique(values, col1), is(false)); + assertThat(mq.areColumnsUnique(values, colAll), is(true)); + assertThat(mq.areColumnsUnique(values, colNone), is(false)); + + // Repeat the above tests directly against the handler. + final RelMdColumnUniqueness handler = + (RelMdColumnUniqueness) RelMdColumnUniqueness.SOURCE + .handlers(BuiltInMetadata.ColumnUniqueness.DEF) + .get(BuiltInMethod.COLUMN_UNIQUENESS.method) + .iterator().next(); + assertThat(handler.areColumnsUnique(values, mq, col0, false), + is(true)); + assertThat(handler.areColumnsUnique(values, mq, col1, false), + is(false)); + assertThat(handler.areColumnsUnique(values, mq, colAll, false), + is(true)); + assertThat(handler.areColumnsUnique(values, mq, colNone, false), + is(false)); + + return null; + }); } private void addRow(ImmutableList.Builder<ImmutableList<RexLiteral>> builder, @@ -1253,15 +1233,10 @@ public class RelMetadataTest extends SqlToRelTestBase { final Join join = (Join) rel.getInput(); final RelOptTable empTable = join.getInput(0).getTable(); final RelOptTable deptTable = join.getInput(1).getTable(); - Frameworks.withPlanner( - new Frameworks.PlannerAction<Void>() { - public Void apply(RelOptCluster cluster, - RelOptSchema relOptSchema, - SchemaPlus rootSchema) { - checkAverageRowSize(cluster, empTable, deptTable); - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + checkAverageRowSize(cluster, empTable, deptTable); + return null; + }); } private void checkAverageRowSize(RelOptCluster cluster, RelOptTable empTable, @@ -1312,7 +1287,7 @@ public class RelMetadataTest extends SqlToRelTestBase { // Union final LogicalUnion union = - LogicalUnion.create(ImmutableList.<RelNode>of(empScan, emptyValues), + LogicalUnion.create(ImmutableList.of(empScan, emptyValues), true); rowSize = mq.getAverageRowSize(union); columnSizes = mq.getAverageColumnSizes(union); @@ -1356,7 +1331,7 @@ public class RelMetadataTest extends SqlToRelTestBase { // Join final LogicalJoin join = LogicalJoin.create(empScan, deptProject, rexBuilder.makeLiteral(true), - ImmutableSet.<CorrelationId>of(), JoinRelType.INNER); + ImmutableSet.of(), JoinRelType.INNER); rowSize = mq.getAverageRowSize(join); columnSizes = mq.getAverageColumnSizes(join); assertThat(columnSizes.size(), equalTo(13)); @@ -1369,7 +1344,7 @@ public class RelMetadataTest extends SqlToRelTestBase { // Aggregate final LogicalAggregate aggregate = LogicalAggregate.create(join, ImmutableBitSet.of(2, 0), - ImmutableList.<ImmutableBitSet>of(), + ImmutableList.of(), ImmutableList.of( AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, ImmutableIntList.of(), @@ -1397,15 +1372,10 @@ public class RelMetadataTest extends SqlToRelTestBase { final Join join = (Join) rel.getInput(); final RelOptTable empTable = join.getInput(0).getTable(); final RelOptTable deptTable = join.getInput(1).getTable(); - Frameworks.withPlanner( - new Frameworks.PlannerAction<Void>() { - public Void apply(RelOptCluster cluster, - RelOptSchema relOptSchema, - SchemaPlus rootSchema) { - checkPredicates(cluster, empTable, deptTable); - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + checkPredicates(cluster, empTable, deptTable); + return null; + }); } private void checkPredicates(RelOptCluster cluster, RelOptTable empTable, @@ -1898,15 +1868,10 @@ public class RelMetadataTest extends SqlToRelTestBase { final Join join = (Join) rel.getInput(); final RelOptTable empTable = join.getInput(0).getTable(); final RelOptTable deptTable = join.getInput(1).getTable(); - Frameworks.withPlanner( - new Frameworks.PlannerAction<Void>() { - public Void apply(RelOptCluster cluster, - RelOptSchema relOptSchema, - SchemaPlus rootSchema) { - checkAllPredicates(cluster, empTable, deptTable); - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + checkAllPredicates(cluster, empTable, deptTable); + return null; + }); } private void checkAllPredicates(RelOptCluster cluster, RelOptTable empTable, http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java index 282449f..07dd0b0 100644 --- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java +++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java @@ -35,7 +35,6 @@ import org.apache.calcite.rel.RelRoot; import org.apache.calcite.rel.core.Aggregate; import org.apache.calcite.rel.core.CorrelationId; import org.apache.calcite.rel.core.Intersect; -import org.apache.calcite.rel.core.Join; import org.apache.calcite.rel.core.JoinRelType; import org.apache.calcite.rel.core.Minus; import org.apache.calcite.rel.core.Project; @@ -110,7 +109,6 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; import org.apache.calcite.runtime.Hook; -import org.apache.calcite.runtime.PredicateImpl; import org.apache.calcite.sql.SemiJoinType; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.fun.SqlStdOperatorTable; @@ -120,23 +118,23 @@ import org.apache.calcite.sql2rel.SqlToRelConverter; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.util.ImmutableBitSet; -import static org.apache.calcite.plan.RelOptRule.none; -import static org.apache.calcite.plan.RelOptRule.operand; - -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import org.junit.Ignore; import org.junit.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import java.util.function.Predicate; -import javax.annotation.Nullable; +import static org.apache.calcite.plan.RelOptRule.none; +import static org.apache.calcite.plan.RelOptRule.operand; +import static org.apache.calcite.plan.RelOptRule.operandJ; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; /** * Unit test for rules in {@code org.apache.calcite.rel} and subpackages. @@ -181,19 +179,9 @@ import static org.junit.Assert.assertTrue; public class RelOptRulesTest extends RelOptTestBase { //~ Methods ---------------------------------------------------------------- - private final PushProjector.ExprCondition skipItem = new PushProjector.ExprCondition() { - - @Override public boolean apply(RexNode rexNode) { - return false; - } - @Override public boolean test(RexNode expr) { - if (expr instanceof RexCall) { - RexCall call = (RexCall) expr; - return "item".equalsIgnoreCase(call.getOperator().getName()); - } - return false; - } - }; + private final PushProjector.ExprCondition skipItem = expr -> + expr instanceof RexCall + && "item".equalsIgnoreCase(((RexCall) expr).getOperator().getName()); protected DiffRepository getDiffRepos() { return DiffRepository.lookup(RelOptRulesTest.class); @@ -466,11 +454,7 @@ public class RelOptRulesTest extends RelOptTestBase { .addRuleInstance(ProjectMergeRule.INSTANCE) .build(); final FilterJoinRule.Predicate predicate = - new FilterJoinRule.Predicate() { - public boolean apply(Join join, JoinRelType joinType, RexNode exp) { - return joinType != JoinRelType.INNER; - } - }; + (join, joinType, exp) -> joinType != JoinRelType.INNER; final FilterJoinRule join = new FilterJoinRule.JoinConditionPushRule(RelBuilder.proto(), predicate); final FilterJoinRule filterOnJoin = @@ -1195,7 +1179,7 @@ public class RelOptRulesTest extends RelOptTestBase { @Test public void testProjectCorrelateTranspose() { ProjectCorrelateTransposeRule customPCTrans = - new ProjectCorrelateTransposeRule(PushProjector.ExprCondition.TRUE, + new ProjectCorrelateTransposeRule(expr -> true, RelFactories.LOGICAL_BUILDER); checkPlanning(customPCTrans, @@ -1993,30 +1977,26 @@ public class RelOptRulesTest extends RelOptTestBase { private void checkPlanning(String query) throws Exception { final Tester tester1 = tester.withCatalogReaderFactory( - new Function<RelDataTypeFactory, Prepare.CatalogReader>() { - public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) { - return new MockCatalogReader(typeFactory, true) { - @Override public MockCatalogReader init() { - // CREATE SCHEMA abc; - // CREATE TABLE a(a INT); - // ... - // CREATE TABLE j(j INT); - MockSchema schema = new MockSchema("SALES"); - registerSchema(schema); - final RelDataType intType = - typeFactory.createSqlType(SqlTypeName.INTEGER); - for (int i = 0; i < 10; i++) { - String t = String.valueOf((char) ('A' + i)); - MockTable table = MockTable.create(this, schema, t, false, 100); - table.addColumn(t, intType); - registerTable(table); - } - return this; - } - // CHECKSTYLE: IGNORE 1 - }.init(); + typeFactory -> new MockCatalogReader(typeFactory, true) { + @Override public MockCatalogReader init() { + // CREATE SCHEMA abc; + // CREATE TABLE a(a INT); + // ... + // CREATE TABLE j(j INT); + MockSchema schema = new MockSchema("SALES"); + registerSchema(schema); + final RelDataType intType = + typeFactory.createSqlType(SqlTypeName.INTEGER); + for (int i = 0; i < 10; i++) { + String t = String.valueOf((char) ('A' + i)); + MockTable table = MockTable.create(this, schema, t, false, 100); + table.addColumn(t, intType); + registerTable(table); + } + return this; } - }); + // CHECKSTYLE: IGNORE 1 + }.init()); HepProgram program = new HepProgramBuilder() .addMatchOrder(HepMatchOrder.BOTTOM_UP) .addRuleInstance(ProjectRemoveRule.INSTANCE) @@ -2804,11 +2784,11 @@ public class RelOptRulesTest extends RelOptTestBase { final AggregateExtractProjectRule rule = new AggregateExtractProjectRule( operand(Aggregate.class, - operand(Project.class, null, - new PredicateImpl<Project>() { + operandJ(Project.class, null, + new Predicate<Project>() { int matchCount = 0; - public boolean test(@Nullable Project project) { + public boolean test(Project project) { return matchCount++ == 0; } }, @@ -2863,9 +2843,9 @@ public class RelOptRulesTest extends RelOptTestBase { final RelRoot root = tester.convertSqlToRel(sql); final RelNode relInitial = root.rel; - assertTrue(relInitial != null); + assertThat(relInitial, notNullValue()); - List<RelMetadataProvider> list = Lists.newArrayList(); + List<RelMetadataProvider> list = new ArrayList<>(); list.add(DefaultRelMetadataProvider.INSTANCE); planner.registerMetadataProviders(list); RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list); @@ -3499,7 +3479,7 @@ public class RelOptRulesTest extends RelOptTestBase { @Override public RelOptPlanner createPlanner() { return new MockRelOptPlanner(Contexts.empty()) { @Override public List<RelTraitDef> getRelTraitDefs() { - return ImmutableList.<RelTraitDef>of(RelCollationTraitDef.INSTANCE); + return ImmutableList.of(RelCollationTraitDef.INSTANCE); } @Override public RelTraitSet emptyTraitSet() { return RelTraitSet.createEmpty().plus( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java b/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java index 3882c84..9b8ddb1 100644 --- a/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java +++ b/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java @@ -36,13 +36,14 @@ import org.apache.calcite.sql2rel.RelDecorrelator; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.util.Closer; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -178,7 +179,7 @@ abstract class RelOptTestBase extends SqlToRelTestBase { assertTrue(relInitial != null); - List<RelMetadataProvider> list = Lists.newArrayList(); + List<RelMetadataProvider> list = new ArrayList<>(); list.add(DefaultRelMetadataProvider.INSTANCE); planner.registerMetadataProviders(list); RelMetadataProvider plannerChain = @@ -227,8 +228,7 @@ abstract class RelOptTestBase extends SqlToRelTestBase { /** Sets the SQL statement for a test. */ Sql sql(String sql) { return new Sql(sql, null, null, - ImmutableMap.<Hook, Function>of(), - ImmutableList.<Function<Tester, Tester>>of()); + ImmutableMap.of(), ImmutableList.of()); } /** Allows fluent testing. */ @@ -236,11 +236,11 @@ abstract class RelOptTestBase extends SqlToRelTestBase { private final String sql; private HepProgram preProgram; private final HepPlanner hepPlanner; - private final ImmutableMap<Hook, Function> hooks; + private final ImmutableMap<Hook, Consumer> hooks; private ImmutableList<Function<Tester, Tester>> transforms; Sql(String sql, HepProgram preProgram, HepPlanner hepPlanner, - ImmutableMap<Hook, Function> hooks, + ImmutableMap<Hook, Consumer> hooks, ImmutableList<Function<Tester, Tester>> transforms) { this.sql = sql; this.preProgram = preProgram; @@ -274,60 +274,43 @@ abstract class RelOptTestBase extends SqlToRelTestBase { } /** Adds a hook and a handler for that hook. Calcite will create a thread - * hook (by calling {@link Hook#addThread(com.google.common.base.Function)}) + * hook (by calling {@link Hook#addThread(Consumer)}) * just before running the query, and remove the hook afterwards. */ - public <T> Sql withHook(Hook hook, Function<T, Void> handler) { + public <T> Sql withHook(Hook hook, Consumer<T> handler) { return new Sql(sql, preProgram, hepPlanner, FlatLists.append(hooks, hook, handler), transforms); } + /** @deprecated Use {@link #withHook(Hook, Consumer)}. */ + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public <T> Sql withHook(Hook hook, + com.google.common.base.Function<T, Void> handler) { + return withHook(hook, (Consumer<T>) handler::apply); + } + public <V> Sql withProperty(Hook hook, V value) { - return withHook(hook, Hook.property(value)); + return withHook(hook, Hook.propertyJ(value)); } public Sql expand(final boolean b) { - return withTransform( - new Function<Tester, Tester>() { - public Tester apply(Tester tester) { - return tester.withExpand(b); - } - }); + return withTransform(tester -> tester.withExpand(b)); } public Sql withLateDecorrelation(final boolean b) { - return withTransform( - new Function<Tester, Tester>() { - public Tester apply(Tester tester) { - return tester.withLateDecorrelation(b); - } - }); + return withTransform(tester -> tester.withLateDecorrelation(b)); } public Sql withDecorrelation(final boolean b) { - return withTransform( - new Function<Tester, Tester>() { - public Tester apply(Tester tester) { - return tester.withDecorrelation(b); - } - }); + return withTransform(tester -> tester.withDecorrelation(b)); } public Sql withTrim(final boolean b) { - return withTransform( - new Function<Tester, Tester>() { - public Tester apply(Tester tester) { - return tester.withTrim(b); - } - }); + return withTransform(tester -> tester.withTrim(b)); } public Sql withContext(final Context context) { - return withTransform( - new Function<Tester, Tester>() { - public Tester apply(Tester tester) { - return tester.withContext(context); - } - }); + return withTransform(tester -> tester.withContext(context)); } public void check() { @@ -338,9 +321,10 @@ abstract class RelOptTestBase extends SqlToRelTestBase { check(true); } + @SuppressWarnings("unchecked") private void check(boolean unchanged) { try (final Closer closer = new Closer()) { - for (Map.Entry<Hook, Function> entry : hooks.entrySet()) { + for (Map.Entry<Hook, Consumer> entry : hooks.entrySet()) { closer.add(entry.getKey().addThread(entry.getValue())); } Tester t = tester; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/RexProgramTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java index 007b1c4..733579d 100644 --- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java @@ -62,7 +62,6 @@ import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import org.junit.Before; @@ -129,7 +128,7 @@ public class RexProgramTest { DummyTestDataContext() { this.map = - ImmutableMap.<String, Object>of( + ImmutableMap.of( Variable.TIME_ZONE.camelName, TimeZone.getTimeZone("America/Los_Angeles"), Variable.CURRENT_TIMESTAMP.camelName, 1311120000000L); } @@ -1007,7 +1006,7 @@ public class RexProgramTest { } final RelDataType rowType3 = builder.build(); final RexDynamicParam range3 = rexBuilder.makeDynamicParam(rowType3, 0); - final List<RexNode> list = Lists.newArrayList(); + final List<RexNode> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add( and(rexBuilder.makeFieldAccess(range3, i * 2), http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java index ae18bc6..582389b 100644 --- a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java +++ b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java @@ -358,7 +358,7 @@ public class ScannableTableTest { final Schema schema = new AbstractSchema() { @Override protected Map<String, Table> getTableMap() { - return ImmutableMap.<String, Table>of("TENS", + return ImmutableMap.of("TENS", new SimpleTable() { private Enumerable<Object[]> superScan(DataContext root) { return super.scan(root); @@ -414,16 +414,13 @@ public class ScannableTableTest { protected ConnectionPostProcessor newSchema(final String schemaName, final String tableName, final Table table) { - return new ConnectionPostProcessor() { - - @Override public Connection apply(Connection connection) throws SQLException { - CalciteConnection con = connection.unwrap(CalciteConnection.class); - SchemaPlus rootSchema = con.getRootSchema(); - SchemaPlus schema = rootSchema.add(schemaName, new AbstractSchema()); - schema.add(tableName, table); - connection.setSchema(schemaName); - return connection; - } + return connection -> { + CalciteConnection con = connection.unwrap(CalciteConnection.class); + SchemaPlus rootSchema = con.getRootSchema(); + SchemaPlus schema = rootSchema.add(schemaName, new AbstractSchema()); + schema.add(tableName, table); + connection.setSchema(schemaName); + return connection; }; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlLineTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlLineTest.java b/core/src/test/java/org/apache/calcite/test/SqlLineTest.java index 9530e06..17b6d86 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlLineTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlLineTest.java @@ -76,7 +76,7 @@ public class SqlLineTest { } else { args.add("--run=" + scriptFile.getAbsolutePath()); } - return run(args.toArray(new String[args.size()])); + return run(args.toArray(new String[0])); } /** http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlTestGen.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java index 95ab005..54ddd61 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java +++ b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java @@ -80,7 +80,7 @@ public class SqlTestGen { list.add(method); } } - return list.toArray(new Method[list.size()]); + return list.toArray(new Method[0]); } //~ Inner Classes ---------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java index 2deab9d..d19e4cc 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java @@ -16,7 +16,6 @@ */ package org.apache.calcite.test; -import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptSchema; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.RelShuttleImpl; @@ -24,11 +23,8 @@ import org.apache.calcite.rel.core.TableScan; import org.apache.calcite.rel.externalize.RelJsonReader; import org.apache.calcite.rel.externalize.RelJsonWriter; import org.apache.calcite.runtime.Hook; -import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.tools.Frameworks; -import com.google.common.base.Function; - import org.junit.After; import org.junit.Before; @@ -41,13 +37,8 @@ public class SqlToRelConverterExtendedTest extends SqlToRelConverterTest { Hook.Closeable closeable; @Before public void before() { - this.closeable = Hook.CONVERTED.addThread( - new Function<RelNode, Void>() { - public Void apply(RelNode a0) { - foo(a0); - return null; - } - }); + this.closeable = + Hook.CONVERTED.addThread(SqlToRelConverterExtendedTest::foo); } @After public void after() { @@ -73,21 +64,17 @@ public class SqlToRelConverterExtendedTest extends SqlToRelConverterTest { }); // Convert JSON back to rel tree. - Frameworks.withPlanner( - new Frameworks.PlannerAction<Object>() { - public Object apply(RelOptCluster cluster, - RelOptSchema relOptSchema, SchemaPlus rootSchema) { - final RelJsonReader reader = new RelJsonReader( - cluster, - schemas[0], rootSchema); - try { - RelNode x = reader.read(json); - } catch (IOException e) { - throw new RuntimeException(e); - } - return null; - } - }); + Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { + final RelJsonReader reader = new RelJsonReader( + cluster, + schemas[0], rootSchema); + try { + RelNode x = reader.read(json); + } catch (IOException e) { + throw new RuntimeException(e); + } + return null; + }); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 4a1f2e6..0f9dad2 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -21,13 +21,11 @@ import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.config.NullCollation; import org.apache.calcite.plan.Contexts; import org.apache.calcite.plan.RelOptUtil; -import org.apache.calcite.prepare.Prepare; import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.RelRoot; import org.apache.calcite.rel.RelVisitor; import org.apache.calcite.rel.core.CorrelationId; import org.apache.calcite.rel.externalize.RelXmlWriter; -import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.sql.SqlExplainLevel; import org.apache.calcite.sql.validate.SqlConformance; import org.apache.calcite.sql.validate.SqlConformanceEnum; @@ -37,7 +35,6 @@ import org.apache.calcite.util.Litmus; import org.apache.calcite.util.TestUtil; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import org.junit.Ignore; @@ -2618,25 +2615,18 @@ public class SqlToRelConverterTest extends SqlToRelTestBase { } private Tester getExtendedTester() { - return tester.withCatalogReaderFactory( - new Function<RelDataTypeFactory, Prepare.CatalogReader>() { - public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) { - return new MockCatalogReader(typeFactory, true) - .init().init2(); - } - }); + return tester.withCatalogReaderFactory(typeFactory -> + new MockCatalogReader(typeFactory, true).init().init2()); } @Test public void testLarge() { - SqlValidatorTest.checkLarge(400, - new Function<String, Void>() { - public Void apply(String input) { - final RelRoot root = tester.convertSqlToRel(input); - final String s = RelOptUtil.toString(root.project()); - assertThat(s, notNullValue()); - return null; - } - }); + // Size factor used to be 400, but lambdas use a lot of stack + final int x = 300; + SqlValidatorTest.checkLarge(x, input -> { + final RelRoot root = tester.convertSqlToRel(input); + final String s = RelOptUtil.toString(root.project()); + assertThat(s, notNullValue()); + }); } @Test public void testUnionInFrom() { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java index 7bc3b88..d2192ae 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java @@ -62,13 +62,13 @@ import org.apache.calcite.sql2rel.StandardConvertletTable; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.util.ImmutableBitSet; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.function.Function; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -111,43 +111,42 @@ public abstract class SqlToRelTestBase { protected Tester getTesterWithDynamicTable() { return tester.withCatalogReaderFactory( - new Function<RelDataTypeFactory, Prepare.CatalogReader>() { - public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) { - return new MockCatalogReader(typeFactory, true) { - @Override public MockCatalogReader init() { - // CREATE SCHEMA "SALES; - // CREATE DYNAMIC TABLE "NATION" - // CREATE DYNAMIC TABLE "CUSTOMER" - - MockSchema schema = new MockSchema("SALES"); - registerSchema(schema); - - MockTable nationTable = new MockDynamicTable(this, schema.getCatalogName(), - schema.getName(), "NATION", false, 100); - registerTable(nationTable); - - MockTable customerTable = new MockDynamicTable(this, schema.getCatalogName(), - schema.getName(), "CUSTOMER", false, 100); - registerTable(customerTable); - - // CREATE TABLE "REGION" - static table with known schema. - final RelDataType intType = - typeFactory.createSqlType(SqlTypeName.INTEGER); - final RelDataType varcharType = - typeFactory.createSqlType(SqlTypeName.VARCHAR); - - MockTable regionTable = MockTable.create(this, schema, "REGION", false, 100); - regionTable.addColumn("R_REGIONKEY", intType); - regionTable.addColumn("R_NAME", varcharType); - regionTable.addColumn("R_COMMENT", varcharType); - registerTable(regionTable); - - return this; - } - // CHECKSTYLE: IGNORE 1 - }.init(); - } - }); + typeFactory -> new MockCatalogReader(typeFactory, true) { + @Override public MockCatalogReader init() { + // CREATE SCHEMA "SALES; + // CREATE DYNAMIC TABLE "NATION" + // CREATE DYNAMIC TABLE "CUSTOMER" + + MockSchema schema = new MockSchema("SALES"); + registerSchema(schema); + + MockTable nationTable = + new MockDynamicTable(this, schema.getCatalogName(), + schema.getName(), "NATION", false, 100); + registerTable(nationTable); + + MockTable customerTable = + new MockDynamicTable(this, schema.getCatalogName(), + schema.getName(), "CUSTOMER", false, 100); + registerTable(customerTable); + + // CREATE TABLE "REGION" - static table with known schema. + final RelDataType intType = + typeFactory.createSqlType(SqlTypeName.INTEGER); + final RelDataType varcharType = + typeFactory.createSqlType(SqlTypeName.VARCHAR); + + MockTable regionTable = + MockTable.create(this, schema, "REGION", false, 100); + regionTable.addColumn("R_REGIONKEY", intType); + regionTable.addColumn("R_NAME", varcharType); + regionTable.addColumn("R_COMMENT", varcharType); + registerTable(regionTable); + + return this; + } + // CHECKSTYLE: IGNORE 1 + }.init()); } /** @@ -605,7 +604,7 @@ public abstract class SqlToRelTestBase { } public RelRoot convertSqlToRel(String sql) { - Preconditions.checkNotNull(sql); + Objects.requireNonNull(sql); final SqlNode sqlQuery; final SqlToRelConverter.Config localConfig; try {
