You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2018/07/09 07:49:32 UTC

[10/30] calcite git commit: [CALCITE-2259] Allow Java 8 syntax

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
index 0749de5..9056ecc 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
@@ -56,10 +56,6 @@ import org.apache.commons.dbcp2.PoolingDataSource;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMultiset;
@@ -86,6 +82,7 @@ import java.sql.Statement;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -96,6 +93,9 @@ import java.util.Properties;
 import java.util.TimeZone;
 import java.util.TreeSet;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 import javax.sql.DataSource;
 
@@ -151,8 +151,7 @@ public class CalciteAssert {
   }
 
   public static final ConnectionFactory EMPTY_CONNECTION_FACTORY =
-      new MapConnectionFactory(ImmutableMap.<String, String>of(),
-          ImmutableList.<ConnectionPostProcessor>of());
+      new MapConnectionFactory(ImmutableMap.of(), ImmutableList.of());
 
   /** Implementation of {@link AssertThat} that does nothing. */
   private static final AssertThat DISABLED =
@@ -178,7 +177,7 @@ public class CalciteAssert {
         }
 
         @Override public AssertThat connectThrows(
-            Function<Throwable, Void> exceptionChecker) {
+            Consumer<Throwable> exceptionChecker) {
           return this;
         }
 
@@ -239,38 +238,32 @@ public class CalciteAssert {
 
   static Function<RelNode, Void> checkRel(final String expected,
       final AtomicInteger counter) {
-    return new Function<RelNode, Void>() {
-      public Void apply(RelNode relNode) {
-        if (counter != null) {
-          counter.incrementAndGet();
-        }
-        String s = RelOptUtil.toString(relNode);
-        assertThat(s, containsStringLinux(expected));
-        return null;
+    return relNode -> {
+      if (counter != null) {
+        counter.incrementAndGet();
       }
+      String s = RelOptUtil.toString(relNode);
+      assertThat(s, containsStringLinux(expected));
+      return null;
     };
   }
 
-  static Function<Throwable, Void> checkException(
-      final String expected) {
-    return new Function<Throwable, Void>() {
-      public Void apply(Throwable p0) {
-        assertNotNull(
-            "expected exception but none was thrown", p0);
-        StringWriter stringWriter = new StringWriter();
-        PrintWriter printWriter = new PrintWriter(stringWriter);
-        p0.printStackTrace(printWriter);
-        printWriter.flush();
-        String stack = stringWriter.toString();
-        assertTrue(stack, stack.contains(expected));
-        return null;
-      }
+  static Consumer<Throwable> checkException(final String expected) {
+    return p0 -> {
+      assertNotNull(
+          "expected exception but none was thrown", p0);
+      StringWriter stringWriter = new StringWriter();
+      PrintWriter printWriter = new PrintWriter(stringWriter);
+      p0.printStackTrace(printWriter);
+      printWriter.flush();
+      String stack = stringWriter.toString();
+      assertTrue(stack, stack.contains(expected));
     };
   }
 
-  static Function<Throwable, Void> checkValidationException(final String expected) {
-    return new Function<Throwable, Void>() {
-      @Nullable @Override public Void apply(@Nullable Throwable throwable) {
+  static Consumer<Throwable> checkValidationException(final String expected) {
+    return new Consumer<Throwable>() {
+      @Override public void accept(@Nullable Throwable throwable) {
         assertNotNull("Nothing was thrown", throwable);
 
         Exception exception = containsCorrectException(throwable);
@@ -284,7 +277,6 @@ public class CalciteAssert {
           String stack = stringWriter.toString();
           assertTrue(stack, stack.contains(expected));
         }
-        return null;
       }
 
       private boolean isCorrectException(Throwable throwable) {
@@ -305,67 +297,55 @@ public class CalciteAssert {
     };
   }
 
-  static Function<ResultSet, Void> checkResult(final String expected) {
+  static Consumer<ResultSet> checkResult(final String expected) {
     return checkResult(expected, new ResultSetFormatter());
   }
 
-  static Function<ResultSet, Void> checkResult(final String expected,
+  static Consumer<ResultSet> checkResult(final String expected,
       final ResultSetFormatter resultSetFormatter) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet resultSet) {
-        try {
-          resultSetFormatter.resultSet(resultSet);
-          assertThat(resultSetFormatter.string(), isLinux(expected));
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    return resultSet -> {
+      try {
+        resultSetFormatter.resultSet(resultSet);
+        assertThat(resultSetFormatter.string(), isLinux(expected));
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  static Function<ResultSet, Void> checkResultValue(final String expected) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet resultSet) {
-        try {
-          if (!resultSet.next()) {
-            throw new AssertionError("too few rows");
-          }
-          if (resultSet.getMetaData().getColumnCount() != 1) {
-            throw new AssertionError("expected 1 column");
-          }
-          final String resultString = resultSet.getString(1);
-          assertThat(resultString,
-              expected == null ? nullValue(String.class) : isLinux(expected));
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
+  static Consumer<ResultSet> checkResultValue(final String expected) {
+    return resultSet -> {
+      try {
+        if (!resultSet.next()) {
+          throw new AssertionError("too few rows");
         }
+        if (resultSet.getMetaData().getColumnCount() != 1) {
+          throw new AssertionError("expected 1 column");
+        }
+        final String resultString = resultSet.getString(1);
+        assertThat(resultString,
+            expected == null ? nullValue(String.class) : isLinux(expected));
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<ResultSet, Void> checkResultCount(
+  public static Consumer<ResultSet> checkResultCount(
       final Matcher<Integer> expected) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet resultSet) {
-        try {
-          final int count = CalciteAssert.countRows(resultSet);
-          assertThat(count, expected);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    return resultSet -> {
+      try {
+        final int count = CalciteAssert.countRows(resultSet);
+        assertThat(count, expected);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<Integer, Void> checkUpdateCount(final int expected) {
-    return new Function<Integer, Void>() {
-      public Void apply(Integer updateCount) {
-        assertThat(updateCount, is(expected));
-        return null;
-      }
+  public static Consumer<Integer> checkUpdateCount(final int expected) {
+    return updateCount -> {
+      assertThat(updateCount, is(expected));
     };
   }
 
@@ -374,12 +354,12 @@ public class CalciteAssert {
    *
    * @param ordered Whether order should be the same both times
    */
-  static Function<ResultSet, Void> consistentResult(final boolean ordered) {
-    return new Function<ResultSet, Void>() {
+  static Consumer<ResultSet> consistentResult(final boolean ordered) {
+    return new Consumer<ResultSet>() {
       int executeCount = 0;
       Collection expected;
 
-      public Void apply(ResultSet resultSet) {
+      public void accept(ResultSet resultSet) {
         ++executeCount;
         try {
           final Collection result =
@@ -394,7 +374,6 @@ public class CalciteAssert {
               fail("oops");
             }
           }
-          return null;
         } catch (SQLException e) {
           throw new RuntimeException(e);
         }
@@ -411,105 +390,89 @@ public class CalciteAssert {
   }
 
   /** @see Matchers#returnsUnordered(String...) */
-  static Function<ResultSet, Void> checkResultUnordered(final String... lines) {
+  static Consumer<ResultSet> checkResultUnordered(final String... lines) {
     return checkResult(true, false, lines);
   }
 
   /** @see Matchers#returnsUnordered(String...) */
-  static Function<ResultSet, Void> checkResult(final boolean sort,
+  static Consumer<ResultSet> checkResult(final boolean sort,
       final boolean head, final String... lines) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet resultSet) {
-        try {
-          final List<String> expectedList = Lists.newArrayList(lines);
-          if (sort) {
-            Collections.sort(expectedList);
-          }
-          final List<String> actualList = Lists.newArrayList();
-          CalciteAssert.toStringList(resultSet, actualList);
-          if (sort) {
-            Collections.sort(actualList);
-          }
-          final List<String> trimmedActualList;
-          if (head && actualList.size() > expectedList.size()) {
-            trimmedActualList = actualList.subList(0, expectedList.size());
-          } else {
-            trimmedActualList = actualList;
-          }
-          if (!trimmedActualList.equals(expectedList)) {
-            assertThat(Util.lines(trimmedActualList),
-                equalTo(Util.lines(expectedList)));
-          }
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
+    return resultSet -> {
+      try {
+        final List<String> expectedList = Lists.newArrayList(lines);
+        if (sort) {
+          Collections.sort(expectedList);
+        }
+        final List<String> actualList = new ArrayList<>();
+        CalciteAssert.toStringList(resultSet, actualList);
+        if (sort) {
+          Collections.sort(actualList);
+        }
+        final List<String> trimmedActualList;
+        if (head && actualList.size() > expectedList.size()) {
+          trimmedActualList = actualList.subList(0, expectedList.size());
+        } else {
+          trimmedActualList = actualList;
+        }
+        if (!trimmedActualList.equals(expectedList)) {
+          assertThat(Util.lines(trimmedActualList),
+              equalTo(Util.lines(expectedList)));
         }
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<ResultSet, Void> checkResultContains(
+  public static Consumer<ResultSet> checkResultContains(
       final String... expected) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet s) {
-        try {
-          final String actual = CalciteAssert.toString(s);
-          for (String st : expected) {
-            assertThat(actual, containsStringLinux(st));
-          }
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
+    return s -> {
+      try {
+        final String actual = toString(s);
+        for (String st : expected) {
+          assertThat(actual, containsStringLinux(st));
         }
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<ResultSet, Void> checkResultContains(
+  public static Consumer<ResultSet> checkResultContains(
       final String expected, final int count) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet s) {
-        try {
-          final String actual = Util.toLinux(CalciteAssert.toString(s));
-          assertTrue(
-              actual + " should have " + count + " occurrence of " + expected,
-              StringUtils.countMatches(actual, expected) == count);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    return s -> {
+      try {
+        final String actual = Util.toLinux(toString(s));
+        assertTrue(
+            actual + " should have " + count + " occurrence of " + expected,
+            StringUtils.countMatches(actual, expected) == count);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<ResultSet, Void> checkMaskedResultContains(
+  public static Consumer<ResultSet> checkMaskedResultContains(
       final String expected) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet s) {
-        try {
-          final String actual = Util.toLinux(CalciteAssert.toString(s));
-          final String maskedActual =
-              actual.replaceAll(", id = [0-9]+", "");
-          assertThat(maskedActual, containsString(expected));
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    return s -> {
+      try {
+        final String actual = Util.toLinux(toString(s));
+        final String maskedActual =
+            actual.replaceAll(", id = [0-9]+", "");
+        assertThat(maskedActual, containsString(expected));
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
 
-  public static Function<ResultSet, Void> checkResultType(
-      final String expected) {
-    return new Function<ResultSet, Void>() {
-      public Void apply(ResultSet s) {
-        try {
-          final String actual = typeString(s.getMetaData());
-          assertEquals(expected, actual);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+  public static Consumer<ResultSet> checkResultType(final String expected) {
+    return s -> {
+      try {
+        final String actual = typeString(s.getMetaData());
+        assertEquals(expected, actual);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     };
   }
@@ -534,10 +497,10 @@ public class CalciteAssert {
       String sql,
       int limit,
       boolean materializationsEnabled,
-      List<Pair<Hook, Function>> hooks,
-      Function<ResultSet, Void> resultChecker,
-      Function<Integer, Void> updateChecker,
-      Function<Throwable, Void> exceptionChecker) throws Exception {
+      List<Pair<Hook, Consumer>> hooks,
+      Consumer<ResultSet> resultChecker,
+      Consumer<Integer> updateChecker,
+      Consumer<Throwable> exceptionChecker) throws Exception {
     final String message =
         "With materializationsEnabled=" + materializationsEnabled
             + ", limit=" + limit;
@@ -560,7 +523,8 @@ public class CalciteAssert {
               DateTimeUtils.UTC_ZONE.getID());
         }
       }
-      for (Pair<Hook, Function> hook : hooks) {
+      for (Pair<Hook, Consumer> hook : hooks) {
+        //noinspection unchecked
         closer.add(hook.left.addThread(hook.right));
       }
       Statement statement = connection.createStatement();
@@ -574,21 +538,21 @@ public class CalciteAssert {
           updateCount = statement.executeUpdate(sql);
         }
         if (exceptionChecker != null) {
-          exceptionChecker.apply(null);
+          exceptionChecker.accept(null);
           return;
         }
       } catch (Exception | Error e) {
         if (exceptionChecker != null) {
-          exceptionChecker.apply(e);
+          exceptionChecker.accept(e);
           return;
         }
         throw e;
       }
       if (resultChecker != null) {
-        resultChecker.apply(resultSet);
+        resultChecker.accept(resultSet);
       }
       if (updateChecker != null) {
-        updateChecker.apply(updateCount);
+        updateChecker.accept(updateCount);
       }
       if (resultSet != null) {
         resultSet.close();
@@ -616,23 +580,12 @@ public class CalciteAssert {
     try (Closer closer = new Closer()) {
       if (convertChecker != null) {
         closer.add(
-            Hook.TRIMMED.addThread(
-                new Function<RelNode, Void>() {
-                  public Void apply(RelNode rel) {
-                    convertChecker.apply(rel);
-                    return null;
-                  }
-                }));
+            Hook.TRIMMED.addThread((Consumer<RelNode>) convertChecker::apply));
       }
       if (substitutionChecker != null) {
         closer.add(
             Hook.SUB.addThread(
-                new Function<RelNode, Void>() {
-                  public Void apply(RelNode rel) {
-                    substitutionChecker.apply(rel);
-                    return null;
-                  }
-                }));
+                (Consumer<RelNode>) substitutionChecker::apply));
       }
       ((CalciteConnection) connection).getProperties().setProperty(
           CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
@@ -769,14 +722,14 @@ public class CalciteAssert {
       }
       return rootSchema.add("foodmart2", new CloneSchema(foodmart));
     case GEO:
-      ModelHandler.addFunctions(rootSchema, null, ImmutableList.<String>of(),
+      ModelHandler.addFunctions(rootSchema, null, ImmutableList.of(),
           GeoFunctions.class.getName(), "*", true);
       final SchemaPlus s = rootSchema.add("GEO", new AbstractSchema());
-      ModelHandler.addFunctions(s, "countries", ImmutableList.<String>of(),
+      ModelHandler.addFunctions(s, "countries", ImmutableList.of(),
           CountriesTableFunction.class.getName(), null, false);
       final String sql = "select * from table(\"countries\"(true))";
       final ViewTableMacro viewMacro = ViewTable.viewMacro(rootSchema, sql,
-          ImmutableList.of("GEO"), ImmutableList.<String>of(), false);
+          ImmutableList.of("GEO"), ImmutableList.of(), false);
       s.add("countries", viewMacro);
       return s;
     case HR:
@@ -808,7 +761,7 @@ public class CalciteAssert {
                   + "    ('Grace', 60, 'F'),\n"
                   + "    ('Wilma', cast(null as integer), 'F'))\n"
                   + "  as t(ename, deptno, gender)",
-              ImmutableList.<String>of(), ImmutableList.of("POST", "EMP"),
+              ImmutableList.of(), ImmutableList.of("POST", "EMP"),
               null));
       post.add("DEPT",
           ViewTable.viewMacro(post,
@@ -817,7 +770,7 @@ public class CalciteAssert {
                   + "    (20, 'Marketing'),\n"
                   + "    (30, 'Engineering'),\n"
                   + "    (40, 'Empty')) as t(deptno, dname)",
-              ImmutableList.<String>of(), ImmutableList.of("POST", "DEPT"),
+              ImmutableList.of(), ImmutableList.of("POST", "DEPT"),
               null));
       post.add("EMPS",
           ViewTable.viewMacro(post,
@@ -828,7 +781,7 @@ public class CalciteAssert {
                   + "    (120, 'Wilma', 20, 'F',                   CAST(NULL AS VARCHAR(20)), 1,                 5, UNKNOWN, TRUE,  DATE '2005-09-07'),\n"
                   + "    (130, 'Alice', 40, 'F',                   'Vancouver',               2, CAST(NULL AS INT), FALSE,   TRUE,  DATE '2007-01-01'))\n"
                   + " as t(empno, name, deptno, gender, city, empid, age, slacker, manager, joinedat)",
-              ImmutableList.<String>of(), ImmutableList.of("POST", "EMPS"),
+              ImmutableList.of(), ImmutableList.of("POST", "EMPS"),
               null));
       return post;
     default:
@@ -852,15 +805,14 @@ public class CalciteAssert {
    */
   public static void assertArrayEqual(
       String message, Object[] expected, Object[] actual) {
-    Joiner joiner = Joiner.on('\n');
-    String strExpected = expected == null ? null : joiner.join(expected);
-    String strActual = actual == null ? null : joiner.join(actual);
-    assertEquals(message, strExpected, strActual);
+    assertEquals(message, str(expected), str(actual));
   }
 
-  static <F, T> Function<F, T> constantNull() {
-    //noinspection unchecked
-    return (Function<F, T>) (Function) Functions.<T>constant(null);
+  private static String str(Object[] objects) {
+    return objects == null
+          ? null
+          : Arrays.stream(objects).map(Object::toString)
+              .collect(Collectors.joining("\n"));
   }
 
   /** Returns a {@link PropBuilder}. */
@@ -878,7 +830,7 @@ public class CalciteAssert {
         new AssertThat(EMPTY_CONNECTION_FACTORY);
 
     private AssertThat(ConnectionFactory connectionFactory) {
-      this.connectionFactory = Preconditions.checkNotNull(connectionFactory);
+      this.connectionFactory = Objects.requireNonNull(connectionFactory);
     }
 
     public AssertThat with(Config config) {
@@ -973,26 +925,23 @@ public class CalciteAssert {
     /** Adds materializations to the schema. */
     public final AssertThat withMaterializations(String model, final boolean existing,
         final String... materializations) {
-      return withMaterializations(model,
-          new Function<JsonBuilder, List<Object>>() {
-            public List<Object> apply(JsonBuilder builder) {
-              assert materializations.length % 2 == 0;
-              final List<Object> list = builder.list();
-              for (int i = 0; i < materializations.length; i++) {
-                String table = materializations[i++];
-                final Map<String, Object> map = builder.map();
-                map.put("table", table);
-                if (!existing) {
-                  map.put("view", table + "v");
-                }
-                String sql = materializations[i];
-                final String sql2 = sql.replaceAll("`", "\"");
-                map.put("sql", sql2);
-                list.add(map);
-              }
-              return list;
-            }
-          });
+      return withMaterializations(model, builder -> {
+        assert materializations.length % 2 == 0;
+        final List<Object> list = builder.list();
+        for (int i = 0; i < materializations.length; i++) {
+          String table = materializations[i++];
+          final Map<String, Object> map = builder.map();
+          map.put("table", table);
+          if (!existing) {
+            map.put("view", table + "v");
+          }
+          String sql = materializations[i];
+          final String sql2 = sql.replaceAll("`", "\"");
+          map.put("sql", sql2);
+          list.add(map);
+        }
+        return list;
+      });
     }
 
     /** Adds materializations to the schema. */
@@ -1033,8 +982,7 @@ public class CalciteAssert {
 
     /** Asserts that there is an exception that matches the given predicate
      * while creating a connection. */
-    public AssertThat connectThrows(
-        Function<Throwable, Void> exceptionChecker) {
+    public AssertThat connectThrows(Consumer<Throwable> exceptionChecker) {
       Throwable throwable;
       try (Connection x = connectionFactory.createConnection()) {
         try {
@@ -1046,7 +994,7 @@ public class CalciteAssert {
       } catch (Throwable e) {
         throwable = e;
       }
-      exceptionChecker.apply(throwable);
+      exceptionChecker.accept(throwable);
       return this;
     }
 
@@ -1061,6 +1009,16 @@ public class CalciteAssert {
       }
     }
 
+    /** Creates a {@link org.apache.calcite.jdbc.CalciteConnection}
+     * and executes a callback that returns no result. */
+    public final AssertThat doWithConnection(Consumer<CalciteConnection> fn)
+        throws Exception {
+      return doWithConnection(c -> {
+        fn.accept(c);
+        return null;
+      });
+    }
+
     /** Creates a {@link DataContext} and executes a callback. */
     public <T> AssertThat doWithDataContext(Function<DataContext, T> fn)
         throws Exception {
@@ -1130,6 +1088,7 @@ public class CalciteAssert {
   }
 
   /** Connection post processor */
+  @FunctionalInterface
   public interface ConnectionPostProcessor {
     Connection apply(Connection connection) throws SQLException;
   }
@@ -1209,8 +1168,8 @@ public class CalciteAssert {
 
     private MapConnectionFactory(ImmutableMap<String, String> map,
         ImmutableList<ConnectionPostProcessor> postProcessors) {
-      this.map = Preconditions.checkNotNull(map);
-      this.postProcessors = Preconditions.checkNotNull(postProcessors);
+      this.map = Objects.requireNonNull(map);
+      this.postProcessors = Objects.requireNonNull(postProcessors);
     }
 
     @Override public boolean equals(Object obj) {
@@ -1267,7 +1226,7 @@ public class CalciteAssert {
     private String plan;
     private int limit;
     private boolean materializationsEnabled = false;
-    private final List<Pair<Hook, Function>> hooks = Lists.newArrayList();
+    private final List<Pair<Hook, Consumer>> hooks = new ArrayList<>();
 
     private AssertQuery(ConnectionFactory connectionFactory, String sql) {
       this.sql = sql;
@@ -1280,10 +1239,10 @@ public class CalciteAssert {
 
     /** Performs an action using a connection, and closes the connection
      * afterwards. */
-    public final AssertQuery withConnection(Function<Connection, Void> f)
+    public final AssertQuery withConnection(Consumer<Connection> f)
         throws Exception {
       try (Connection c = createConnection()) {
-        f.apply(c);
+        f.accept(c);
       }
       return this;
     }
@@ -1296,7 +1255,8 @@ public class CalciteAssert {
       return returns(checkResult(expected));
     }
 
-    /** Simlar to {@link #returns}, but trims a few values before comparing. */
+    /** Similar to {@link #returns}, but trims a few values before
+     * comparing. */
     public AssertQuery returns2(final String expected) {
       return returns(
           checkResult(expected,
@@ -1328,7 +1288,7 @@ public class CalciteAssert {
       return returns(checkResultCount(is(expectedCount)));
     }
 
-    public final AssertQuery returns(Function<ResultSet, Void> checker) {
+    public final AssertQuery returns(Consumer<ResultSet> checker) {
       return returns(sql, checker);
     }
 
@@ -1343,8 +1303,14 @@ public class CalciteAssert {
       }
     }
 
-    protected AssertQuery returns(String sql,
-        Function<ResultSet, Void> checker) {
+    @SuppressWarnings("Guava")
+    @Deprecated // to be removed in 2.0
+    public final AssertQuery returns(
+        com.google.common.base.Function<ResultSet, Void> checker) {
+      return returns(sql, checker::apply);
+    }
+
+    protected AssertQuery returns(String sql, Consumer<ResultSet> checker) {
       try (final Connection connection = createConnection()) {
         assertQuery(connection, sql, limit, materializationsEnabled,
             hooks, checker, null, null);
@@ -1460,7 +1426,7 @@ public class CalciteAssert {
     }
 
     public final AssertQuery explainMatches(String extra,
-        Function<ResultSet, Void> checker) {
+        Consumer<ResultSet> checker) {
       return returns("explain plan " + extra + "for " + sql, checker);
     }
 
@@ -1478,8 +1444,8 @@ public class CalciteAssert {
       ensurePlan(checkUpdateCount(count));
       expected = "getDataSource(), \""
           + expected.replace("\\", "\\\\")
-              .replace("\"", "\\\"")
-              .replaceAll("\n", "\\\\n")
+          .replace("\"", "\\\"")
+          .replaceAll("\n", "\\\\n")
           + "\"";
       assertTrue(
           "Plan [" + plan + "] contains [" + expected + "]",
@@ -1492,23 +1458,17 @@ public class CalciteAssert {
     public AssertQuery planHasSql(String expected) {
       return planContains(
           "getDataSource(), \""
-          + expected.replace("\\", "\\\\")
+              + expected.replace("\\", "\\\\")
               .replace("\"", "\\\"")
               .replaceAll("\n", "\\\\n")
-          + "\"");
+              + "\"");
     }
 
-    private void ensurePlan(Function<Integer, Void> checkUpdate) {
+    private void ensurePlan(Consumer<Integer> checkUpdate) {
       if (plan != null) {
         return;
       }
-      addHook(Hook.JAVA_PLAN,
-          new Function<String, Void>() {
-            public Void apply(String a0) {
-              plan = a0;
-              return null;
-            }
-          });
+      addHook(Hook.JAVA_PLAN, (Consumer<String>) a0 -> plan = a0);
       try (final Connection connection = createConnection()) {
         assertQuery(connection, sql, limit, materializationsEnabled,
             hooks, null, checkUpdate, null);
@@ -1523,19 +1483,13 @@ public class CalciteAssert {
      * queries. The checker should throw to fail the test if it does not see
      * what it wants. This method can be used to check whether a particular
      * MongoDB or SQL query is generated, for instance. */
-    public AssertQuery queryContains(Function<List, Void> predicate1) {
-      final List<Object> list = Lists.newArrayList();
-      addHook(Hook.QUERY_PLAN,
-          new Function<Object, Void>() {
-            public Void apply(Object a0) {
-              list.add(a0);
-              return null;
-            }
-          });
+    public AssertQuery queryContains(Consumer<List> predicate1) {
+      final List<Object> list = new ArrayList<>();
+      addHook(Hook.QUERY_PLAN, list::add);
       try (final Connection connection = createConnection()) {
         assertQuery(connection, sql, limit, materializationsEnabled,
             hooks, null, null, null);
-        predicate1.apply(list);
+        predicate1.accept(list);
         return this;
       } catch (Exception e) {
         throw new RuntimeException(
@@ -1543,6 +1497,14 @@ public class CalciteAssert {
       }
     }
 
+    /** @deprecated Use {@link #queryContains(Consumer)}. */
+    @SuppressWarnings("Guava")
+    @Deprecated // to be removed before 2.0
+    public final AssertQuery queryContains(
+        com.google.common.base.Function<List, Void> predicate1) {
+      return queryContains((Consumer<List>) predicate1::apply);
+    }
+
     /** Sets a limit on the number of rows returned. -1 means no limit. */
     public AssertQuery limit(int limit) {
       this.limit = limit;
@@ -1555,7 +1517,7 @@ public class CalciteAssert {
         materializationsEnabled = false;
         final boolean ordered =
             sql.toUpperCase(Locale.ROOT).contains("ORDER BY");
-        final Function<ResultSet, Void> checker = consistentResult(ordered);
+        final Consumer<ResultSet> checker = consistentResult(ordered);
         returns(checker);
         materializationsEnabled = true;
         returns(checker);
@@ -1569,35 +1531,37 @@ public class CalciteAssert {
       return this;
     }
 
+    @SuppressWarnings("Guava")
+    @Deprecated // to be removed in 2.0
+    public <T> AssertQuery withHook(Hook hook, Function<T, Void> handler) {
+      return withHook(hook, (Consumer<T>) handler::apply);
+    }
+
     /** 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> AssertQuery withHook(Hook hook, Function<T, Void> handler) {
+    public <T> AssertQuery withHook(Hook hook, Consumer<T> handler) {
       addHook(hook, handler);
       return this;
     }
 
-    private <T> void addHook(Hook hook, Function<T, Void> handler) {
-      hooks.add(Pair.of(hook, (Function) handler));
+    private <T> void addHook(Hook hook, Consumer<T> handler) {
+      hooks.add(Pair.of(hook, handler));
     }
 
     /** Adds a property hook. */
     public <V> AssertQuery withProperty(Hook hook, V value) {
-      return withHook(hook, Hook.property(value));
+      return withHook(hook, Hook.propertyJ(value));
     }
 
     /** Adds a factory to create a {@link RelNode} query. This {@code RelNode}
      * will be used instead of the SQL string. */
     public AssertQuery withRel(final Function<RelBuilder, RelNode> relFn) {
       return withHook(Hook.STRING_TO_QUERY,
-          new Function<
-              Pair<FrameworkConfig, Holder<CalcitePrepare.Query>>, Void>() {
-            public Void apply(
-                Pair<FrameworkConfig, Holder<CalcitePrepare.Query>> pair) {
-              final RelBuilder b = RelBuilder.create(pair.left);
-              pair.right.set(CalcitePrepare.Query.of(relFn.apply(b)));
-              return null;
-            }
+          (Consumer<Pair<FrameworkConfig, Holder<CalcitePrepare.Query>>>)
+          pair -> {
+            final RelBuilder b = RelBuilder.create(pair.left);
+            pair.right.set(CalcitePrepare.Query.of(relFn.apply(b)));
           });
     }
   }
@@ -1613,10 +1577,10 @@ public class CalciteAssert {
       this.function = function;
     }
 
-    public final AssertMetaData returns(Function<ResultSet, Void> checker) {
+    public final AssertMetaData returns(Consumer<ResultSet> checker) {
       try (final Connection c = connectionFactory.createConnection()) {
         final ResultSet resultSet = function.apply(c);
-        checker.apply(resultSet);
+        checker.accept(resultSet);
         resultSet.close();
         c.close();
         return this;
@@ -1701,7 +1665,7 @@ public class CalciteAssert {
     }
 
     @Override public AssertQuery returns(String sql,
-        Function<ResultSet, Void> checker) {
+        Consumer<ResultSet> checker) {
       return this;
     }
 
@@ -1735,8 +1699,7 @@ public class CalciteAssert {
       return this;
     }
 
-    @Override public AssertQuery
-    queryContains(Function<List, Void> predicate1) {
+    @Override public AssertQuery queryContains(Consumer<List> predicate1) {
       return this;
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java b/core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java
index 99440c8..a095f8c 100644
--- a/core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java
@@ -452,8 +452,7 @@ public class CollectionTypeTest {
     }
 
     @Override public boolean rolledUpColumnValidInsideAgg(String column,
-                                                          SqlCall call, SqlNode parent,
-                                                          CalciteConnectionConfig config) {
+        SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
       return false;
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/ExceptionMessageTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ExceptionMessageTest.java b/core/src/test/java/org/apache/calcite/test/ExceptionMessageTest.java
index 2d61698..6d605f8 100644
--- a/core/src/test/java/org/apache/calcite/test/ExceptionMessageTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ExceptionMessageTest.java
@@ -27,7 +27,6 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Iterator;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -51,10 +50,8 @@ public class ExceptionMessageTest {
         new Entry(2, "name2")
     };
 
-    public Iterable<Entry> badEntries = new Iterable<Entry>() {
-      public Iterator<Entry> iterator() {
-        throw new IllegalStateException("Can't iterate over badEntries");
-      }
+    public Iterable<Entry> badEntries = () -> {
+      throw new IllegalStateException("Can't iterate over badEntries");
     };
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/FoodMartLatticeStatisticProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/FoodMartLatticeStatisticProvider.java b/core/src/test/java/org/apache/calcite/test/FoodMartLatticeStatisticProvider.java
index 4eae872..be9213e 100644
--- a/core/src/test/java/org/apache/calcite/test/FoodMartLatticeStatisticProvider.java
+++ b/core/src/test/java/org/apache/calcite/test/FoodMartLatticeStatisticProvider.java
@@ -36,12 +36,8 @@ import java.util.Map;
 public class FoodMartLatticeStatisticProvider
     extends DelegatingLatticeStatisticProvider {
   public static final FoodMartLatticeStatisticProvider.Factory FACTORY =
-      new Factory() {
-        public LatticeStatisticProvider apply(Lattice lattice) {
-          return new FoodMartLatticeStatisticProvider(lattice,
-              Lattices.CACHED_SQL.apply(lattice));
-        }
-      };
+      lattice -> new FoodMartLatticeStatisticProvider(lattice,
+          Lattices.CACHED_SQL.apply(lattice));
 
   private static final Map<String, Integer> CARDINALITY_MAP =
       ImmutableMap.<String, Integer>builder()

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/InduceGroupingTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/InduceGroupingTypeTest.java b/core/src/test/java/org/apache/calcite/test/InduceGroupingTypeTest.java
index 59b7f73..de82061 100644
--- a/core/src/test/java/org/apache/calcite/test/InduceGroupingTypeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/InduceGroupingTypeTest.java
@@ -19,10 +19,9 @@ package org.apache.calcite.test;
 import org.apache.calcite.rel.core.Aggregate;
 import org.apache.calcite.util.ImmutableBitSet;
 
-import com.google.common.collect.Lists;
-
 import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -37,7 +36,7 @@ public class InduceGroupingTypeTest {
     final ImmutableBitSet groupSet = ImmutableBitSet.of(1, 2, 4, 5);
 
     // SIMPLE
-    List<ImmutableBitSet> groupSets = Lists.newArrayList();
+    List<ImmutableBitSet> groupSets = new ArrayList<>();
     groupSets.add(groupSet);
     assertEquals(Aggregate.Group.SIMPLE,
         Aggregate.Group.induce(groupSet, groupSets));
@@ -48,7 +47,7 @@ public class InduceGroupingTypeTest {
         Aggregate.Group.induce(groupSet, groupSets));
 
     // ROLLUP
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of(1, 2, 4, 5));
     groupSets.add(ImmutableBitSet.of(1, 2, 4));
     groupSets.add(ImmutableBitSet.of(1, 2));
@@ -58,7 +57,7 @@ public class InduceGroupingTypeTest {
         Aggregate.Group.induce(groupSet, groupSets));
 
     // OTHER
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of(1, 2, 4, 5));
     groupSets.add(ImmutableBitSet.of(1, 2, 4));
     groupSets.add(ImmutableBitSet.of(1, 2));
@@ -66,7 +65,7 @@ public class InduceGroupingTypeTest {
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of(1, 2, 4, 5));
     groupSets.add(ImmutableBitSet.of(1, 2, 4));
     groupSets.add(ImmutableBitSet.of(1, 2));
@@ -74,7 +73,7 @@ public class InduceGroupingTypeTest {
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of(1, 2, 5));
     groupSets.add(ImmutableBitSet.of(1, 2, 4));
     groupSets.add(ImmutableBitSet.of(1, 2));
@@ -92,11 +91,11 @@ public class InduceGroupingTypeTest {
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of());
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
@@ -108,23 +107,23 @@ public class InduceGroupingTypeTest {
     final ImmutableBitSet groupSet = ImmutableBitSet.of(2);
 
     // Could be ROLLUP but we prefer CUBE
-    List<ImmutableBitSet> groupSets = Lists.newArrayList();
+    List<ImmutableBitSet> groupSets = new ArrayList<>();
     groupSets.add(groupSet);
     groupSets.add(ImmutableBitSet.of());
     assertEquals(Aggregate.Group.CUBE,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(ImmutableBitSet.of());
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     groupSets.add(groupSet);
     assertEquals(Aggregate.Group.SIMPLE,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
   }
@@ -133,12 +132,12 @@ public class InduceGroupingTypeTest {
     final ImmutableBitSet groupSet = ImmutableBitSet.of();
 
     // Could be CUBE or ROLLUP but we choose SIMPLE
-    List<ImmutableBitSet> groupSets = Lists.newArrayList();
+    List<ImmutableBitSet> groupSets = new ArrayList<>();
     groupSets.add(groupSet);
     assertEquals(Aggregate.Group.SIMPLE,
         Aggregate.Group.induce(groupSet, groupSets));
 
-    groupSets = Lists.newArrayList();
+    groupSets = new ArrayList<>();
     assertEquals(Aggregate.Group.OTHER,
         Aggregate.Group.induce(groupSet, groupSets));
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/InterpreterTest.java b/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
index 9e419fd..a179da7 100644
--- a/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
@@ -28,12 +28,11 @@ import org.apache.calcite.tools.FrameworkConfig;
 import org.apache.calcite.tools.Frameworks;
 import org.apache.calcite.tools.Planner;
 
-import com.google.common.collect.Lists;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -130,7 +129,7 @@ public class InterpreterTest {
 
   private static void assertRows(Interpreter interpreter,
       boolean unordered, String... rows) {
-    final List<String> list = Lists.newArrayList();
+    final List<String> list = new ArrayList<>();
     for (Object[] row : interpreter) {
       list.add(Arrays.toString(row));
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
index e65fe65..1bf0f7f 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
@@ -17,12 +17,9 @@
 package org.apache.calcite.test;
 
 import org.apache.calcite.config.Lex;
-import org.apache.calcite.jdbc.CalciteConnection;
 import org.apache.calcite.test.CalciteAssert.AssertThat;
 import org.apache.calcite.test.CalciteAssert.DatabaseInstance;
 
-import com.google.common.base.Function;
-
 import org.hsqldb.jdbcDriver;
 
 import org.junit.Test;
@@ -622,19 +619,15 @@ public class JdbcAdapterTest {
             "jdbcSchema: null");
     CalciteAssert.model(
         model)
-        .doWithConnection(
-            new Function<CalciteConnection, Void>() {
-              public Void apply(CalciteConnection connection) {
-                try {
-                  final ResultSet resultSet =
-                      connection.getMetaData().getTables(null, null, "%", null);
-                  assertFalse(CalciteAssert.toString(resultSet).isEmpty());
-                  return null;
-                } catch (SQLException e) {
-                  throw new RuntimeException(e);
-                }
-              }
-            });
+        .doWithConnection(connection -> {
+          try {
+            final ResultSet resultSet =
+                connection.getMetaData().getTables(null, null, "%", null);
+            assertFalse(CalciteAssert.toString(resultSet).isEmpty());
+          } catch (SQLException e) {
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   /** Test case for
@@ -720,19 +713,15 @@ public class JdbcAdapterTest {
         CalciteAssert.model(JdbcTest.FOODMART_MODEL)
             .enable(CalciteAssert.DB == DatabaseInstance.HSQLDB
                 || CalciteAssert.DB == DatabaseInstance.POSTGRESQL);
-    that.doWithConnection(
-        new Function<CalciteConnection, Void>() {
-          public Void apply(CalciteConnection connection) {
-            try (LockWrapper ignore = exclusiveCleanDb(connection)) {
-              that.query(sql)
-                  .explainContains(explain)
-                  .planUpdateHasSql(jdbcSql, 1);
-              return null;
-            } catch (SQLException e) {
-              throw new RuntimeException(e);
-            }
-          }
-        });
+    that.doWithConnection(connection -> {
+      try (LockWrapper ignore = exclusiveCleanDb(connection)) {
+        that.query(sql)
+            .explainContains(explain)
+            .planUpdateHasSql(jdbcSql, 1);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
+      }
+    });
   }
 
   @Test public void testTableModifyInsertMultiValues() throws Exception {
@@ -756,19 +745,15 @@ public class JdbcAdapterTest {
         CalciteAssert.model(JdbcTest.FOODMART_MODEL)
             .enable(CalciteAssert.DB == DatabaseInstance.HSQLDB
                 || CalciteAssert.DB == DatabaseInstance.POSTGRESQL);
-    that.doWithConnection(
-        new Function<CalciteConnection, Void>() {
-          public Void apply(CalciteConnection connection) {
-            try (LockWrapper ignore = exclusiveCleanDb(connection)) {
-              that.query(sql)
-                  .explainContains(explain)
-                  .planUpdateHasSql(jdbcSql, 2);
-              return null;
-            } catch (SQLException e) {
-              throw new RuntimeException(e);
-            }
-          }
-        });
+    that.doWithConnection(connection -> {
+      try (LockWrapper ignore = exclusiveCleanDb(connection)) {
+        that.query(sql)
+            .explainContains(explain)
+            .planUpdateHasSql(jdbcSql, 2);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
+      }
+    });
   }
 
   @Test public void testTableModifyInsertWithSubQuery() throws Exception {
@@ -776,37 +761,34 @@ public class JdbcAdapterTest {
         .model(JdbcTest.FOODMART_MODEL)
         .enable(CalciteAssert.DB == DatabaseInstance.HSQLDB);
 
-    that.doWithConnection(new Function<CalciteConnection, Void>() {
-      public Void apply(CalciteConnection connection) {
-        try (LockWrapper ignore = exclusiveCleanDb(connection)) {
-          final String sql = "INSERT INTO \"foodmart\".\"expense_fact\"(\n"
-              + " \"store_id\", \"account_id\", \"exp_date\", \"time_id\","
-              + " \"category_id\", \"currency_id\", \"amount\")\n"
-              + "SELECT  \"store_id\", \"account_id\", \"exp_date\","
-              + " \"time_id\" + 1, \"category_id\", \"currency_id\","
-              + " \"amount\"\n"
-              + "FROM \"foodmart\".\"expense_fact\"\n"
-              + "WHERE \"store_id\" = 666";
-          final String explain = "PLAN=JdbcToEnumerableConverter\n"
-              + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[INSERT], flattened=[false])\n"
-              + "    JdbcProject(store_id=[$0], account_id=[$1], exp_date=[$2], time_id=[+($3, 1)], category_id=[$4], currency_id=[$5], amount=[$6])\n"
-              + "      JdbcFilter(condition=[=($0, 666)])\n"
-              + "        JdbcTableScan(table=[[foodmart, expense_fact]])\n";
-          final String jdbcSql = "INSERT INTO \"foodmart\".\"expense_fact\""
-              + " (\"store_id\", \"account_id\", \"exp_date\", \"time_id\","
-              + " \"category_id\", \"currency_id\", \"amount\")\n"
-              + "(SELECT \"store_id\", \"account_id\", \"exp_date\","
-              + " \"time_id\" + 1 AS \"time_id\", \"category_id\","
-              + " \"currency_id\", \"amount\"\n"
-              + "FROM \"foodmart\".\"expense_fact\"\n"
-              + "WHERE \"store_id\" = 666)";
-          that.query(sql)
-              .explainContains(explain)
-              .planUpdateHasSql(jdbcSql, 1);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    that.doWithConnection(connection -> {
+      try (LockWrapper ignore = exclusiveCleanDb(connection)) {
+        final String sql = "INSERT INTO \"foodmart\".\"expense_fact\"(\n"
+            + " \"store_id\", \"account_id\", \"exp_date\", \"time_id\","
+            + " \"category_id\", \"currency_id\", \"amount\")\n"
+            + "SELECT  \"store_id\", \"account_id\", \"exp_date\","
+            + " \"time_id\" + 1, \"category_id\", \"currency_id\","
+            + " \"amount\"\n"
+            + "FROM \"foodmart\".\"expense_fact\"\n"
+            + "WHERE \"store_id\" = 666";
+        final String explain = "PLAN=JdbcToEnumerableConverter\n"
+            + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[INSERT], flattened=[false])\n"
+            + "    JdbcProject(store_id=[$0], account_id=[$1], exp_date=[$2], time_id=[+($3, 1)], category_id=[$4], currency_id=[$5], amount=[$6])\n"
+            + "      JdbcFilter(condition=[=($0, 666)])\n"
+            + "        JdbcTableScan(table=[[foodmart, expense_fact]])\n";
+        final String jdbcSql = "INSERT INTO \"foodmart\".\"expense_fact\""
+            + " (\"store_id\", \"account_id\", \"exp_date\", \"time_id\","
+            + " \"category_id\", \"currency_id\", \"amount\")\n"
+            + "(SELECT \"store_id\", \"account_id\", \"exp_date\","
+            + " \"time_id\" + 1 AS \"time_id\", \"category_id\","
+            + " \"currency_id\", \"amount\"\n"
+            + "FROM \"foodmart\".\"expense_fact\"\n"
+            + "WHERE \"store_id\" = 666)";
+        that.query(sql)
+            .explainContains(explain)
+            .planUpdateHasSql(jdbcSql, 1);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     });
   }
@@ -816,27 +798,25 @@ public class JdbcAdapterTest {
         .model(JdbcTest.FOODMART_MODEL)
         .enable(CalciteAssert.DB == DatabaseInstance.HSQLDB);
 
-    that.doWithConnection(new Function<CalciteConnection, Void>() {
-      public Void apply(CalciteConnection connection) {
-        try (LockWrapper ignore = exclusiveCleanDb(connection)) {
-          final String sql = "UPDATE \"foodmart\".\"expense_fact\"\n"
-              + " SET \"account_id\"=888\n"
-              + " WHERE \"store_id\"=666\n";
-          final String explain = "PLAN=JdbcToEnumerableConverter\n"
-              + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[UPDATE], updateColumnList=[[account_id]], sourceExpressionList=[[888]], flattened=[false])\n"
-              + "    JdbcProject(store_id=[$0], account_id=[$1], exp_date=[$2], time_id=[$3], category_id=[$4], currency_id=[$5], amount=[$6], EXPR$0=[888])\n"
-              + "      JdbcFilter(condition=[=($0, 666)])\n"
-              + "        JdbcTableScan(table=[[foodmart, expense_fact]])";
-          final String jdbcSql = "UPDATE \"foodmart\".\"expense_fact\""
-              + " SET \"account_id\" = 888\n"
-              + "WHERE \"store_id\" = 666";
-          that.query(sql)
-              .explainContains(explain)
-              .planUpdateHasSql(jdbcSql, 1);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    that.doWithConnection(connection -> {
+      try (LockWrapper ignore = exclusiveCleanDb(connection)) {
+        final String sql = "UPDATE \"foodmart\".\"expense_fact\"\n"
+            + " SET \"account_id\"=888\n"
+            + " WHERE \"store_id\"=666\n";
+        final String explain = "PLAN=JdbcToEnumerableConverter\n"
+            + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[UPDATE], updateColumnList=[[account_id]], sourceExpressionList=[[888]], flattened=[false])\n"
+            + "    JdbcProject(store_id=[$0], account_id=[$1], exp_date=[$2], time_id=[$3], category_id=[$4], currency_id=[$5], amount=[$6], EXPR$0=[888])\n"
+            + "      JdbcFilter(condition=[=($0, 666)])\n"
+            + "        JdbcTableScan(table=[[foodmart, expense_fact]])";
+        final String jdbcSql = "UPDATE \"foodmart\".\"expense_fact\""
+            + " SET \"account_id\" = 888\n"
+            + "WHERE \"store_id\" = 666";
+        that.query(sql)
+            .explainContains(explain)
+            .planUpdateHasSql(jdbcSql, 1);
+        return null;
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     });
   }
@@ -846,24 +826,21 @@ public class JdbcAdapterTest {
         .model(JdbcTest.FOODMART_MODEL)
         .enable(CalciteAssert.DB == DatabaseInstance.HSQLDB);
 
-    that.doWithConnection(new Function<CalciteConnection, Void>() {
-      public Void apply(CalciteConnection connection) {
-        try (LockWrapper ignore = exclusiveCleanDb(connection)) {
-          final String sql = "DELETE FROM \"foodmart\".\"expense_fact\"\n"
-              + "WHERE \"store_id\"=666\n";
-          final String explain = "PLAN=JdbcToEnumerableConverter\n"
-              + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[DELETE], flattened=[false])\n"
-              + "    JdbcFilter(condition=[=($0, 666)])\n"
-              + "      JdbcTableScan(table=[[foodmart, expense_fact]]";
-          final String jdbcSql = "DELETE FROM \"foodmart\".\"expense_fact\"\n"
-              + "WHERE \"store_id\" = 666";
-          that.query(sql)
-              .explainContains(explain)
-              .planUpdateHasSql(jdbcSql, 1);
-          return null;
-        } catch (SQLException e) {
-          throw new RuntimeException(e);
-        }
+    that.doWithConnection(connection -> {
+      try (LockWrapper ignore = exclusiveCleanDb(connection)) {
+        final String sql = "DELETE FROM \"foodmart\".\"expense_fact\"\n"
+            + "WHERE \"store_id\"=666\n";
+        final String explain = "PLAN=JdbcToEnumerableConverter\n"
+            + "  JdbcTableModify(table=[[foodmart, expense_fact]], operation=[DELETE], flattened=[false])\n"
+            + "    JdbcFilter(condition=[=($0, 666)])\n"
+            + "      JdbcTableScan(table=[[foodmart, expense_fact]]";
+        final String jdbcSql = "DELETE FROM \"foodmart\".\"expense_fact\"\n"
+            + "WHERE \"store_id\" = 666";
+        that.query(sql)
+            .explainContains(explain)
+            .planUpdateHasSql(jdbcSql, 1);
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
       }
     });
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
index 377c23b..a0a753c 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
@@ -16,10 +16,6 @@
  */
 package org.apache.calcite.test;
 
-import org.apache.calcite.jdbc.CalciteConnection;
-
-import com.google.common.base.Function;
-
 import org.hamcrest.Matcher;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -56,26 +52,22 @@ public class JdbcFrontJdbcBackTest {
   @Test public void testTables() throws Exception {
     that()
         .with(CalciteAssert.Config.JDBC_FOODMART)
-        .doWithConnection(
-            new Function<CalciteConnection, Object>() {
-              public Object apply(CalciteConnection a0) {
-                try {
-                  ResultSet rset =
-                      a0.getMetaData().getTables(
-                          null, null, null, null);
-                  StringBuilder buf = new StringBuilder();
-                  while (rset.next()) {
-                    buf.append(rset.getString(3)).append(';');
-                  }
-                  assertEquals(
-                      "account;agg_c_10_sales_fact_1997;agg_c_14_sales_fact_1997;agg_c_special_sales_fact_1997;agg_g_ms_pcat_sales_fact_1997;agg_l_03_sales_fact_1997;agg_l_04_sales_fact_1997;agg_l_05_sales_fact_1997;agg_lc_06_sales_fact_1997;agg_lc_100_sales_fact_1997;agg_ll_01_sales_fact_1997;agg_pl_01_sales_fact_1997;category;currency;customer;days;department;employee;employee_closure;expense_fact;inventory_fact_1997;inventory_fact_1998;position;product;product_class;products;promotion;region;reserve_employee;salary;sales_fact_1997;sales_fact_1998;sales_fact_dec_1998;store;store_ragged;time_by_day;warehouse;warehouse_class;COLUMNS;TABLES;",
-                      buf.toString());
-                } catch (SQLException e) {
-                  throw new RuntimeException(e);
-                }
-                return null;
-              }
-            });
+        .doWithConnection(connection -> {
+          try {
+            ResultSet rset =
+                connection.getMetaData().getTables(
+                    null, null, null, null);
+            StringBuilder buf = new StringBuilder();
+            while (rset.next()) {
+              buf.append(rset.getString(3)).append(';');
+            }
+            assertEquals(
+                "account;agg_c_10_sales_fact_1997;agg_c_14_sales_fact_1997;agg_c_special_sales_fact_1997;agg_g_ms_pcat_sales_fact_1997;agg_l_03_sales_fact_1997;agg_l_04_sales_fact_1997;agg_l_05_sales_fact_1997;agg_lc_06_sales_fact_1997;agg_lc_100_sales_fact_1997;agg_ll_01_sales_fact_1997;agg_pl_01_sales_fact_1997;category;currency;customer;days;department;employee;employee_closure;expense_fact;inventory_fact_1997;inventory_fact_1998;position;product;product_class;products;promotion;region;reserve_employee;salary;sales_fact_1997;sales_fact_1998;sales_fact_dec_1998;store;store_ragged;time_by_day;warehouse;warehouse_class;COLUMNS;TABLES;",
+                buf.toString());
+          } catch (SQLException e) {
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   @Test public void testTablesByType() throws Exception {
@@ -89,47 +81,39 @@ public class JdbcFrontJdbcBackTest {
       final Matcher<String> matcher) throws Exception {
     that()
         .with(CalciteAssert.Config.REGULAR_PLUS_METADATA)
-        .doWithConnection(
-            new Function<CalciteConnection, Object>() {
-              public Object apply(CalciteConnection a0) {
-                try (ResultSet rset = a0.getMetaData().getTables(null, null,
-                    null, new String[] {tableType})) {
-                  StringBuilder buf = new StringBuilder();
-                  while (rset.next()) {
-                    buf.append(rset.getString(3)).append(';');
-                  }
-                  assertThat(buf.toString(), matcher);
-                  return null;
-                } catch (SQLException e) {
-                  throw new RuntimeException(e);
-                }
-              }
-            });
+        .doWithConnection(connection -> {
+          try (ResultSet rset = connection.getMetaData().getTables(null, null,
+              null, new String[] {tableType})) {
+            StringBuilder buf = new StringBuilder();
+            while (rset.next()) {
+              buf.append(rset.getString(3)).append(';');
+            }
+            assertThat(buf.toString(), matcher);
+          } catch (SQLException e) {
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   @Test public void testColumns() throws Exception {
     that()
         .with(CalciteAssert.Config.JDBC_FOODMART)
-        .doWithConnection(
-            new Function<CalciteConnection, Object>() {
-              public Object apply(CalciteConnection a0) {
-                try {
-                  ResultSet rset =
-                      a0.getMetaData().getColumns(
-                          null, null, "sales_fact_1997", null);
-                  StringBuilder buf = new StringBuilder();
-                  while (rset.next()) {
-                    buf.append(rset.getString(4)).append(';');
-                  }
-                  assertEquals(
-                      "product_id;time_id;customer_id;promotion_id;store_id;store_sales;store_cost;unit_sales;",
-                      buf.toString());
-                } catch (SQLException e) {
-                  throw new RuntimeException(e);
-                }
-                return null;
-              }
-            });
+        .doWithConnection(connection -> {
+          try {
+            ResultSet rset =
+                connection.getMetaData().getColumns(
+                    null, null, "sales_fact_1997", null);
+            StringBuilder buf = new StringBuilder();
+            while (rset.next()) {
+              buf.append(rset.getString(4)).append(';');
+            }
+            assertEquals(
+                "product_id;time_id;customer_id;promotion_id;store_id;store_sales;store_cost;unit_sales;",
+                buf.toString());
+          } catch (SQLException e) {
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   /** Tests a JDBC method known to be not implemented (as it happens,
@@ -138,20 +122,16 @@ public class JdbcFrontJdbcBackTest {
   @Test public void testEmpty() throws Exception {
     that()
         .with(CalciteAssert.Config.JDBC_FOODMART)
-        .doWithConnection(
-            new Function<CalciteConnection, Object>() {
-              public Object apply(CalciteConnection a0) {
-                try {
-                  ResultSet rset =
-                      a0.getMetaData().getPrimaryKeys(
-                          null, null, "sales_fact_1997");
-                  assertFalse(rset.next());
-                } catch (SQLException e) {
-                  throw new RuntimeException(e);
-                }
-                return null;
-              }
-            });
+        .doWithConnection(connection -> {
+          try {
+            ResultSet rset =
+                connection.getMetaData().getPrimaryKeys(
+                    null, null, "sales_fact_1997");
+            assertFalse(rset.next());
+          } catch (SQLException e) {
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   @Test public void testCase() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java b/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
index da6facc..a8c86f8 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
@@ -30,8 +30,6 @@ import org.apache.calcite.schema.Schemas;
 import org.apache.calcite.schema.impl.AbstractSchema;
 import org.apache.calcite.schema.impl.AbstractTableQueryable;
 
-import com.google.common.base.Function;
-
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -246,24 +244,20 @@ public class JdbcFrontLinqBackTest {
     CalciteAssert.AssertThat with = mutable(employees);
     with.query("select count(*) as c from \"foo\".\"bar\"")
         .returns("C=1\n");
-    with.doWithConnection(
-        new Function<CalciteConnection, Object>() {
-          public Object apply(CalciteConnection c) {
-            try {
-              final String sql = "insert into \"foo\".\"bar\"\n"
-                  + "values (?, 0, ?, 10.0, null)";
-              try (PreparedStatement p = c.prepareStatement(sql)) {
-                p.setInt(1, 1);
-                p.setString(2, "foo");
-                final int count = p.executeUpdate();
-                assertThat(count, is(1));
-              }
-              return null;
-            } catch (SQLException e) {
-              throw new RuntimeException(e);
-            }
-          }
-        });
+    with.doWithConnection(c -> {
+      try {
+        final String sql = "insert into \"foo\".\"bar\"\n"
+            + "values (?, 0, ?, 10.0, null)";
+        try (PreparedStatement p = c.prepareStatement(sql)) {
+          p.setInt(1, 1);
+          p.setString(2, "foo");
+          final int count = p.executeUpdate();
+          assertThat(count, is(1));
+        }
+      } catch (SQLException e) {
+        throw new RuntimeException(e);
+      }
+    });
     with.query("select count(*) as c from \"foo\".\"bar\"")
         .returns("C=2\n");
     with.query("select * from \"foo\".\"bar\"")
@@ -305,19 +299,16 @@ public class JdbcFrontLinqBackTest {
    */
   private static CalciteAssert.ConnectionPostProcessor makePostProcessor(
       final List<JdbcTest.Employee> initialData) {
-    return new CalciteAssert.ConnectionPostProcessor() {
-      public Connection apply(final Connection connection)
-          throws SQLException {
-        CalciteConnection calciteConnection =
-            connection.unwrap(CalciteConnection.class);
-        SchemaPlus rootSchema = calciteConnection.getRootSchema();
-        SchemaPlus mapSchema = rootSchema.add("foo", new AbstractSchema());
-        final String tableName = "bar";
-        final JdbcTest.AbstractModifiableTable table =
-            mutable(tableName, initialData);
-        mapSchema.add(tableName, table);
-        return calciteConnection;
-      }
+    return connection -> {
+      CalciteConnection calciteConnection =
+          connection.unwrap(CalciteConnection.class);
+      SchemaPlus rootSchema = calciteConnection.getRootSchema();
+      SchemaPlus mapSchema = rootSchema.add("foo", new AbstractSchema());
+      final String tableName = "bar";
+      final JdbcTest.AbstractModifiableTable table =
+          mutable(tableName, initialData);
+      mapSchema.add(tableName, table);
+      return calciteConnection;
     };
   }