You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by mm...@apache.org on 2018/07/20 17:41:26 UTC

[13/53] [abbrv] calcite git commit: [CALCITE-2259] Allow Java 8 syntax

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
index 15ca544..8b07b83 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
@@ -186,22 +186,20 @@ public abstract class ReturnTypes {
    * BOOLEAN.
    */
   public static final SqlReturnTypeInference BOOLEAN_NULLABLE_OPTIMIZED =
-      new SqlReturnTypeInference() {
+      opBinding -> {
         // Equivalent to
         //   cascade(ARG0, SqlTypeTransforms.TO_NULLABLE);
         // but implemented by hand because used in AND, which is a very common
         // operator.
-        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
-          final int n = opBinding.getOperandCount();
-          RelDataType type1 = null;
-          for (int i = 0; i < n; i++) {
-            type1 = opBinding.getOperandType(i);
-            if (type1.isNullable()) {
-              break;
-            }
+        final int n = opBinding.getOperandCount();
+        RelDataType type1 = null;
+        for (int i = 0; i < n; i++) {
+          type1 = opBinding.getOperandType(i);
+          if (type1.isNullable()) {
+            break;
           }
-          return type1;
         }
+        return type1;
       };
 
   /**
@@ -300,44 +298,36 @@ public abstract class ReturnTypes {
    * @see Glossary#SQL99 SQL:1999 Part 2 Section 9.3
    */
   public static final SqlReturnTypeInference LEAST_RESTRICTIVE =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
-          return opBinding.getTypeFactory().leastRestrictive(
-              opBinding.collectOperandTypes());
-        }
-      };
+      opBinding -> opBinding.getTypeFactory().leastRestrictive(
+          opBinding.collectOperandTypes());
   /**
    * Returns the same type as the multiset carries. The multiset type returned
    * is the least restrictive of the call's multiset operands
    */
-  public static final SqlReturnTypeInference MULTISET =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            final SqlOperatorBinding opBinding) {
-          ExplicitOperatorBinding newBinding =
-              new ExplicitOperatorBinding(
-                  opBinding,
-                  new AbstractList<RelDataType>() {
-                    // CHECKSTYLE: IGNORE 12
-                    public RelDataType get(int index) {
-                      RelDataType type =
-                          opBinding.getOperandType(index)
-                              .getComponentType();
-                      assert type != null;
-                      return type;
-                    }
-
-                    public int size() {
-                      return opBinding.getOperandCount();
-                    }
-                  });
-          RelDataType biggestElementType =
-              LEAST_RESTRICTIVE.inferReturnType(newBinding);
-          return opBinding.getTypeFactory().createMultisetType(
-              biggestElementType,
-              -1);
-        }
-      };
+  public static final SqlReturnTypeInference MULTISET = opBinding -> {
+    ExplicitOperatorBinding newBinding =
+        new ExplicitOperatorBinding(
+            opBinding,
+            new AbstractList<RelDataType>() {
+              // CHECKSTYLE: IGNORE 12
+              public RelDataType get(int index) {
+                RelDataType type =
+                    opBinding.getOperandType(index)
+                        .getComponentType();
+                assert type != null;
+                return type;
+              }
+
+              public int size() {
+                return opBinding.getOperandCount();
+              }
+            });
+    RelDataType biggestElementType =
+        LEAST_RESTRICTIVE.inferReturnType(newBinding);
+    return opBinding.getTypeFactory().createMultisetType(
+        biggestElementType,
+        -1);
+  };
 
   /**
    * Returns a multiset type.
@@ -383,33 +373,29 @@ public abstract class ReturnTypes {
    * The result type of a call is a decimal with a scale of 0, and the same
    * precision and nullability as the first argument.
    */
-  public static final SqlReturnTypeInference DECIMAL_SCALE0 =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          RelDataType type1 = opBinding.getOperandType(0);
-          if (SqlTypeUtil.isDecimal(type1)) {
-            if (type1.getScale() == 0) {
-              return type1;
-            } else {
-              int p = type1.getPrecision();
-              RelDataType ret;
-              ret =
-                  opBinding.getTypeFactory().createSqlType(
-                      SqlTypeName.DECIMAL,
-                      p,
-                      0);
-              if (type1.isNullable()) {
-                ret =
-                    opBinding.getTypeFactory()
-                        .createTypeWithNullability(ret, true);
-              }
-              return ret;
-            }
-          }
-          return null;
+  public static final SqlReturnTypeInference DECIMAL_SCALE0 = opBinding -> {
+    RelDataType type1 = opBinding.getOperandType(0);
+    if (SqlTypeUtil.isDecimal(type1)) {
+      if (type1.getScale() == 0) {
+        return type1;
+      } else {
+        int p = type1.getPrecision();
+        RelDataType ret;
+        ret =
+            opBinding.getTypeFactory().createSqlType(
+                SqlTypeName.DECIMAL,
+                p,
+                0);
+        if (type1.isNullable()) {
+          ret =
+              opBinding.getTypeFactory()
+                  .createTypeWithNullability(ret, true);
         }
-      };
+        return ret;
+      }
+    }
+    return null;
+  };
   /**
    * Type-inference strategy whereby the result type of a call is
    * {@link #DECIMAL_SCALE0} with a fallback to {@link #ARG0} This rule
@@ -423,15 +409,12 @@ public abstract class ReturnTypes {
    * product of two exact numeric operands where at least one of the operands
    * is a decimal.
    */
-  public static final SqlReturnTypeInference DECIMAL_PRODUCT =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
-          RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          RelDataType type1 = opBinding.getOperandType(0);
-          RelDataType type2 = opBinding.getOperandType(1);
-          return typeFactory.createDecimalProduct(type1, type2);
-        }
-      };
+  public static final SqlReturnTypeInference DECIMAL_PRODUCT = opBinding -> {
+    RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    RelDataType type1 = opBinding.getOperandType(0);
+    RelDataType type2 = opBinding.getOperandType(1);
+    return typeFactory.createDecimalProduct(type1, type2);
+  };
   /**
    * Same as {@link #DECIMAL_PRODUCT} but returns with nullability if any of
    * the operands is nullable by using
@@ -456,16 +439,12 @@ public abstract class ReturnTypes {
    * product of two exact numeric operands where at least one of the operands
    * is a decimal.
    */
-  public static final SqlReturnTypeInference DECIMAL_QUOTIENT =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          RelDataType type1 = opBinding.getOperandType(0);
-          RelDataType type2 = opBinding.getOperandType(1);
-          return typeFactory.createDecimalQuotient(type1, type2);
-        }
-      };
+  public static final SqlReturnTypeInference DECIMAL_QUOTIENT = opBinding -> {
+    RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    RelDataType type1 = opBinding.getOperandType(0);
+    RelDataType type2 = opBinding.getOperandType(1);
+    return typeFactory.createDecimalQuotient(type1, type2);
+  };
   /**
    * Same as {@link #DECIMAL_QUOTIENT} but returns with nullability if any of
    * the operands is nullable by using
@@ -500,42 +479,38 @@ public abstract class ReturnTypes {
    *
    * @see Glossary#SQL2003 SQL:2003 Part 2 Section 6.26
    */
-  public static final SqlReturnTypeInference DECIMAL_SUM =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          RelDataType type1 = opBinding.getOperandType(0);
-          RelDataType type2 = opBinding.getOperandType(1);
-          if (SqlTypeUtil.isExactNumeric(type1)
-              && SqlTypeUtil.isExactNumeric(type2)) {
-            if (SqlTypeUtil.isDecimal(type1)
-                || SqlTypeUtil.isDecimal(type2)) {
-              int p1 = type1.getPrecision();
-              int p2 = type2.getPrecision();
-              int s1 = type1.getScale();
-              int s2 = type2.getScale();
-
-              final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-              int scale = Math.max(s1, s2);
-              final RelDataTypeSystem typeSystem = typeFactory.getTypeSystem();
-              assert scale <= typeSystem.getMaxNumericScale();
-              int precision = Math.max(p1 - s1, p2 - s2) + scale + 1;
-              precision =
-                  Math.min(
-                      precision,
-                      typeSystem.getMaxNumericPrecision());
-              assert precision > 0;
-
-              return typeFactory.createSqlType(
-                  SqlTypeName.DECIMAL,
-                  precision,
-                  scale);
-            }
-          }
-
-          return null;
-        }
-      };
+  public static final SqlReturnTypeInference DECIMAL_SUM = opBinding -> {
+    RelDataType type1 = opBinding.getOperandType(0);
+    RelDataType type2 = opBinding.getOperandType(1);
+    if (SqlTypeUtil.isExactNumeric(type1)
+        && SqlTypeUtil.isExactNumeric(type2)) {
+      if (SqlTypeUtil.isDecimal(type1)
+          || SqlTypeUtil.isDecimal(type2)) {
+        int p1 = type1.getPrecision();
+        int p2 = type2.getPrecision();
+        int s1 = type1.getScale();
+        int s2 = type2.getScale();
+
+        final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+        int scale = Math.max(s1, s2);
+        final RelDataTypeSystem typeSystem = typeFactory.getTypeSystem();
+        assert scale <= typeSystem.getMaxNumericScale();
+        int precision = Math.max(p1 - s1, p2 - s2) + scale + 1;
+        precision =
+            Math.min(
+                precision,
+                typeSystem.getMaxNumericPrecision());
+        assert precision > 0;
+
+        return typeFactory.createSqlType(
+            SqlTypeName.DECIMAL,
+            precision,
+            scale);
+      }
+    }
+
+    return null;
+  };
   /**
    * Same as {@link #DECIMAL_SUM} but returns with nullability if any
    * of the operands is nullable by using
@@ -571,75 +546,73 @@ public abstract class ReturnTypes {
    * </ul>
    */
   public static final SqlReturnTypeInference DYADIC_STRING_SUM_PRECISION =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataType argType0 = opBinding.getOperandType(0);
-          final RelDataType argType1 = opBinding.getOperandType(1);
-
-          final boolean containsAnyType =
-              (argType0.getSqlTypeName() == SqlTypeName.ANY)
-                  || (argType1.getSqlTypeName() == SqlTypeName.ANY);
-
-          if (!containsAnyType
-              && !(SqlTypeUtil.inCharOrBinaryFamilies(argType0)
-                  && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) {
-            Preconditions.checkArgument(
-                SqlTypeUtil.sameNamedType(argType0, argType1));
-          }
-          SqlCollation pickedCollation = null;
-          if (!containsAnyType
-              && SqlTypeUtil.inCharFamily(argType0)) {
-            if (!SqlTypeUtil.isCharTypeComparable(
-                opBinding.collectOperandTypes().subList(0, 2))) {
-              throw opBinding.newError(
-                  RESOURCE.typeNotComparable(
-                      argType0.getFullTypeString(),
-                      argType1.getFullTypeString()));
-            }
-
-            pickedCollation =
-                SqlCollation.getCoercibilityDyadicOperator(
-                    argType0.getCollation(), argType1.getCollation());
-            assert null != pickedCollation;
+      opBinding -> {
+        final RelDataType argType0 = opBinding.getOperandType(0);
+        final RelDataType argType1 = opBinding.getOperandType(1);
+
+        final boolean containsAnyType =
+            (argType0.getSqlTypeName() == SqlTypeName.ANY)
+                || (argType1.getSqlTypeName() == SqlTypeName.ANY);
+
+        if (!containsAnyType
+            && !(SqlTypeUtil.inCharOrBinaryFamilies(argType0)
+            && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) {
+          Preconditions.checkArgument(
+              SqlTypeUtil.sameNamedType(argType0, argType1));
+        }
+        SqlCollation pickedCollation = null;
+        if (!containsAnyType
+            && SqlTypeUtil.inCharFamily(argType0)) {
+          if (!SqlTypeUtil.isCharTypeComparable(
+              opBinding.collectOperandTypes().subList(0, 2))) {
+            throw opBinding.newError(
+                RESOURCE.typeNotComparable(
+                    argType0.getFullTypeString(),
+                    argType1.getFullTypeString()));
           }
 
-          // Determine whether result is variable-length
-          SqlTypeName typeName =
-              argType0.getSqlTypeName();
-          if (SqlTypeUtil.isBoundedVariableWidth(argType1)) {
-            typeName = argType1.getSqlTypeName();
-          }
+          pickedCollation =
+              SqlCollation.getCoercibilityDyadicOperator(
+                  argType0.getCollation(), argType1.getCollation());
+          assert null != pickedCollation;
+        }
 
-          RelDataType ret;
-          int typePrecision;
-          final long x =
-              (long) argType0.getPrecision() + (long) argType1.getPrecision();
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataTypeSystem typeSystem = typeFactory.getTypeSystem();
-          if (argType0.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED
-              || argType1.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED
-              || x > typeSystem.getMaxPrecision(typeName)) {
-            typePrecision = RelDataType.PRECISION_NOT_SPECIFIED;
-          } else {
-            typePrecision = (int) x;
-          }
+        // Determine whether result is variable-length
+        SqlTypeName typeName =
+            argType0.getSqlTypeName();
+        if (SqlTypeUtil.isBoundedVariableWidth(argType1)) {
+          typeName = argType1.getSqlTypeName();
+        }
+
+        RelDataType ret;
+        int typePrecision;
+        final long x =
+            (long) argType0.getPrecision() + (long) argType1.getPrecision();
+        final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+        final RelDataTypeSystem typeSystem = typeFactory.getTypeSystem();
+        if (argType0.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED
+            || argType1.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED
+            || x > typeSystem.getMaxPrecision(typeName)) {
+          typePrecision = RelDataType.PRECISION_NOT_SPECIFIED;
+        } else {
+          typePrecision = (int) x;
+        }
 
-          ret = typeFactory.createSqlType(typeName, typePrecision);
-          if (null != pickedCollation) {
-            RelDataType pickedType;
-            if (argType0.getCollation().equals(pickedCollation)) {
-              pickedType = argType0;
-            } else if (argType1.getCollation().equals(pickedCollation)) {
-              pickedType = argType1;
-            } else {
-              throw new AssertionError("should never come here");
-            }
-            ret =
-                typeFactory.createTypeWithCharsetAndCollation(ret,
-                    pickedType.getCharset(), pickedType.getCollation());
+        ret = typeFactory.createSqlType(typeName, typePrecision);
+        if (null != pickedCollation) {
+          RelDataType pickedType;
+          if (argType0.getCollation().equals(pickedCollation)) {
+            pickedType = argType0;
+          } else if (argType1.getCollation().equals(pickedCollation)) {
+            pickedType = argType1;
+          } else {
+            throw new AssertionError("should never come here");
           }
-          return ret;
+          ret =
+              typeFactory.createTypeWithCharsetAndCollation(ret,
+                  pickedType.getCharset(), pickedType.getCollation());
         }
+        return ret;
       };
 
   /**
@@ -663,88 +636,72 @@ public abstract class ReturnTypes {
    * as a {@link org.apache.calcite.sql.validate.SqlValidatorNamespace}, and
    * therefore the result type of the call is the type of that namespace.
    */
-  public static final SqlReturnTypeInference SCOPE =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          SqlCallBinding callBinding = (SqlCallBinding) opBinding;
-          return callBinding.getValidator().getNamespace(
-              callBinding.getCall()).getRowType();
-        }
-      };
+  public static final SqlReturnTypeInference SCOPE = opBinding -> {
+    SqlCallBinding callBinding = (SqlCallBinding) opBinding;
+    return callBinding.getValidator().getNamespace(
+        callBinding.getCall()).getRowType();
+  };
 
   /**
    * Returns a multiset of column #0 of a multiset. For example, given
    * <code>RECORD(x INTEGER, y DATE) MULTISET</code>, returns <code>INTEGER
    * MULTISET</code>.
    */
-  public static final SqlReturnTypeInference MULTISET_PROJECT0 =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          assert opBinding.getOperandCount() == 1;
-          final RelDataType recordMultisetType =
-              opBinding.getOperandType(0);
-          RelDataType multisetType =
-              recordMultisetType.getComponentType();
-          assert multisetType != null : "expected a multiset type: "
-              + recordMultisetType;
-          final List<RelDataTypeField> fields =
-              multisetType.getFieldList();
-          assert fields.size() > 0;
-          final RelDataType firstColType = fields.get(0).getType();
-          return opBinding.getTypeFactory().createMultisetType(
-              firstColType,
-              -1);
-        }
-      };
+  public static final SqlReturnTypeInference MULTISET_PROJECT0 = opBinding -> {
+    assert opBinding.getOperandCount() == 1;
+    final RelDataType recordMultisetType =
+        opBinding.getOperandType(0);
+    RelDataType multisetType =
+        recordMultisetType.getComponentType();
+    assert multisetType != null : "expected a multiset type: "
+        + recordMultisetType;
+    final List<RelDataTypeField> fields =
+        multisetType.getFieldList();
+    assert fields.size() > 0;
+    final RelDataType firstColType = fields.get(0).getType();
+    return opBinding.getTypeFactory().createMultisetType(
+        firstColType,
+        -1);
+  };
   /**
    * Returns a multiset of the first column of a multiset. For example, given
    * <code>INTEGER MULTISET</code>, returns <code>RECORD(x INTEGER)
    * MULTISET</code>.
    */
-  public static final SqlReturnTypeInference MULTISET_RECORD =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          assert opBinding.getOperandCount() == 1;
-          final RelDataType multisetType = opBinding.getOperandType(0);
-          RelDataType componentType = multisetType.getComponentType();
-          assert componentType != null : "expected a multiset type: "
-              + multisetType;
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataType type = typeFactory.builder()
-              .add(SqlUtil.deriveAliasFromOrdinal(0), componentType).build();
-          return typeFactory.createMultisetType(type, -1);
-        }
-      };
+  public static final SqlReturnTypeInference MULTISET_RECORD = opBinding -> {
+    assert opBinding.getOperandCount() == 1;
+    final RelDataType multisetType = opBinding.getOperandType(0);
+    RelDataType componentType = multisetType.getComponentType();
+    assert componentType != null : "expected a multiset type: "
+        + multisetType;
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    final RelDataType type = typeFactory.builder()
+        .add(SqlUtil.deriveAliasFromOrdinal(0), componentType).build();
+    return typeFactory.createMultisetType(type, -1);
+  };
   /**
    * Returns the field type of a structured type which has only one field. For
    * example, given {@code RECORD(x INTEGER)} returns {@code INTEGER}.
    */
-  public static final SqlReturnTypeInference RECORD_TO_SCALAR =
-      new SqlReturnTypeInference() {
-        public RelDataType inferReturnType(
-            SqlOperatorBinding opBinding) {
-          assert opBinding.getOperandCount() == 1;
+  public static final SqlReturnTypeInference RECORD_TO_SCALAR = opBinding -> {
+    assert opBinding.getOperandCount() == 1;
 
-          final RelDataType recordType = opBinding.getOperandType(0);
+    final RelDataType recordType = opBinding.getOperandType(0);
 
-          boolean isStruct = recordType.isStruct();
-          int fieldCount = recordType.getFieldCount();
+    boolean isStruct = recordType.isStruct();
+    int fieldCount = recordType.getFieldCount();
 
-          assert isStruct && (fieldCount == 1);
+    assert isStruct && (fieldCount == 1);
 
-          RelDataTypeField fieldType = recordType.getFieldList().get(0);
-          assert fieldType != null
-              : "expected a record type with one field: "
-              + recordType;
-          final RelDataType firstColType = fieldType.getType();
-          return opBinding.getTypeFactory().createTypeWithNullability(
-              firstColType,
-              true);
-        }
-      };
+    RelDataTypeField fieldType = recordType.getFieldList().get(0);
+    assert fieldType != null
+        : "expected a record type with one field: "
+        + recordType;
+    final RelDataType firstColType = fieldType.getType();
+    return opBinding.getTypeFactory().createTypeWithNullability(
+        firstColType,
+        true);
+  };
 
   /**
    * Type-inference strategy for SUM aggregate function inferred from the
@@ -753,20 +710,16 @@ public abstract class ReturnTypes {
    * with the default implementation of RelDataTypeSystem, s has the same
    * type name as x.
    */
-  public static final SqlReturnTypeInference AGG_SUM =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataType type = typeFactory.getTypeSystem()
-              .deriveSumType(typeFactory, opBinding.getOperandType(0));
-          if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
-            return typeFactory.createTypeWithNullability(type, true);
-          } else {
-            return type;
-          }
-        }
-      };
+  public static final SqlReturnTypeInference AGG_SUM = opBinding -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    final RelDataType type = typeFactory.getTypeSystem()
+        .deriveSumType(typeFactory, opBinding.getOperandType(0));
+    if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
+      return typeFactory.createTypeWithNullability(type, true);
+    } else {
+      return type;
+    }
+  };
 
   /**
    * Type-inference strategy for $SUM0 aggregate function inferred from the
@@ -775,72 +728,55 @@ public abstract class ReturnTypes {
    * x.
    */
   public static final SqlReturnTypeInference AGG_SUM_EMPTY_IS_ZERO =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataType sumType = typeFactory.getTypeSystem()
-              .deriveSumType(typeFactory, opBinding.getOperandType(0));
-          // SUM0 should not return null.
-          return typeFactory.createTypeWithNullability(sumType, false);
-        }
+      opBinding -> {
+        final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+        final RelDataType sumType = typeFactory.getTypeSystem()
+            .deriveSumType(typeFactory, opBinding.getOperandType(0));
+        // SUM0 should not return null.
+        return typeFactory.createTypeWithNullability(sumType, false);
       };
 
   /**
    * Type-inference strategy for the {@code CUME_DIST} and {@code PERCENT_RANK}
    * aggregate functions.
    */
-  public static final SqlReturnTypeInference FRACTIONAL_RANK =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          return typeFactory.getTypeSystem().deriveFractionalRankType(typeFactory);
-        }
-      };
+  public static final SqlReturnTypeInference FRACTIONAL_RANK = opBinding -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    return typeFactory.getTypeSystem().deriveFractionalRankType(typeFactory);
+  };
 
   /**
    * Type-inference strategy for the {@code NTILE}, {@code RANK},
    * {@code DENSE_RANK}, and {@code ROW_NUMBER} aggregate functions.
    */
-  public static final SqlReturnTypeInference RANK =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          return typeFactory.getTypeSystem().deriveRankType(typeFactory);
-        }
-      };
-
-  public static final SqlReturnTypeInference AVG_AGG_FUNCTION =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataType relDataType = typeFactory.getTypeSystem().deriveAvgAggType(
-              typeFactory, opBinding.getOperandType(0));
-          if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
-            return typeFactory.createTypeWithNullability(relDataType, true);
-          } else {
-            return relDataType;
-          }
-        }
-      };
-
-  public static final SqlReturnTypeInference COVAR_FUNCTION =
-      new SqlReturnTypeInference() {
-        @Override public RelDataType
-        inferReturnType(SqlOperatorBinding opBinding) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          final RelDataType relDataType = typeFactory.getTypeSystem().deriveCovarType(
-              typeFactory, opBinding.getOperandType(0), opBinding.getOperandType(1));
-          if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
-            return typeFactory.createTypeWithNullability(relDataType, true);
-          } else {
-            return relDataType;
-          }
-        }
-      };
+  public static final SqlReturnTypeInference RANK = opBinding -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    return typeFactory.getTypeSystem().deriveRankType(typeFactory);
+  };
+
+  public static final SqlReturnTypeInference AVG_AGG_FUNCTION = opBinding -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    final RelDataType relDataType =
+        typeFactory.getTypeSystem().deriveAvgAggType(typeFactory,
+            opBinding.getOperandType(0));
+    if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
+      return typeFactory.createTypeWithNullability(relDataType, true);
+    } else {
+      return relDataType;
+    }
+  };
+
+  public static final SqlReturnTypeInference COVAR_FUNCTION = opBinding -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    final RelDataType relDataType =
+        typeFactory.getTypeSystem().deriveCovarType(typeFactory,
+            opBinding.getOperandType(0), opBinding.getOperandType(1));
+    if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
+      return typeFactory.createTypeWithNullability(relDataType, true);
+    } else {
+      return relDataType;
+    }
+  };
 }
 
 // End ReturnTypes.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
index 038ead3..77f11fa 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRules.java
@@ -16,7 +16,6 @@
  */
 package org.apache.calcite.sql.type;
 
-import com.google.common.base.Preconditions;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -28,9 +27,9 @@ import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
-import javax.annotation.Nonnull;
 
 /**
  * Rules that determine whether a type is assignable from another type.
@@ -371,8 +370,8 @@ public class SqlTypeAssignmentRules {
   public boolean canCastFrom(
       SqlTypeName to,
       SqlTypeName from) {
-    Preconditions.checkNotNull(to);
-    Preconditions.checkNotNull(from);
+    Objects.requireNonNull(to);
+    Objects.requireNonNull(from);
 
     if (to == SqlTypeName.NULL) {
       return false;
@@ -400,13 +399,8 @@ public class SqlTypeAssignmentRules {
     Builder() {
       this.map = new HashMap<>();
       this.sets =
-          CacheBuilder.newBuilder().build(
-              new CacheLoader<Set<SqlTypeName>, ImmutableSet<SqlTypeName>>() {
-                public ImmutableSet<SqlTypeName> load(
-                    @Nonnull Set<SqlTypeName> key) {
-                  return Sets.immutableEnumSet(key);
-                }
-              });
+          CacheBuilder.newBuilder()
+              .build(CacheLoader.from(set -> Sets.immutableEnumSet(set)));
     }
 
     /** Creates a Builder as a copy of another Builder. */

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransforms.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransforms.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransforms.java
index 0ff8525..81efd2b 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransforms.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransforms.java
@@ -22,9 +22,8 @@ import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.sql.SqlOperatorBinding;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
-
 import java.util.List;
+import java.util.Objects;
 
 /**
  * SqlTypeTransforms defines a number of reusable instances of
@@ -44,78 +43,53 @@ public abstract class SqlTypeTransforms {
    * nullable
    */
   public static final SqlTypeTransform TO_NULLABLE =
-      new SqlTypeTransform() {
-        public RelDataType transformType(
-            SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          return SqlTypeUtil.makeNullableIfOperandsAre(
-              opBinding.getTypeFactory(),
+      (opBinding, typeToTransform) ->
+          SqlTypeUtil.makeNullableIfOperandsAre(opBinding.getTypeFactory(),
               opBinding.collectOperandTypes(),
-              Preconditions.checkNotNull(typeToTransform));
-        }
-      };
+              Objects.requireNonNull(typeToTransform));
 
   /**
    * Parameter type-inference transform strategy where a derived type is
    * transformed into the same type, but nullable if and only if all of a call's
    * operands are nullable.
    */
-  public static final SqlTypeTransform TO_NULLABLE_ALL =
-      new SqlTypeTransform() {
-        public RelDataType transformType(SqlOperatorBinding opBinding,
-            RelDataType type) {
-          final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
-          return typeFactory.createTypeWithNullability(type,
-              SqlTypeUtil.allNullable(opBinding.collectOperandTypes()));
-        }
-      };
+  public static final SqlTypeTransform TO_NULLABLE_ALL = (opBinding, type) -> {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    return typeFactory.createTypeWithNullability(type,
+        SqlTypeUtil.allNullable(opBinding.collectOperandTypes()));
+  };
 
   /**
    * Parameter type-inference transform strategy where a derived type is
    * transformed into the same type but not nullable.
    */
   public static final SqlTypeTransform TO_NOT_NULLABLE =
-      new SqlTypeTransform() {
-        public RelDataType transformType(
-            SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          return opBinding.getTypeFactory().createTypeWithNullability(
-              Preconditions.checkNotNull(typeToTransform),
-              false);
-        }
-      };
+      (opBinding, typeToTransform) ->
+          opBinding.getTypeFactory().createTypeWithNullability(
+              Objects.requireNonNull(typeToTransform), false);
 
   /**
    * Parameter type-inference transform strategy where a derived type is
    * transformed into the same type with nulls allowed.
    */
   public static final SqlTypeTransform FORCE_NULLABLE =
-      new SqlTypeTransform() {
-        public RelDataType transformType(
-            SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          return opBinding.getTypeFactory().createTypeWithNullability(
-              Preconditions.checkNotNull(typeToTransform),
-              true);
-        }
-      };
+      (opBinding, typeToTransform) ->
+          opBinding.getTypeFactory().createTypeWithNullability(
+              Objects.requireNonNull(typeToTransform), true);
 
   /**
    * Type-inference strategy whereby the result is NOT NULL if any of
    * the arguments is NOT NULL; otherwise the type is unchanged.
    */
   public static final SqlTypeTransform LEAST_NULLABLE =
-      new SqlTypeTransform() {
-        public RelDataType transformType(SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          for (RelDataType type : opBinding.collectOperandTypes()) {
-            if (!type.isNullable()) {
-              return opBinding.getTypeFactory()
-                  .createTypeWithNullability(typeToTransform, false);
-            }
+      (opBinding, typeToTransform) -> {
+        for (RelDataType type : opBinding.collectOperandTypes()) {
+          if (!type.isNullable()) {
+            return opBinding.getTypeFactory()
+                .createTypeWithNullability(typeToTransform, false);
           }
-          return typeToTransform;
         }
+        return typeToTransform;
       };
 
   /**
@@ -176,13 +150,7 @@ public abstract class SqlTypeTransforms {
    * @see MultisetSqlType#getComponentType
    */
   public static final SqlTypeTransform TO_MULTISET_ELEMENT_TYPE =
-      new SqlTypeTransform() {
-        public RelDataType transformType(
-            SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          return typeToTransform.getComponentType();
-        }
-      };
+      (opBinding, typeToTransform) -> typeToTransform.getComponentType();
 
   /**
    * Parameter type-inference transform strategy that wraps a given type
@@ -191,13 +159,8 @@ public abstract class SqlTypeTransforms {
    * @see org.apache.calcite.rel.type.RelDataTypeFactory#createMultisetType(RelDataType, long)
    */
   public static final SqlTypeTransform TO_MULTISET =
-      new SqlTypeTransform() {
-        public RelDataType transformType(SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          return opBinding.getTypeFactory().createMultisetType(typeToTransform,
-              -1);
-        }
-      };
+      (opBinding, typeToTransform) ->
+          opBinding.getTypeFactory().createMultisetType(typeToTransform, -1);
 
   /**
    * Parameter type-inference transform strategy where a derived type must be
@@ -205,15 +168,10 @@ public abstract class SqlTypeTransforms {
    * of that field.
    */
   public static final SqlTypeTransform ONLY_COLUMN =
-      new SqlTypeTransform() {
-        public RelDataType transformType(
-            SqlOperatorBinding opBinding,
-            RelDataType typeToTransform) {
-          final List<RelDataTypeField> fields =
-              typeToTransform.getFieldList();
-          assert fields.size() == 1;
-          return fields.get(0).getType();
-        }
+      (opBinding, typeToTransform) -> {
+        final List<RelDataTypeField> fields = typeToTransform.getFieldList();
+        assert fields.size() == 1;
+        return fields.get(0).getType();
       };
 }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
index 5b3ddab..c774c61 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
@@ -36,9 +36,7 @@ import org.apache.calcite.util.NumberUtil;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 import java.nio.charset.Charset;
@@ -46,6 +44,7 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -66,7 +65,7 @@ public abstract class SqlTypeUtil {
     assert argTypes.size() >= 2;
 
     // Filter out ANY elements.
-    List<RelDataType> argTypes2 = Lists.newArrayList();
+    List<RelDataType> argTypes2 = new ArrayList<>();
     for (RelDataType t : argTypes) {
       if (!isAny(t)) {
         argTypes2.add(t);
@@ -202,7 +201,7 @@ public abstract class SqlTypeUtil {
       final RelDataTypeFactory typeFactory,
       final List<RelDataType> argTypes,
       RelDataType type) {
-    Preconditions.checkNotNull(type);
+    Objects.requireNonNull(type);
     if (containsNullable(argTypes)) {
       type = typeFactory.createTypeWithNullability(type, true);
     }
@@ -1183,8 +1182,8 @@ public abstract class SqlTypeUtil {
   public static RelDataType createEmptyStructType(
       RelDataTypeFactory typeFactory) {
     return typeFactory.createStructType(
-        ImmutableList.<RelDataType>of(),
-        ImmutableList.<String>of());
+        ImmutableList.of(),
+        ImmutableList.of());
   }
 
   /** Returns whether a type is flat. It is not flat if it is a record type that

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/util/SqlShuttle.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/util/SqlShuttle.java b/core/src/main/java/org/apache/calcite/sql/util/SqlShuttle.java
index c4e6f67..064883b 100644
--- a/core/src/main/java/org/apache/calcite/sql/util/SqlShuttle.java
+++ b/core/src/main/java/org/apache/calcite/sql/util/SqlShuttle.java
@@ -108,7 +108,7 @@ public class SqlShuttle extends SqlBasicVisitor<SqlNode> {
       this.call = call;
       this.update = false;
       final List<SqlNode> operands = call.getOperandList();
-      this.clonedOperands = operands.toArray(new SqlNode[operands.size()]);
+      this.clonedOperands = operands.toArray(new SqlNode[0]);
       this.alwaysCopy = alwaysCopy;
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java b/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
index cf45da2..a00a523 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
@@ -209,7 +209,7 @@ class AggChecker extends SqlBasicVisitor<Void> {
 
     // Visit the operands (only expressions).
     call.getOperator()
-        .acceptCall(this, call, true, ArgHandlerImpl.<Void>instance());
+        .acceptCall(this, call, true, ArgHandlerImpl.instance());
 
     // Restore scope.
     scopes.pop();

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/AggVisitor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AggVisitor.java b/core/src/main/java/org/apache/calcite/sql/validate/AggVisitor.java
index 3bbd16d..44dfcfa 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AggVisitor.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AggVisitor.java
@@ -25,8 +25,7 @@ import org.apache.calcite.sql.SqlSyntax;
 import org.apache.calcite.sql.fun.SqlAbstractGroupFunction;
 import org.apache.calcite.sql.util.SqlBasicVisitor;
 
-import com.google.common.collect.Lists;
-
+import java.util.ArrayList;
 import java.util.List;
 
 /** Visitor that can find aggregate and windowed aggregate functions.
@@ -82,7 +81,7 @@ abstract class AggVisitor extends SqlBasicVisitor<Void> {
     if (operator instanceof SqlFunction) {
       final SqlFunction sqlFunction = (SqlFunction) operator;
       if (sqlFunction.getFunctionType().isUserDefinedNotSpecificFunction()) {
-        final List<SqlOperator> list = Lists.newArrayList();
+        final List<SqlOperator> list = new ArrayList<>();
         opTab.lookupOperatorOverloads(sqlFunction.getSqlIdentifier(),
             sqlFunction.getFunctionType(), SqlSyntax.FUNCTION, list);
         for (SqlOperator operator2 : list) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java b/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
index 5df9374..5c23e1d 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
@@ -27,7 +27,6 @@ import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.Litmus;
 import org.apache.calcite.util.Pair;
 
-import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -37,6 +36,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.Supplier;
 
 import static org.apache.calcite.sql.SqlUtil.stripAs;
 
@@ -58,18 +58,15 @@ public class AggregatingSelectScope
   private List<SqlNode> temporaryGroupExprList;
 
   public final Supplier<Resolved> resolved =
-      Suppliers.memoize(
-          new Supplier<Resolved>() {
-            public Resolved get() {
-              assert temporaryGroupExprList == null;
-              temporaryGroupExprList = new ArrayList<>();
-              try {
-                return resolve();
-              } finally {
-                temporaryGroupExprList = null;
-              }
-            }
-          });
+      Suppliers.memoize(() -> {
+        assert temporaryGroupExprList == null;
+        temporaryGroupExprList = new ArrayList<>();
+        try {
+          return resolve();
+        } finally {
+          temporaryGroupExprList = null;
+        }
+      })::get;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -149,18 +146,18 @@ public class AggregatingSelectScope
       for (SqlNode selectItem : selectScope.getExpandedSelectList()) {
         groupExprs.add(stripAs(selectItem));
       }
-      return Pair.of(ImmutableList.<SqlNode>of(), groupExprs.build());
+      return Pair.of(ImmutableList.of(), groupExprs.build());
     } else if (select.getGroup() != null) {
       if (temporaryGroupExprList != null) {
         // we are in the middle of resolving
-        return Pair.of(ImmutableList.<SqlNode>of(),
+        return Pair.of(ImmutableList.of(),
             ImmutableList.copyOf(temporaryGroupExprList));
       } else {
         final Resolved resolved = this.resolved.get();
         return Pair.of(resolved.extraExprList, resolved.groupExprList);
       }
     } else {
-      return Pair.of(ImmutableList.<SqlNode>of(), ImmutableList.<SqlNode>of());
+      return Pair.of(ImmutableList.of(), ImmutableList.of());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/CatalogScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/CatalogScope.java b/core/src/main/java/org/apache/calcite/sql/validate/CatalogScope.java
index 1420123..44cee30 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/CatalogScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/CatalogScope.java
@@ -17,13 +17,11 @@
 package org.apache.calcite.sql.validate;
 
 import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.linq4j.function.Function1;
-import org.apache.calcite.linq4j.function.Predicate1;
 import org.apache.calcite.sql.SqlNode;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Sets;
 
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -51,20 +49,10 @@ class CatalogScope extends DelegatingScope {
     this.schemaNames =
         Linq4j.asEnumerable(
             validator.getCatalogReader()
-                .getAllSchemaObjectNames(ImmutableList.<String>of()))
-            .where(
-                new Predicate1<SqlMoniker>() {
-                  public boolean apply(SqlMoniker input) {
-                    return input.getType() == SqlMonikerType.SCHEMA;
-                  }
-                })
-            .select(
-                new Function1<SqlMoniker, List<String>>() {
-                  public List<String> apply(SqlMoniker input) {
-                    return input.getFullyQualifiedNames();
-                  }
-                })
-            .into(Sets.<List<String>>newHashSet());
+                .getAllSchemaObjectNames(ImmutableList.of()))
+            .where(input -> input.getType() == SqlMonikerType.SCHEMA)
+            .select(SqlMoniker::getFullyQualifiedNames)
+            .into(new HashSet<>());
   }
 
   //~ Methods ----------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
index b1b01d2..cf5d9d2 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
@@ -462,7 +462,7 @@ public abstract class DelegatingScope implements SqlValidatorScope {
                 return kind;
               }
             };
-        Collections.sort(resolved.resolves, c);
+        resolved.resolves.sort(c);
         if (c.compare(resolved.resolves.get(0), resolved.resolves.get(1)) == 0) {
           throw validator.newValidationError(suffix,
               RESOURCE.columnAmbiguous(suffix.toString()));

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java
index e3395db..8546742 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java
@@ -25,12 +25,12 @@ import org.apache.calcite.sql.SqlNodeList;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.util.Pair;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import javax.annotation.Nullable;
 
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -74,7 +74,7 @@ public class IdentifierNamespace extends AbstractNamespace {
     super(validator, enclosingNode);
     this.id = id;
     this.extendList = extendList;
-    this.parentScope = Preconditions.checkNotNull(parentScope);
+    this.parentScope = Objects.requireNonNull(parentScope);
   }
 
   IdentifierNamespace(SqlValidatorImpl validator, SqlNode node,
@@ -174,7 +174,7 @@ public class IdentifierNamespace extends AbstractNamespace {
   }
 
   public RelDataType validateImpl(RelDataType targetRowType) {
-    resolvedNamespace = Preconditions.checkNotNull(resolveImpl(id));
+    resolvedNamespace = Objects.requireNonNull(resolveImpl(id));
     if (resolvedNamespace instanceof TableNamespace) {
       SqlValidatorTable table = resolvedNamespace.getTable();
       if (validator.shouldExpandIdentifiers()) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
index 3537e01..741481e 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
@@ -23,7 +23,6 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
@@ -32,6 +31,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -57,7 +57,7 @@ public abstract class ListScope extends DelegatingScope {
 
   @Override public void addChild(SqlValidatorNamespace ns, String alias,
       boolean nullable) {
-    Preconditions.checkNotNull(alias);
+    Objects.requireNonNull(alias);
     children.add(new ScopeChild(children.size(), alias, ns, nullable));
   }
 
@@ -67,7 +67,7 @@ public abstract class ListScope extends DelegatingScope {
    * @return list of child namespaces
    */
   public List<SqlValidatorNamespace> getChildren() {
-    return Lists.transform(children, ScopeChild.NAMESPACE_FN);
+    return Lists.transform(children, scopeChild -> scopeChild.namespace);
   }
 
   /**
@@ -76,7 +76,7 @@ public abstract class ListScope extends DelegatingScope {
    * @return list of child namespaces
    */
   List<String> getChildNames() {
-    return Lists.transform(children, ScopeChild.NAME_FN);
+    return Lists.transform(children, scopeChild -> scopeChild.name);
   }
 
   private ScopeChild findChild(List<String> names,

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SchemaNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SchemaNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/SchemaNamespace.java
index ab0c4a3..4580aa9 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SchemaNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SchemaNamespace.java
@@ -21,10 +21,10 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
+import java.util.Objects;
 
 /** Namespace based on a schema.
  *
@@ -37,7 +37,7 @@ class SchemaNamespace extends AbstractNamespace {
   /** Creates a SchemaNamespace. */
   SchemaNamespace(SqlValidatorImpl validator, ImmutableList<String> names) {
     super(validator, null);
-    this.names = Preconditions.checkNotNull(names);
+    this.names = Objects.requireNonNull(names);
   }
 
   protected RelDataType validateImpl(RelDataType targetRowType) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/ScopeChild.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/ScopeChild.java b/core/src/main/java/org/apache/calcite/sql/validate/ScopeChild.java
index 2b210b4..b04f0e5 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/ScopeChild.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/ScopeChild.java
@@ -16,7 +16,6 @@
  */
 package org.apache.calcite.sql.validate;
 
-import com.google.common.base.Function;
 
 /** One of the inputs of a {@link SqlValidatorScope}.
  *
@@ -29,20 +28,6 @@ class ScopeChild {
   final SqlValidatorNamespace namespace;
   final boolean nullable;
 
-  static final Function<ScopeChild, SqlValidatorNamespace> NAMESPACE_FN =
-      new Function<ScopeChild, SqlValidatorNamespace>() {
-        public SqlValidatorNamespace apply(ScopeChild input) {
-          return input.namespace;
-        }
-      };
-
-  static final Function<ScopeChild, String> NAME_FN =
-      new Function<ScopeChild, String>() {
-        public String apply(ScopeChild input) {
-          return input.name;
-        }
-      };
-
   /** Creates a ScopeChild.
    *
    * @param ordinal Ordinal of child within parent scope

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlIdentifierMoniker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlIdentifierMoniker.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlIdentifierMoniker.java
index 29a75e0..39c8b8c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlIdentifierMoniker.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlIdentifierMoniker.java
@@ -18,9 +18,8 @@ package org.apache.calcite.sql.validate;
 
 import org.apache.calcite.sql.SqlIdentifier;
 
-import com.google.common.base.Preconditions;
-
 import java.util.List;
+import java.util.Objects;
 
 /**
  * An implementation of {@link SqlMoniker} that encapsulates the normalized name
@@ -37,7 +36,7 @@ public class SqlIdentifierMoniker implements SqlMoniker {
    * Creates an SqlIdentifierMoniker.
    */
   public SqlIdentifierMoniker(SqlIdentifier id) {
-    this.id = Preconditions.checkNotNull(id);
+    this.id = Objects.requireNonNull(id);
   }
 
   //~ Methods ----------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlMonikerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlMonikerImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlMonikerImpl.java
index e2c5825..b802c4a 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlMonikerImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlMonikerImpl.java
@@ -20,7 +20,6 @@ import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
@@ -42,7 +41,7 @@ public class SqlMonikerImpl implements SqlMoniker {
    */
   public SqlMonikerImpl(List<String> names, SqlMonikerType type) {
     this.names = ImmutableList.copyOf(names);
-    this.type = Preconditions.checkNotNull(type);
+    this.type = Objects.requireNonNull(type);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedAggFunction.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedAggFunction.java
index 68c954f..0cf8c0f 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedAggFunction.java
@@ -33,7 +33,6 @@ import org.apache.calcite.sql.type.SqlReturnTypeInference;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Function;
 import com.google.common.collect.Lists;
 
 import java.util.ArrayList;
@@ -76,12 +75,7 @@ public class SqlUserDefinedAggFunction extends SqlAggFunction {
   }
 
   private List<RelDataType> toSql(List<RelDataType> types) {
-    return Lists.transform(types,
-        new com.google.common.base.Function<RelDataType, RelDataType>() {
-          public RelDataType apply(RelDataType type) {
-            return toSql(type);
-          }
-        });
+    return Lists.transform(types, this::toSql);
   }
 
   private RelDataType toSql(RelDataType type) {
@@ -98,11 +92,7 @@ public class SqlUserDefinedAggFunction extends SqlAggFunction {
   public List<RelDataType> getParameterTypes(
       final RelDataTypeFactory typeFactory) {
     return Lists.transform(function.getParameters(),
-        new Function<FunctionParameter, RelDataType>() {
-          public RelDataType apply(FunctionParameter input) {
-            return input.getType(typeFactory);
-          }
-        });
+        parameter -> parameter.getType(typeFactory));
   }
 
   @SuppressWarnings("deprecation")

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedFunction.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedFunction.java
index cc3ed3f..0c2c796 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedFunction.java
@@ -75,7 +75,8 @@ public class SqlUserDefinedFunction extends SqlFunction {
   }
 
   @Override public List<String> getParamNames() {
-    return Lists.transform(function.getParameters(), FunctionParameter.NAME_FN);
+    return Lists.transform(function.getParameters(),
+        FunctionParameter::getName);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedTableMacro.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedTableMacro.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedTableMacro.java
index 4f191ac..153ad2c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedTableMacro.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlUserDefinedTableMacro.java
@@ -21,7 +21,6 @@ import org.apache.calcite.linq4j.tree.BlockBuilder;
 import org.apache.calcite.linq4j.tree.Expression;
 import org.apache.calcite.linq4j.tree.Expressions;
 import org.apache.calcite.linq4j.tree.FunctionExpression;
-import org.apache.calcite.linq4j.tree.ParameterExpression;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
@@ -45,13 +44,13 @@ import org.apache.calcite.util.NlsString;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * User-defined table macro.
@@ -69,14 +68,14 @@ public class SqlUserDefinedTableMacro extends SqlFunction {
       TableMacro tableMacro) {
     super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
         returnTypeInference, operandTypeInference, operandTypeChecker,
-        Preconditions.checkNotNull(paramTypes),
+        Objects.requireNonNull(paramTypes),
         SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
     this.tableMacro = tableMacro;
   }
 
   @Override public List<String> getParamNames() {
     return Lists.transform(tableMacro.getParameters(),
-        FunctionParameter.NAME_FN);
+        FunctionParameter::getName);
   }
 
   /** Returns the table in this UDF, or null if there is no table. */
@@ -133,7 +132,7 @@ public class SqlUserDefinedTableMacro extends SqlFunction {
   private static Object getValue(SqlNode right) throws NonLiteralException {
     switch (right.getKind()) {
     case ARRAY_VALUE_CONSTRUCTOR:
-      final List<Object> list = Lists.newArrayList();
+      final List<Object> list = new ArrayList<>();
       for (SqlNode o : ((SqlCall) right).getOperandList()) {
         list.add(getValue(o));
       }
@@ -188,8 +187,7 @@ public class SqlUserDefinedTableMacro extends SqlFunction {
         RexToLixTranslator.convert(Expressions.constant(o), clazz);
     bb.add(Expressions.return_(null, expr));
     final FunctionExpression convert =
-        Expressions.lambda(bb.toBlock(),
-            Collections.<ParameterExpression>emptyList());
+        Expressions.lambda(bb.toBlock(), Collections.emptyList());
     return convert.compile().dynamicInvoke();
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 0dd9308..71b4b76 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -102,10 +102,7 @@ import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteTrace;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
@@ -130,7 +127,9 @@ import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
+import java.util.function.Supplier;
 
 import static org.apache.calcite.sql.SqlUtil.stripAs;
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -298,10 +297,10 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       SqlValidatorCatalogReader catalogReader,
       RelDataTypeFactory typeFactory,
       SqlConformance conformance) {
-    this.opTab = Preconditions.checkNotNull(opTab);
-    this.catalogReader = Preconditions.checkNotNull(catalogReader);
-    this.typeFactory = Preconditions.checkNotNull(typeFactory);
-    this.conformance = Preconditions.checkNotNull(conformance);
+    this.opTab = Objects.requireNonNull(opTab);
+    this.catalogReader = Objects.requireNonNull(catalogReader);
+    this.typeFactory = Objects.requireNonNull(typeFactory);
+    this.conformance = Objects.requireNonNull(conformance);
 
     unknownType = typeFactory.createUnknownType();
     booleanType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
@@ -533,7 +532,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
         }
       }
       // If NATURAL JOIN or USING is present, move key fields to the front of
-      // the list.
+      // the list, per standard SQL. Disabled if there are dynamic fields.
       if (!hasDynamicStruct || Bug.CALCITE_2400_FIXED) {
         new Permute(scope.getNode().getFrom(), 0).permute(selectItems, fields);
       }
@@ -1583,8 +1582,8 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
    */
   @SuppressWarnings("deprecation")
   public final void setValidatedNodeType(SqlNode node, RelDataType type) {
-    Preconditions.checkNotNull(type);
-    Preconditions.checkNotNull(node);
+    Objects.requireNonNull(type);
+    Objects.requireNonNull(node);
     if (type.equals(unknownType)) {
       // don't set anything until we know what it is, and don't overwrite
       // a known type with the unknown type
@@ -1600,8 +1599,8 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   public RelDataType deriveType(
       SqlValidatorScope scope,
       SqlNode expr) {
-    Preconditions.checkNotNull(scope);
-    Preconditions.checkNotNull(expr);
+    Objects.requireNonNull(scope);
+    Objects.requireNonNull(expr);
 
     // if we already know the type, no need to re-derive
     RelDataType type = nodeToTypeMap.get(expr);
@@ -1628,9 +1627,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       SqlNode operand) {
     DeriveTypeVisitor v = new DeriveTypeVisitor(scope);
     final RelDataType type = operand.accept(v);
-    // After Guava 17, use Verify.verifyNotNull for Preconditions.checkNotNull
-    Bug.upgrade("guava-17");
-    return Preconditions.checkNotNull(scope.nullifyType(operand, type));
+    return Objects.requireNonNull(scope.nullifyType(operand, type));
   }
 
   public RelDataType deriveConstructorType(
@@ -1854,7 +1851,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   }
 
   public void setDefaultNullCollation(NullCollation nullCollation) {
-    this.nullCollation = Preconditions.checkNotNull(nullCollation);
+    this.nullCollation = Objects.requireNonNull(nullCollation);
   }
 
   public NullCollation getDefaultNullCollation() {
@@ -2356,8 +2353,8 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       String alias,
       boolean forceNullable,
       boolean checkUpdate) {
-    Preconditions.checkNotNull(node);
-    Preconditions.checkNotNull(enclosingNode);
+    Objects.requireNonNull(node);
+    Objects.requireNonNull(enclosingNode);
     Preconditions.checkArgument(usingScope == null || alias != null);
 
     SqlCall call;
@@ -3011,7 +3008,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       SqlNode node,
       RelDataType targetRowType,
       SqlValidatorScope scope) {
-    Preconditions.checkNotNull(targetRowType);
+    Objects.requireNonNull(targetRowType);
     switch (node.getKind()) {
     case AS:
       validateFrom(
@@ -3252,12 +3249,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     final SelectScope fromScope = (SelectScope) getFromScope(select);
     List<String> names = fromScope.getChildNames();
     if (!catalogReader.nameMatcher().isCaseSensitive()) {
-      names = Lists.transform(names,
-          new Function<String, String>() {
-            public String apply(String s) {
-              return s.toUpperCase(Locale.ROOT);
-            }
-          });
+      names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT));
     }
     final int duplicateAliasOrdinal = Util.firstDuplicate(names);
     if (duplicateAliasOrdinal >= 0) {
@@ -3581,7 +3573,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
 
         if (supportsModalityCount == 0) {
           if (fail) {
-            String inputs = Joiner.on(", ").join(scope.getChildNames());
+            String inputs = String.join(", ", scope.getChildNames());
             throw newValidationError(select,
                 Static.RESOURCE.cannotStreamResultsForNonStreamingInputs(inputs));
           } else {
@@ -3791,7 +3783,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       }
     }
     final SqlValidatorScope orderScope = getOrderScope(select);
-    Preconditions.checkNotNull(orderScope);
+    Objects.requireNonNull(orderScope);
 
     List<SqlNode> expandList = new ArrayList<>();
     for (SqlNode orderItem : orderList) {
@@ -4009,7 +4001,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
     final SqlValidatorScope selectScope = getSelectScope(select);
     final List<SqlNode> expandedSelectItems = new ArrayList<>();
-    final Set<String> aliases = Sets.newHashSet();
+    final Set<String> aliases = new HashSet<>();
     final List<Map.Entry<String, RelDataType>> fieldList = new ArrayList<>();
 
     for (int i = 0; i < selectItems.size(); i++) {
@@ -5173,7 +5165,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       // "LOCALTIME", which would have been handled as a
       // SqlIdentifier.)
       throw handleUnresolvedFunction(call, (SqlFunction) operator,
-          ImmutableList.<RelDataType>of(), null);
+          ImmutableList.of(), null);
     }
 
     SqlValidatorScope operandScope = scope.getOperandScope(call);
@@ -5361,7 +5353,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     InsertNamespace(SqlValidatorImpl validator, SqlInsert node,
         SqlNode enclosingNode, SqlValidatorScope parentScope) {
       super(validator, node.getTargetTable(), enclosingNode, parentScope);
-      this.node = Preconditions.checkNotNull(node);
+      this.node = Objects.requireNonNull(node);
     }
 
     public SqlInsert getNode() {
@@ -5378,7 +5370,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     UpdateNamespace(SqlValidatorImpl validator, SqlUpdate node,
         SqlNode enclosingNode, SqlValidatorScope parentScope) {
       super(validator, node.getTargetTable(), enclosingNode, parentScope);
-      this.node = Preconditions.checkNotNull(node);
+      this.node = Objects.requireNonNull(node);
     }
 
     public SqlUpdate getNode() {
@@ -5395,7 +5387,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     DeleteNamespace(SqlValidatorImpl validator, SqlDelete node,
         SqlNode enclosingNode, SqlValidatorScope parentScope) {
       super(validator, node.getTargetTable(), enclosingNode, parentScope);
-      this.node = Preconditions.checkNotNull(node);
+      this.node = Objects.requireNonNull(node);
     }
 
     public SqlDelete getNode() {
@@ -5412,7 +5404,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     MergeNamespace(SqlValidatorImpl validator, SqlMerge node,
         SqlNode enclosingNode, SqlValidatorScope parentScope) {
       super(validator, node.getTargetTable(), enclosingNode, parentScope);
-      this.node = Preconditions.checkNotNull(node);
+      this.node = Objects.requireNonNull(node);
     }
 
     public SqlMerge getNode() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorScope.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorScope.java
index 21c1a5a..98a32dc 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorScope.java
@@ -26,8 +26,6 @@ import org.apache.calcite.sql.SqlSelect;
 import org.apache.calcite.sql.SqlWindow;
 import org.apache.calcite.util.Pair;
 
-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 com.google.common.collect.Lists;
@@ -36,6 +34,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Name-resolution scope. Represents any position in a parse tree than an
@@ -241,12 +240,7 @@ public interface SqlValidatorScope {
 
     /** Returns a list ["step1", "step2"]. */
     List<String> stepNames() {
-      return Lists.transform(steps(),
-          new Function<Step, String>() {
-            public String apply(Step input) {
-              return input.name;
-            }
-          });
+      return Lists.transform(steps(), input -> input.name);
     }
 
     protected void build(ImmutableList.Builder<Step> paths) {
@@ -271,11 +265,11 @@ public interface SqlValidatorScope {
 
     Step(Path parent, RelDataType rowType, int i, String name,
         StructKind kind) {
-      this.parent = Preconditions.checkNotNull(parent);
+      this.parent = Objects.requireNonNull(parent);
       this.rowType = rowType; // may be null
       this.i = i;
       this.name = name;
-      this.kind = Preconditions.checkNotNull(kind);
+      this.kind = Objects.requireNonNull(kind);
     }
 
     @Override public int stepCount() {
@@ -332,12 +326,12 @@ public interface SqlValidatorScope {
 
     Resolve(SqlValidatorNamespace namespace, boolean nullable,
         SqlValidatorScope scope, Path path, List<String> remainingNames) {
-      this.namespace = Preconditions.checkNotNull(namespace);
+      this.namespace = Objects.requireNonNull(namespace);
       this.nullable = nullable;
       this.scope = scope;
       assert !(scope instanceof TableScope);
-      this.path = Preconditions.checkNotNull(path);
-      this.remainingNames = remainingNames == null ? ImmutableList.<String>of()
+      this.path = Objects.requireNonNull(path);
+      this.remainingNames = remainingNames == null ? ImmutableList.of()
           : ImmutableList.copyOf(remainingNames);
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
index 092daf9..87b8f15 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
@@ -49,12 +49,10 @@ import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
 import java.nio.charset.Charset;
 import java.util.ArrayList;
@@ -108,7 +106,7 @@ public class SqlValidatorUtil {
         final SqlValidatorTable validatorTable = tableNamespace.getTable();
         final RelDataTypeFactory typeFactory = catalogReader.getTypeFactory();
         final List<RelDataTypeField> extendedFields = dmlNamespace.extendList == null
-            ? ImmutableList.<RelDataTypeField>of()
+            ? ImmutableList.of()
             : getExtendedColumns(typeFactory, validatorTable, dmlNamespace.extendList);
         return getRelOptTable(
             tableNamespace, catalogReader, datasetName, usedDataset, extendedFields);
@@ -218,9 +216,8 @@ public class SqlValidatorUtil {
       RelDataType sourceRowType,
       Map<Integer, RelDataTypeField> indexToField) {
     ImmutableBitSet source = ImmutableBitSet.of(
-        Lists.transform(
-            sourceRowType.getFieldList(),
-            new RelDataTypeField.ToFieldIndex()));
+        Lists.transform(sourceRowType.getFieldList(),
+            RelDataTypeField::getIndex));
     ImmutableBitSet target =
         ImmutableBitSet.of(indexToField.keySet());
     return source.intersect(target);
@@ -268,11 +265,7 @@ public class SqlValidatorUtil {
   static void checkIdentifierListForDuplicates(List<SqlNode> columnList,
       SqlValidatorImpl.ValidationErrorFunction validationErrorFunction) {
     final List<List<String>> names = Lists.transform(columnList,
-        new Function<SqlNode, List<String>>() {
-          public List<String> apply(SqlNode o) {
-            return ((SqlIdentifier) o).names;
-          }
-        });
+        o -> ((SqlIdentifier) o).names);
     final int i = Util.firstDuplicate(names);
     if (i >= 0) {
       throw validationErrorFunction.apply(columnList.get(i),
@@ -444,7 +437,7 @@ public class SqlValidatorUtil {
       Suggester suggester,
       boolean caseSensitive) {
     final Set<String> used = caseSensitive
-        ? new LinkedHashSet<String>()
+        ? new LinkedHashSet<>()
         : new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
     int changeCount = 0;
     final List<String> newNameList = new ArrayList<>();
@@ -539,7 +532,7 @@ public class SqlValidatorUtil {
     // doing a contains() on a list can be expensive.
     final Set<String> uniqueNameList =
         typeFactory.getTypeSystem().isSchemaCaseSensitive()
-            ? new HashSet<String>()
+            ? new HashSet<>()
             : new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
     addFields(systemFieldList, typeList, nameList, uniqueNameList);
     addFields(leftType.getFieldList(), typeList, nameList, uniqueNameList);
@@ -717,7 +710,7 @@ public class SqlValidatorUtil {
    * {@code topBuilder}. To find the grouping sets of the query, we will take
    * the cartesian product of the group sets. */
   public static void analyzeGroupItem(SqlValidatorScope scope,
-                                      GroupAnalyzer groupAnalyzer,
+      GroupAnalyzer groupAnalyzer,
       ImmutableList.Builder<ImmutableList<ImmutableBitSet>> topBuilder,
       SqlNode groupExpr) {
     final ImmutableList.Builder<ImmutableBitSet> builder;
@@ -811,7 +804,7 @@ public class SqlValidatorUtil {
    * is grouping. */
   private static List<ImmutableBitSet> analyzeGroupTuple(SqlValidatorScope scope,
        GroupAnalyzer groupAnalyzer, List<SqlNode> operandList) {
-    List<ImmutableBitSet> list = Lists.newArrayList();
+    List<ImmutableBitSet> list = new ArrayList<>();
     for (SqlNode operand : operandList) {
       list.add(
           analyzeGroupExpr(scope, groupAnalyzer, operand));
@@ -915,7 +908,7 @@ public class SqlValidatorUtil {
   @VisibleForTesting
   public static ImmutableList<ImmutableBitSet> rollup(
       List<ImmutableBitSet> bitSets) {
-    Set<ImmutableBitSet> builder = Sets.newLinkedHashSet();
+    Set<ImmutableBitSet> builder = new LinkedHashSet<>();
     for (;;) {
       final ImmutableBitSet union = ImmutableBitSet.union(bitSets);
       builder.add(union);
@@ -940,11 +933,11 @@ public class SqlValidatorUtil {
       List<ImmutableBitSet> bitSets) {
     // Given the bit sets [{1}, {2, 3}, {5}],
     // form the lists [[{1}, {}], [{2, 3}, {}], [{5}, {}]].
-    final Set<List<ImmutableBitSet>> builder = Sets.newLinkedHashSet();
+    final Set<List<ImmutableBitSet>> builder = new LinkedHashSet<>();
     for (ImmutableBitSet bitSet : bitSets) {
       builder.add(Arrays.asList(bitSet, ImmutableBitSet.of()));
     }
-    Set<ImmutableBitSet> flattenedBitSets = Sets.newLinkedHashSet();
+    Set<ImmutableBitSet> flattenedBitSets = new LinkedHashSet<>();
     for (List<ImmutableBitSet> o : Linq4j.product(builder)) {
       flattenedBitSets.add(ImmutableBitSet.union(o));
     }
@@ -1080,7 +1073,7 @@ public class SqlValidatorUtil {
   private static List<SqlValidatorNamespace> children(SqlValidatorScope scope) {
     return scope instanceof ListScope
         ? ((ListScope) scope).getChildren()
-        : ImmutableList.<SqlValidatorNamespace>of();
+        : ImmutableList.of();
   }
 
   /**
@@ -1168,18 +1161,11 @@ public class SqlValidatorUtil {
   }
 
   public static final Suggester EXPR_SUGGESTER =
-      new Suggester() {
-        public String apply(String original, int attempt, int size) {
-          return Util.first(original, "EXPR$") + attempt;
-        }
-      };
+      (original, attempt, size) -> Util.first(original, "EXPR$") + attempt;
 
   public static final Suggester F_SUGGESTER =
-      new Suggester() {
-        public String apply(String original, int attempt, int size) {
-          return Util.first(original, "$f") + Math.max(size, attempt);
-        }
-      };
+      (original, attempt, size) -> Util.first(original, "$f")
+          + Math.max(size, attempt);
 
   /** Builds a list of GROUP BY expressions. */
   static class GroupAnalyzer {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java
index 558ffa4..1417bdf 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java
@@ -20,7 +20,6 @@ import org.apache.calcite.plan.RelOptTable;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.rel.type.RelDataTypeField;
-import org.apache.calcite.runtime.PredicateImpl;
 import org.apache.calcite.schema.ExtensibleTable;
 import org.apache.calcite.schema.Table;
 import org.apache.calcite.schema.impl.ModifiableViewTable;
@@ -29,13 +28,12 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNodeList;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -48,12 +46,12 @@ class TableNamespace extends AbstractNamespace {
   private TableNamespace(SqlValidatorImpl validator, SqlValidatorTable table,
       List<RelDataTypeField> fields) {
     super(validator, null);
-    this.table = Preconditions.checkNotNull(table);
+    this.table = Objects.requireNonNull(table);
     this.extendedFields = ImmutableList.copyOf(fields);
   }
 
   TableNamespace(SqlValidatorImpl validator, SqlValidatorTable table) {
-    this(validator, table, ImmutableList.<RelDataTypeField>of());
+    this(validator, table, ImmutableList.of());
   }
 
   protected RelDataType validateImpl(RelDataType targetRowType) {
@@ -108,8 +106,7 @@ class TableNamespace extends AbstractNamespace {
           ((RelOptTable) table).extend(extendedFields);
       final SqlValidatorTable validatorTable =
           relOptTable.unwrap(SqlValidatorTable.class);
-      return new TableNamespace(
-          validator, validatorTable, ImmutableList.<RelDataTypeField>of());
+      return new TableNamespace(validator, validatorTable, ImmutableList.of());
     }
     return new TableNamespace(validator, table, extendedFields);
   }
@@ -151,17 +148,11 @@ class TableNamespace extends AbstractNamespace {
 
         if (!extType.equals(baseType)) {
           // Get the extended column node that failed validation.
-          final Predicate<SqlNode> nameMatches = new PredicateImpl<SqlNode>() {
-            @Override public boolean test(SqlNode sqlNode) {
-              if (sqlNode instanceof SqlIdentifier) {
-                final SqlIdentifier identifier = (SqlIdentifier) sqlNode;
-                return Util.last(identifier.names).equals(extendedField.getName());
-              }
-              return false;
-            }
-          };
           final SqlNode extColNode =
-              Iterables.find(extendList.getList(), nameMatches);
+              Iterables.find(extendList.getList(),
+                  sqlNode -> sqlNode instanceof SqlIdentifier
+                      && Util.last(((SqlIdentifier) sqlNode).names).equals(
+                          extendedField.getName()));
 
           throw validator.getValidationErrorFunction().apply(extColNode,
               RESOURCE.typeNotAssignable(

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/TableScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/TableScope.java b/core/src/main/java/org/apache/calcite/sql/validate/TableScope.java
index 89171c2..b43b1ee 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/TableScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/TableScope.java
@@ -19,7 +19,7 @@ package org.apache.calcite.sql.validate;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlSelect;
 
-import com.google.common.base.Preconditions;
+import java.util.Objects;
 
 /**
  * The name-resolution scope of a LATERAL TABLE clause.
@@ -40,8 +40,8 @@ class TableScope extends ListScope {
    * @param parent  Parent scope
    */
   TableScope(SqlValidatorScope parent, SqlNode node) {
-    super(Preconditions.checkNotNull(parent));
-    this.node = Preconditions.checkNotNull(node);
+    super(Objects.requireNonNull(parent));
+    this.node = Objects.requireNonNull(node);
   }
 
   //~ Methods ----------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/sql/validate/UnnestNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/UnnestNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/UnnestNamespace.java
index 2f6c918..c946da8 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/UnnestNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/UnnestNamespace.java
@@ -22,7 +22,6 @@ import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlUnnestOperator;
 
-
 /**
  * Namespace for UNNEST.
  */