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 2017/01/25 21:25:15 UTC

[1/9] calcite git commit: [CALCITE-1599] Remove unused createIterable call in LocalService (Gian Merlino)

Repository: calcite
Updated Branches:
  refs/heads/master 83e517d51 -> 5181563f9


[CALCITE-1599] Remove unused createIterable call in LocalService (Gian Merlino)

The result was ignored. Also remove now-unused "list2" method.

Rename some variables to "ignore" to silence warnings. (Julian Hyde)

Close apache/calcite#352


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/0f45481d
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/0f45481d
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/0f45481d

Branch: refs/heads/master
Commit: 0f45481daf31ebdec8e8e6b9f42262b5fe3a9257
Parents: 83e517d
Author: Gian Merlino <gi...@gmail.com>
Authored: Sun Jan 15 09:06:20 2017 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Jan 21 23:18:56 2017 -0800

----------------------------------------------------------------------
 .../calcite/avatica/remote/LocalService.java    | 24 ++++----------------
 1 file changed, 5 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/0f45481d/avatica/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java
index 1562446..929830b 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java
@@ -19,7 +19,6 @@ package org.apache.calcite.avatica.remote;
 import org.apache.calcite.avatica.AvaticaUtils;
 import org.apache.calcite.avatica.Meta;
 import org.apache.calcite.avatica.Meta.ExecuteBatchResult;
-import org.apache.calcite.avatica.MetaImpl;
 import org.apache.calcite.avatica.MissingResultsException;
 import org.apache.calcite.avatica.NoSuchStatementException;
 import org.apache.calcite.avatica.metrics.MetricsSystem;
@@ -28,7 +27,6 @@ import org.apache.calcite.avatica.metrics.Timer.Context;
 import org.apache.calcite.avatica.metrics.noop.NoopMetricsSystem;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
@@ -125,8 +123,6 @@ public class LocalService implements Service {
         }
       }
     } else {
-      //noinspection unchecked
-      list = (List<Object>) (List) list2(resultSet);
       cursorFactory = Meta.CursorFactory.LIST;
     }
 
@@ -138,16 +134,6 @@ public class LocalService implements Service {
         resultSet.ownStatement, signature, frame, updateCount, serverLevelRpcMetadata);
   }
 
-  private List<List<Object>> list2(Meta.MetaResultSet resultSet) {
-    final Meta.StatementHandle h = new Meta.StatementHandle(
-        resultSet.connectionId, resultSet.statementId, null);
-    final List<TypedValue> parameterValues = Collections.emptyList();
-    final Iterable<Object> iterable = meta.createIterable(h, null,
-        resultSet.signature, parameterValues, resultSet.firstFrame);
-    final List<List<Object>> list = new ArrayList<>();
-    return MetaImpl.collect(resultSet.signature.cursorFactory, iterable, list);
-  }
-
   public ResultSetResponse apply(CatalogsRequest request) {
     final Meta.ConnectionHandle ch =
         new Meta.ConnectionHandle(request.connectionId);
@@ -202,7 +188,7 @@ public class LocalService implements Service {
   }
 
   public PrepareResponse apply(PrepareRequest request) {
-    try (final Context ctx = prepareTimer.start()) {
+    try (final Context ignore = prepareTimer.start()) {
       final Meta.ConnectionHandle ch =
           new Meta.ConnectionHandle(request.connectionId);
       final Meta.StatementHandle h =
@@ -212,7 +198,7 @@ public class LocalService implements Service {
   }
 
   public ExecuteResponse apply(PrepareAndExecuteRequest request) {
-    try (final Context ctx = prepareAndExecuteTimer.start()) {
+    try (final Context ignore = prepareAndExecuteTimer.start()) {
       final Meta.StatementHandle sh =
           new Meta.StatementHandle(request.connectionId, request.statementId, null);
       try {
@@ -263,7 +249,7 @@ public class LocalService implements Service {
   }
 
   public ExecuteResponse apply(ExecuteRequest request) {
-    try (final Context ctx = executeTimer.start()) {
+    try (final Context ignore = executeTimer.start()) {
       try {
         final Meta.ExecuteResult executeResult = meta.execute(request.statementHandle,
             request.parameterValues, AvaticaUtils.toSaturatedInt(request.maxRowCount));
@@ -308,7 +294,7 @@ public class LocalService implements Service {
   }
 
   public ConnectionSyncResponse apply(ConnectionSyncRequest request) {
-    try (final Context ctx = connectionSyncTimer.start()) {
+    try (final Context ignore = connectionSyncTimer.start()) {
       final Meta.ConnectionHandle ch =
           new Meta.ConnectionHandle(request.connectionId);
       final Meta.ConnectionProperties connProps =
@@ -340,7 +326,7 @@ public class LocalService implements Service {
   }
 
   public CommitResponse apply(CommitRequest request) {
-    try (final Context ctx = commitTimer.start()) {
+    try (final Context ignore = commitTimer.start()) {
       meta.commit(new Meta.ConnectionHandle(request.connectionId));
 
       // If commit() errors, let the ErrorResponse be sent back via an uncaught Exception.


[3/9] calcite git commit: [CALCITE-1597] Obsolete Util.newInternal, .pre, .post, .permAssert and Throwables.propagate

Posted by jh...@apache.org.
[CALCITE-1597] Obsolete Util.newInternal, .pre, .post, .permAssert and Throwables.propagate

Replace Util.newInternal with new AssertionError in some contexts,
new RuntimeException in others. Replace methods pre, pos, permAssert
in Util with methods in Preconditions.

Remove uses of Throwables.propagate and .propagateIfPossible because
they are deprecated as of Guava 20. Create method
Util.throwIfUnchecked because we can't use Guava's
Throwables.throwIfUnchecked yet.


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/603648bc
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/603648bc
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/603648bc

Branch: refs/heads/master
Commit: 603648bc2466ab699fa6646ffc1ad717b8c11880
Parents: 89f1125
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Jan 23 01:38:12 2017 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:00:12 2017 -0800

----------------------------------------------------------------------
 .../adapter/cassandra/CassandraRules.java       |  13 +--
 core/src/main/codegen/templates/Parser.jj       |   4 +-
 .../calcite/interpreter/AggregateNode.java      |   9 +-
 .../calcite/jdbc/CalciteConnectionImpl.java     |   5 +-
 .../CachingLatticeStatisticProvider.java        |   5 +-
 .../apache/calcite/plan/ConventionTraitDef.java |   4 +-
 .../org/apache/calcite/plan/RelOptUtil.java     |  13 ++-
 .../org/apache/calcite/plan/hep/HepPlanner.java |   5 +-
 .../calcite/plan/volcano/VolcanoPlanner.java    |  27 ++---
 .../calcite/plan/volcano/VolcanoRuleCall.java   |  15 ++-
 .../org/apache/calcite/rel/AbstractRelNode.java |   2 +-
 .../main/java/org/apache/calcite/rel/BiRel.java |   3 +-
 .../calcite/rel/convert/ConverterImpl.java      |   7 +-
 .../metadata/CachingRelMetadataProvider.java    |   4 +-
 .../metadata/ChainedRelMetadataProvider.java    |   6 +-
 .../rel/metadata/JaninoRelMetadataProvider.java |  11 +-
 .../rel/metadata/MetadataFactoryImpl.java       |   7 +-
 .../metadata/ReflectiveRelMetadataProvider.java |   5 +-
 .../calcite/rel/rules/CalcRelSplitter.java      |   8 +-
 .../calcite/rel/rules/JoinCommuteRule.java      |   8 +-
 .../calcite/rel/rules/ProjectToWindowRule.java  |   4 +-
 .../calcite/rel/rules/ReduceDecimalsRule.java   |   3 +-
 .../java/org/apache/calcite/rex/RexBuilder.java |   8 +-
 .../java/org/apache/calcite/rex/RexLiteral.java |  11 +-
 .../apache/calcite/rex/RexProgramBuilder.java   |  20 ++--
 .../apache/calcite/schema/impl/ViewTable.java   |   7 +-
 .../org/apache/calcite/sql/SqlCallBinding.java  |   3 +-
 .../java/org/apache/calcite/sql/SqlLiteral.java |   5 +-
 .../java/org/apache/calcite/sql/SqlNode.java    |  16 +--
 .../apache/calcite/sql/SqlPostfixOperator.java  |   3 +-
 .../apache/calcite/sql/SqlPrefixOperator.java   |   3 +-
 .../java/org/apache/calcite/sql/SqlSyntax.java  |   4 +-
 .../java/org/apache/calcite/sql/SqlWindow.java  |   2 +-
 .../apache/calcite/sql/fun/SqlLikeOperator.java |   5 +-
 .../calcite/sql/fun/SqlMinMaxAggFunction.java   |   5 +-
 .../sql/parser/SqlAbstractParserImpl.java       |  12 +--
 .../calcite/sql/parser/SqlParserUtil.java       |  19 ++--
 .../calcite/sql/pretty/SqlPrettyWriter.java     |  14 +--
 .../apache/calcite/sql/type/BasicSqlType.java   |   5 +-
 .../apache/calcite/sql/type/ReturnTypes.java    |   9 +-
 .../sql/type/SqlTypeAssignmentRules.java        |   9 +-
 .../apache/calcite/sql/type/SqlTypeUtil.java    |  12 +--
 .../sql/util/ReflectiveSqlOperatorTable.java    |  10 +-
 .../calcite/sql/validate/AbstractNamespace.java |  11 +-
 .../calcite/sql/validate/SetopNamespace.java    |   3 +-
 .../sql/validate/SqlIdentifierMoniker.java      |   6 +-
 .../calcite/sql/validate/SqlValidatorImpl.java  |  25 +++--
 .../sql2rel/ReflectiveConvertletTable.java      |  57 ++++-------
 .../apache/calcite/sql2rel/RelFieldTrimmer.java |   2 +-
 .../sql2rel/SqlNodeToRexConverterImpl.java      |   5 +-
 .../calcite/sql2rel/SqlToRelConverter.java      |  22 ++--
 .../org/apache/calcite/tools/RelRunners.java    |   4 +-
 .../java/org/apache/calcite/util/Closer.java    |   6 +-
 .../org/apache/calcite/util/ReflectUtil.java    |  16 +--
 .../apache/calcite/util/SaffronProperties.java  |   2 +-
 .../main/java/org/apache/calcite/util/Util.java | 100 ++++++++-----------
 .../calcite/util/javac/JaninoCompiler.java      |  11 +-
 .../plan/volcano/VolcanoPlannerTest.java        |  24 +----
 .../rel/rel2sql/RelToSqlConverterTest.java      |   9 +-
 .../calcite/sql/parser/SqlParserTest.java       |   3 +-
 .../calcite/sql/test/SqlOperatorBaseTest.java   |   9 +-
 .../org/apache/calcite/test/DiffRepository.java |  20 ++--
 .../apache/calcite/test/JdbcAdapterTest.java    |  13 ++-
 .../calcite/test/JdbcFrontLinqBackTest.java     |   3 +-
 .../java/org/apache/calcite/test/JdbcTest.java  |   5 +-
 .../org/apache/calcite/test/QuidemTest.java     |   7 +-
 .../calcite/test/ReflectiveSchemaTest.java      |   5 +-
 .../apache/calcite/test/RelMetadataTest.java    |   3 +-
 .../apache/calcite/test/RelOptRulesTest.java    |  11 +-
 .../org/apache/calcite/test/RexProgramTest.java |   2 +-
 .../org/apache/calcite/test/SqlTestGen.java     |  35 ++-----
 .../apache/calcite/test/SqlToRelTestBase.java   |   8 +-
 .../org/apache/calcite/test/StreamTest.java     |   3 +-
 .../adapter/druid/DruidConnectionImpl.java      |  19 ++--
 .../calcite/adapter/druid/DruidQuery.java       |   3 +-
 .../org/apache/calcite/test/DruidAdapterIT.java |   9 +-
 .../elasticsearch/ElasticsearchSchema.java      |   5 +-
 .../calcite/adapter/csv/CsvEnumerator.java      |   4 +-
 .../calcite/adapter/csv/CsvStreamReader.java    |   4 +-
 .../java/org/apache/calcite/test/CsvTest.java   |   3 +-
 .../calcite/adapter/mongodb/MongoRules.java     |   3 +-
 .../org/apache/calcite/test/MongoAdapterIT.java |   3 +-
 .../org/apache/calcite/test/CalciteHandler.java |   4 +-
 83 files changed, 333 insertions(+), 504 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java
----------------------------------------------------------------------
diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java
index ec29bd6..3a9e9e9 100644
--- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java
+++ b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraRules.java
@@ -45,7 +45,6 @@ import org.apache.calcite.util.Pair;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
-import java.util.AbstractList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -66,16 +65,8 @@ public class CassandraRules {
   };
 
   static List<String> cassandraFieldNames(final RelDataType rowType) {
-    return SqlValidatorUtil.uniquify(
-        new AbstractList<String>() {
-          @Override public String get(int index) {
-            return rowType.getFieldList().get(index).getName();
-          }
-
-          @Override public int size() {
-            return rowType.getFieldCount();
-          }
-        });
+    return SqlValidatorUtil.uniquify(rowType.getFieldNames(),
+        SqlValidatorUtil.EXPR_SUGGESTER, true);
   }
 
   /** Translator from {@link RexNode} to strings in Cassandra's expression

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 931f38f..979a707 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -100,6 +100,7 @@ import org.apache.calcite.sql.parser.SqlParserUtil;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.validate.SqlConformance;
 import org.apache.calcite.util.Glossary;
+import org.apache.calcite.util.NlsString;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteTrace;
 
@@ -1883,7 +1884,8 @@ SqlNode TableRef2(boolean lateral) :
         (
             <SUBSTITUTE> <LPAREN> sample = StringLiteral() <RPAREN>
             {
-                String sampleName = SqlLiteral.stringValue(sample);
+                String sampleName =
+                    ((NlsString) SqlLiteral.value(sample)).getValue();
                 SqlSampleSpec sampleSpec = SqlSampleSpec.createNamed(sampleName);
                 SqlLiteral sampleLiteral = SqlLiteral.createSample(sampleSpec, pos);
                 tableRef = SqlStdOperatorTable.TABLESAMPLE.createCall(

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
index 1cffac4..a342b25 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
@@ -41,7 +41,6 @@ import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.Pair;
 
 import com.google.common.base.Supplier;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -451,7 +450,7 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
         try {
           instance = aggFunction.declaringClass.newInstance();
         } catch (InstantiationException | IllegalAccessException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     }
@@ -471,7 +470,7 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
       try {
         this.value = factory.aggFunction.initMethod.invoke(factory.instance);
       } catch (IllegalAccessException | InvocationTargetException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
 
@@ -485,7 +484,7 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
       try {
         value = factory.aggFunction.addMethod.invoke(factory.instance, args);
       } catch (IllegalAccessException | InvocationTargetException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
 
@@ -494,7 +493,7 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
       try {
         return factory.aggFunction.resultMethod.invoke(factory.instance, args);
       } catch (IllegalAccessException | InvocationTargetException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java
index 98a1994..5717603 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java
@@ -61,7 +61,6 @@ import org.apache.calcite.util.BuiltInMethod;
 import org.apache.calcite.util.Holder;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
@@ -163,7 +162,7 @@ abstract class CalciteConnectionImpl
                     ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
                     getHoldability());
               } catch (SQLException e) {
-                throw Throwables.propagate(e);
+                throw new RuntimeException(e);
               }
             }
           });
@@ -288,7 +287,7 @@ abstract class CalciteConnectionImpl
     try {
       cancelFlag = getCancelFlag(handle);
     } catch (NoSuchStatementException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
     map.put(DataContext.Variable.CANCEL_FLAG.camelName, cancelFlag);
     final DataContext dataContext = createDataContext(map);

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java b/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java
index bf2702c..5ab6cf6 100644
--- a/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java
+++ b/core/src/main/java/org/apache/calcite/materialize/CachingLatticeStatisticProvider.java
@@ -17,8 +17,8 @@
 package org.apache.calcite.materialize;
 
 import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -50,7 +50,8 @@ class CachingLatticeStatisticProvider implements LatticeStatisticProvider {
     try {
       return cache.get(Pair.of(lattice, column));
     } catch (UncheckedExecutionException | ExecutionException e) {
-      throw Throwables.propagate(e.getCause());
+      Util.throwIfUnchecked(e.getCause());
+      throw new RuntimeException(e.getCause());
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java b/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java
index eddbb89..a46ee73 100644
--- a/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java
+++ b/core/src/main/java/org/apache/calcite/plan/ConventionTraitDef.java
@@ -20,7 +20,6 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.convert.ConverterRule;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.util.Pair;
-import org.apache.calcite.util.Util;
 import org.apache.calcite.util.graph.DefaultDirectedGraph;
 import org.apache.calcite.util.graph.DefaultEdge;
 import org.apache.calcite.util.graph.DirectedGraph;
@@ -159,8 +158,7 @@ public class ConventionTraitDef extends RelTraitDef<Convention> {
                   converted, previous, arc,
                   conversionData.mapArcToConverterRule);
           if (converted == null) {
-            throw Util.newInternal("Converter from " + previous
-                + " to " + arc
+            throw new AssertionError("Converter from " + previous + " to " + arc
                 + " guaranteed that it could convert any relexp");
           }
         }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index 3239419..37bb54a 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -308,8 +308,8 @@ public abstract class RelOptUtil {
       RelNode p) {
     try {
       visitor.go(p);
-    } catch (Throwable e) {
-      throw Util.newInternal(e, "while visiting tree");
+    } catch (Exception e) {
+      throw new RuntimeException("while visiting tree", e);
     }
   }
 
@@ -382,7 +382,7 @@ public abstract class RelOptUtil {
         + "\nexpression type is " + actualRowType.getFullTypeString()
         + "\nset is " + equivalenceClass.toString()
         + "\nexpression is " + newRel.toString();
-    throw Util.newInternal(s);
+    throw new AssertionError(s);
   }
 
   /**
@@ -1128,10 +1128,9 @@ public abstract class RelOptUtil {
                     ImmutableList.of(leftKeyType, rightKeyType));
 
             if (targetKeyType == null) {
-              throw Util.newInternal(
-                  "Cannot find common type for join keys "
-                  + leftKey + " (type " + leftKeyType + ") and "
-                  + rightKey + " (type " + rightKeyType + ")");
+              throw new AssertionError("Cannot find common type for join keys "
+                  + leftKey + " (type " + leftKeyType + ") and " + rightKey
+                  + " (type " + rightKeyType + ")");
             }
 
             if (leftKeyType != targetKeyType) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
index e029872..1473f8f 100644
--- a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
@@ -924,9 +924,8 @@ public class HepPlanner extends AbstractRelOptPlanner {
       return;
     }
 
-    throw Util.newInternal(
-        "Query graph cycle detected in HepPlanner:  "
-            + cyclicVertices);
+    throw new AssertionError("Query graph cycle detected in HepPlanner: "
+        + cyclicVertices);
   }
 
   private void dumpGraph() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
index 39b2857..15dbb98 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
@@ -1093,9 +1093,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
       try {
         schema.registerRules(this);
       } catch (Exception e) {
-        throw Util.newInternal(
-            e,
-            "Error while registering schema " + schema);
+        throw new AssertionError("While registering schema " + schema, e);
       }
     }
   }
@@ -1600,7 +1598,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
     if (p != null) {
       p = p.equivalentSet;
       if (p == s) {
-        throw Util.newInternal("cycle in equivalence tree");
+        throw new AssertionError("cycle in equivalence tree");
       }
     }
     return p;
@@ -1626,9 +1624,8 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
 
     assert !isRegistered(rel) : "already been registered: " + rel;
     if (rel.getCluster().getPlanner() != this) {
-      throw Util.newInternal("Relational expression " + rel
-          + " belongs to a different planner than is currently being"
-          + " used.");
+      throw new AssertionError("Relational expression " + rel
+          + " belongs to a different planner than is currently being used.");
     }
 
     // Now is a good time to ensure that the relational expression
@@ -1638,17 +1635,15 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
     assert convention != null;
     if (!convention.getInterface().isInstance(rel)
         && !(rel instanceof Converter)) {
-      throw Util.newInternal(
-          "Relational expression " + rel
-              + " has calling-convention " + convention
-              + " but does not implement the required interface '"
-              + convention.getInterface() + "' of that convention");
+      throw new AssertionError("Relational expression " + rel
+          + " has calling-convention " + convention
+          + " but does not implement the required interface '"
+          + convention.getInterface() + "' of that convention");
     }
     if (traits.size() != traitDefs.size()) {
-      throw Util.newInternal(
-          "Relational expression " + rel
-          + " does not have the correct number of traits "
-          + traits.size() + " != " + traitDefs.size());
+      throw new AssertionError("Relational expression " + rel
+          + " does not have the correct number of traits: " + traits.size()
+          + " != " + traitDefs.size());
     }
 
     // Ensure that its sub-expressions are registered.

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoRuleCall.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoRuleCall.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoRuleCall.java
index 8372821..7a629fe 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoRuleCall.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoRuleCall.java
@@ -22,7 +22,6 @@ import org.apache.calcite.plan.RelOptRuleOperand;
 import org.apache.calcite.plan.RelTraitPropagationVisitor;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -144,10 +143,9 @@ public class VolcanoRuleCall extends RelOptRuleCall {
                 false);
         volcanoPlanner.listener.ruleProductionSucceeded(event);
       }
-    } catch (Throwable e) {
-      throw Util.newInternal(
-          e,
-          "Error occurred while applying rule " + getRule());
+    } catch (Exception e) {
+      throw new RuntimeException("Error occurred while applying rule "
+          + getRule(), e);
     }
   }
 
@@ -232,10 +230,9 @@ public class VolcanoRuleCall extends RelOptRuleCall {
                 false);
         volcanoPlanner.listener.ruleAttempted(event);
       }
-    } catch (Throwable e) {
-      throw Util.newInternal(e,
-          "Error while applying rule "
-          + getRule() + ", args " + Arrays.toString(rels));
+    } catch (Exception e) {
+      throw new RuntimeException("Error while applying rule " + getRule()
+          + ", args " + Arrays.toString(rels), e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
index 5592a76..78ac0da 100644
--- a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
+++ b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
@@ -361,7 +361,7 @@ public abstract class AbstractRelNode implements RelNode {
   public void replaceInput(
       int ordinalInParent,
       RelNode p) {
-    throw Util.newInternal("replaceInput called on " + this);
+    throw new UnsupportedOperationException("replaceInput called on " + this);
   }
 
   public String toString() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/BiRel.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/BiRel.java b/core/src/main/java/org/apache/calcite/rel/BiRel.java
index c72f5ea..6e3a4f2 100644
--- a/core/src/main/java/org/apache/calcite/rel/BiRel.java
+++ b/core/src/main/java/org/apache/calcite/rel/BiRel.java
@@ -19,7 +19,6 @@ package org.apache.calcite.rel;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.runtime.FlatLists;
-import org.apache.calcite.util.Util;
 
 import java.util.List;
 
@@ -70,7 +69,7 @@ public abstract class BiRel extends AbstractRelNode {
       this.right = p;
       break;
     default:
-      throw Util.newInternal();
+      throw new IndexOutOfBoundsException("Input " + ordinalInParent);
     }
     recomputeDigest();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java b/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
index b0cb40b..acadd74 100644
--- a/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/convert/ConverterImpl.java
@@ -24,7 +24,6 @@ import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.SingleRel;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
-import org.apache.calcite.util.Util;
 
 /**
  * Abstract implementation of {@link Converter}.
@@ -66,10 +65,10 @@ public abstract class ConverterImpl extends SingleRel
     return planner.getCostFactory().makeCost(dRows, dCpu, dIo);
   }
 
+  @Deprecated // to be removed before 2.0
   protected Error cannotImplement() {
-    return Util.newInternal(
-        getClass() + " cannot convert from "
-            + inTraits + " traits");
+    return new AssertionError(getClass() + " cannot convert from "
+        + inTraits + " traits");
   }
 
   public RelTraitSet getInputTraits() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/metadata/CachingRelMetadataProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/CachingRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/CachingRelMetadataProvider.java
index eb63604..478190c 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/CachingRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/CachingRelMetadataProvider.java
@@ -20,7 +20,6 @@ import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.rel.RelNode;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
 
@@ -141,8 +140,7 @@ public class CachingRelMetadataProvider implements RelMetadataProvider {
         }
         return result;
       } catch (InvocationTargetException e) {
-        Throwables.propagateIfPossible(e.getCause());
-        throw e;
+        throw e.getCause();
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/metadata/ChainedRelMetadataProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/ChainedRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/ChainedRelMetadataProvider.java
index 1ecec0f..8643f91 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/ChainedRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/ChainedRelMetadataProvider.java
@@ -17,8 +17,8 @@
 package org.apache.calcite.rel.metadata;
 
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Lists;
@@ -140,8 +140,8 @@ public class ChainedRelMetadataProvider implements RelMetadataProvider {
           if (e.getCause() instanceof CyclicMetadataException) {
             continue;
           }
-          Throwables.propagateIfPossible(e.getCause());
-          throw e;
+          Util.throwIfUnchecked(e.getCause());
+          throw new RuntimeException(e.getCause());
         }
       }
       return null;

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
index 9e32159..42de769 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
@@ -54,8 +54,8 @@ import org.apache.calcite.rel.stream.LogicalDelta;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.util.ControlFlowException;
 import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -367,8 +367,8 @@ public class JaninoRelMetadataProvider implements RelMetadataProvider {
     try {
       return compile(decl, buff.toString(), def, argList);
     } catch (CompileException | IOException e) {
-      System.out.println(buff);
-      throw Throwables.propagate(e);
+      throw new RuntimeException("Error compiling:\n"
+          + buff, e);
     }
   }
 
@@ -444,7 +444,7 @@ public class JaninoRelMetadataProvider implements RelMetadataProvider {
     } catch (InstantiationException
         | IllegalAccessException
         | InvocationTargetException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
     return def.handlerClass.cast(o);
   }
@@ -457,7 +457,8 @@ public class JaninoRelMetadataProvider implements RelMetadataProvider {
       //noinspection unchecked
       return (H) HANDLERS.get(key);
     } catch (UncheckedExecutionException | ExecutionException e) {
-      throw Throwables.propagate(e.getCause());
+      Util.throwIfUnchecked(e.getCause());
+      throw new RuntimeException(e.getCause());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/metadata/MetadataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/MetadataFactoryImpl.java b/core/src/main/java/org/apache/calcite/rel/metadata/MetadataFactoryImpl.java
index 09446be..063cf6e 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/MetadataFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/MetadataFactoryImpl.java
@@ -18,8 +18,8 @@ package org.apache.calcite.rel.metadata;
 
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -50,7 +50,7 @@ public class MetadataFactoryImpl implements MetadataFactory {
     this.cache = CacheBuilder.newBuilder().build(loader(provider));
   }
 
-  static CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
+  private static CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
       UnboundMetadata<Metadata>> loader(final RelMetadataProvider provider) {
     return new CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
         UnboundMetadata<Metadata>>() {
@@ -73,7 +73,8 @@ public class MetadataFactoryImpl implements MetadataFactory {
       final Metadata apply = cache.get(key).bind(rel, mq);
       return metadataClazz.cast(apply);
     } catch (UncheckedExecutionException | ExecutionException e) {
-      throw Throwables.propagate(e.getCause());
+      Util.throwIfUnchecked(e.getCause());
+      throw new RuntimeException(e.getCause());
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
index baceb35..bdaf4d3 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java
@@ -26,7 +26,6 @@ import org.apache.calcite.util.ReflectiveVisitor;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Multimap;
@@ -197,8 +196,8 @@ public class ReflectiveRelMetadataProvider
                         return handlerMethod.invoke(target, args1);
                       } catch (InvocationTargetException
                           | UndeclaredThrowableException e) {
-                        Throwables.propagateIfPossible(e.getCause());
-                        throw e;
+                        Util.throwIfUnchecked(e.getCause());
+                        throw new RuntimeException(e.getCause());
                       } finally {
                         mq.map.remove(key);
                       }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
index a29dd97..5a19e56 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java
@@ -43,6 +43,7 @@ import org.apache.calcite.util.graph.DefaultEdge;
 import org.apache.calcite.util.graph.DirectedGraph;
 import org.apache.calcite.util.graph.TopologicalOrderIterator;
 
+import com.google.common.base.Preconditions;
 import com.google.common.primitives.Ints;
 
 import org.slf4j.Logger;
@@ -240,8 +241,7 @@ public abstract class CalcRelSplitter {
       inputExprOrdinals = projectExprOrdinals;
     }
 
-    Util.permAssert(
-        doneCondition || (conditionRef == null),
+    Preconditions.checkArgument(doneCondition || (conditionRef == null),
         "unhandled condition");
     return rel;
   }
@@ -371,7 +371,7 @@ public abstract class CalcRelSplitter {
           // level, with all options open?
           if (count(relTypesPossibleForTopLevel) >= relTypes.length) {
             // Cannot implement for any type.
-            throw Util.newInternal("cannot implement " + expr);
+            throw new AssertionError("cannot implement " + expr);
           }
           levelTypeOrdinals[levelCount] =
               firstSet(relTypesPossibleForTopLevel);
@@ -712,7 +712,7 @@ public abstract class CalcRelSplitter {
         return relType.canImplement(rel.getProgram());
       }
     }
-    throw Util.newInternal("unknown type " + relTypeName);
+    throw new AssertionError("unknown type " + relTypeName);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
index 863bf25..28d48af 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinCommuteRule.java
@@ -34,7 +34,6 @@ import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.tools.RelBuilder;
 import org.apache.calcite.tools.RelBuilderFactory;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 
@@ -100,6 +99,10 @@ public class JoinCommuteRule extends RelOptRule {
   }
 
   /**
+   * Returns a relational expression with the inputs switched round. Does not
+   * modify <code>join</code>. Returns null if the join cannot be swapped (for
+   * example, because it is an outer join).
+   *
    * @param join           join to be swapped
    * @param swapOuterJoins whether outer joins should be swapped
    * @return swapped join if swapping possible; else null
@@ -220,8 +223,7 @@ public class JoinCommuteRule extends RelOptRule {
               rightFields.get(index).getType(),
               index);
         }
-        throw Util.newInternal("Bad field offset: index="
-            + var.getIndex()
+        throw new AssertionError("Bad field offset: index=" + var.getIndex()
             + ", leftFieldCount=" + leftFields.size()
             + ", rightFieldCount=" + rightFields.size());
       } else {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
index a2856f5..054f4c6 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java
@@ -41,13 +41,13 @@ import org.apache.calcite.runtime.PredicateImpl;
 import org.apache.calcite.tools.RelBuilder;
 import org.apache.calcite.util.ImmutableIntList;
 import org.apache.calcite.util.Pair;
-import org.apache.calcite.util.Util;
 import org.apache.calcite.util.graph.DefaultDirectedGraph;
 import org.apache.calcite.util.graph.DefaultEdge;
 import org.apache.calcite.util.graph.DirectedGraph;
 import org.apache.calcite.util.graph.TopologicalOrderIterator;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -226,7 +226,7 @@ public abstract class ProjectToWindowRule extends RelOptRule {
 
         protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet,
             RelBuilder relBuilder, RelNode input, RexProgram program) {
-          Util.permAssert(program.getCondition() == null,
+          Preconditions.checkArgument(program.getCondition() == null,
               "WindowedAggregateRel cannot accept a condition");
           return LogicalWindow.create(cluster, traitSet, relBuilder, input,
               program);

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
index ef0af42..5154a15 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceDecimalsRule.java
@@ -868,8 +868,7 @@ public class ReduceDecimalsRule extends RelOptRule {
       } else if (call.getOperator() == SqlStdOperatorTable.MOD) {
         return expandMod(call, operands);
       } else {
-        throw Util.newInternal(
-            "ReduceDecimalsRule could not expand "
+        throw new AssertionError("ReduceDecimalsRule could not expand "
             + call.getOperator());
       }
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index 87c84e3..d8edee9 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -48,6 +48,7 @@ import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
@@ -168,8 +169,7 @@ public class RexBuilder {
     final RelDataTypeField field =
         type.getField(fieldName, caseSensitive, false);
     if (field == null) {
-      throw Util.newInternal(
-          "Type '" + type + "' has no field '"
+      throw new AssertionError("Type '" + type + "' has no field '"
           + fieldName + "'");
     }
     return makeFieldAccessInternal(expr, field);
@@ -189,7 +189,7 @@ public class RexBuilder {
     final RelDataType type = expr.getType();
     final List<RelDataTypeField> fields = type.getFieldList();
     if ((i < 0) || (i >= fields.size())) {
-      throw Util.newInternal("Field ordinal " + i + " is invalid for "
+      throw new AssertionError("Field ordinal " + i + " is invalid for "
           + " type '" + type + "'");
     }
     return makeFieldAccessInternal(expr, fields.get(i));
@@ -374,7 +374,7 @@ public class RexBuilder {
           makeCast(type, constantNull()));
     }
     if (!allowPartial) {
-      Util.permAssert(physical, "DISALLOW PARTIAL over RANGE");
+      Preconditions.checkArgument(physical, "DISALLOW PARTIAL over RANGE");
       final RelDataType bigintType = getTypeFactory().createSqlType(
           SqlTypeName.BIGINT);
       // todo: read bound

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
index c7c9b56..1d1e14d 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
@@ -532,16 +532,15 @@ public class RexLiteral extends RexNode {
         }
       }
       if (cal == null) {
-        throw Util.newInternal(
-            "fromJdbcString: invalid date/time value '"
-                + literal + "'");
+        throw new AssertionError("fromJdbcString: invalid date/time value '"
+            + literal + "'");
       }
       return new RexLiteral(cal, type, typeName);
     case SYMBOL:
 
       // Symbols are for internal use
     default:
-      throw Util.newInternal("fromJdbcString: unsupported type");
+      throw new AssertionError("fromJdbcString: unsupported type");
     }
   }
 
@@ -554,7 +553,7 @@ public class RexLiteral extends RexNode {
     case TIMESTAMP:
       return DateTimeUtils.TIMESTAMP_FORMAT_STRING;
     default:
-      throw Util.newInternal("getCalendarFormat: unknown type");
+      throw new AssertionError("getCalendarFormat: unknown type");
     }
   }
 
@@ -676,7 +675,7 @@ public class RexLiteral extends RexNode {
         return value.negate();
       }
     }
-    throw Util.newInternal("not a literal: " + node);
+    throw new AssertionError("not a literal: " + node);
   }
 
   public static boolean isNullLiteral(RexNode node) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
index 3a20448..2fadc90 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexProgramBuilder.java
@@ -22,7 +22,6 @@ import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.util.Litmus;
 import org.apache.calcite.util.Pair;
-import org.apache.calcite.util.Util;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -163,21 +162,18 @@ public class RexProgramBuilder {
             if (index < fields.size()) {
               final RelDataTypeField inputField = fields.get(index);
               if (input.getType() != inputField.getType()) {
-                throw Util.newInternal("in expression " + expr
-                    + ", field reference " + input
-                    + " has inconsistent type");
+                throw new AssertionError("in expression " + expr
+                    + ", field reference " + input + " has inconsistent type");
               }
             } else {
               if (index >= fieldOrdinal) {
-                throw Util.newInternal("in expression " + expr
-                    + ", field reference " + input
-                    + " is out of bounds");
+                throw new AssertionError("in expression " + expr
+                    + ", field reference " + input + " is out of bounds");
               }
               RexNode refExpr = exprList.get(index);
               if (refExpr.getType() != input.getType()) {
-                throw Util.newInternal("in expression " + expr
-                    + ", field reference " + input
-                    + " has inconsistent type");
+                throw new AssertionError("in expression " + expr
+                    + ", field reference " + input + " has inconsistent type");
               }
             }
             return null;
@@ -951,8 +947,8 @@ public class RexProgramBuilder {
         if (expr instanceof RexLocalRef) {
           local = (RexLocalRef) expr;
           if (local.index >= index) {
-            throw Util.newInternal("expr " + local
-                + " references later expr " + local.index);
+            throw new AssertionError(
+                "expr " + local + " references later expr " + local.index);
           }
         } else {
           // Add expression to the list, just so that subsequent

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java b/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java
index 0a5d006..507db2f 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java
@@ -42,7 +42,6 @@ import org.apache.calcite.schema.Table;
 import org.apache.calcite.schema.TableMacro;
 import org.apache.calcite.schema.TranslatableTable;
 import org.apache.calcite.util.ImmutableIntList;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 
@@ -134,9 +133,9 @@ public class ViewTable
 
       root = root.withRel(RelOptUtil.createCastRel(root.rel, rowType, true));
       return root;
-    } catch (Throwable e) {
-      throw Util.newInternal(
-          e, "Error while parsing view definition:  " + queryString);
+    } catch (Exception e) {
+      throw new RuntimeException("Error while parsing view definition: "
+          + queryString, e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
index ae8abae..77e4b52 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
@@ -29,7 +29,6 @@ import org.apache.calcite.sql.validate.SqlValidatorNamespace;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.util.NlsString;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Lists;
@@ -211,7 +210,7 @@ public class SqlCallBinding extends SqlOperatorBinding {
             RESOURCE.numberLiteralOutOfRange(bd.toString()));
       }
     }
-    throw Util.newInternal("should never come here");
+    throw new AssertionError();
   }
 
   @Override public Comparable getOperandLiteralValue(int ordinal) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
index 3f29975..228abfc 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
@@ -371,9 +371,10 @@ public class SqlLiteral extends SqlNode {
       return literal.toValue();
     } else if (node instanceof SqlCall
         && ((SqlCall) node).getOperator() == SqlStdOperatorTable.CAST) {
+      //noinspection deprecation
       return stringValue(((SqlCall) node).operand(0));
     } else {
-      throw Util.newInternal("invalid string literal: " + node);
+      throw new AssertionError("invalid string literal: " + node);
     }
   }
 
@@ -387,7 +388,7 @@ public class SqlLiteral extends SqlNode {
     } else if (SqlUtil.isLiteralChain(node)) {
       return SqlLiteralChainOperator.concatenateOperands((SqlCall) node);
     } else {
-      throw Util.newInternal("invalid literal: " + node);
+      throw new AssertionError("invalid literal: " + node);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlNode.java b/core/src/main/java/org/apache/calcite/sql/SqlNode.java
index b31cf7b..e7c77fb 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlNode.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlNode.java
@@ -27,6 +27,8 @@ import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.util.Litmus;
 import org.apache.calcite.util.Util;
 
+import com.google.common.base.Preconditions;
+
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -55,8 +57,7 @@ public abstract class SqlNode implements Cloneable {
    * @param pos Parser position, must not be null.
    */
   SqlNode(SqlParserPos pos) {
-    Util.pre(pos != null, "pos != null");
-    this.pos = pos;
+    this.pos = Preconditions.checkNotNull(pos);
   }
 
   //~ Methods ----------------------------------------------------------------
@@ -68,16 +69,7 @@ public abstract class SqlNode implements Cloneable {
   /**
    * Clones a SqlNode with a different position.
    */
-  public SqlNode clone(SqlParserPos pos) {
-    // REVIEW jvs 26-July-2006:  shouldn't pos be used here?  Or are
-    // subclasses always supposed to override, in which case this
-    // method should probably be abstract?
-    try {
-      return (SqlNode) super.clone();
-    } catch (CloneNotSupportedException e) {
-      throw Util.newInternal(e, "error while cloning " + this);
-    }
-  }
+  public abstract SqlNode clone(SqlParserPos pos);
 
   /**
    * Returns the type of node this is, or

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlPostfixOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlPostfixOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlPostfixOperator.java
index 31020d1..4c69252 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlPostfixOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlPostfixOperator.java
@@ -69,8 +69,7 @@ public class SqlPostfixOperator extends SqlOperator {
       RelDataType operandType =
           validator.getValidatedNodeType(call.operand(0));
       if (null == operandType) {
-        throw Util.newInternal(
-            "operand's type should have been derived");
+        throw new AssertionError("operand's type should have been derived");
       }
       if (SqlTypeUtil.inCharFamily(operandType)) {
         SqlCollation collation = operandType.getCollation();

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlPrefixOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlPrefixOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlPrefixOperator.java
index af44dd2..a28e727 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlPrefixOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlPrefixOperator.java
@@ -70,8 +70,7 @@ public class SqlPrefixOperator extends SqlOperator {
       RelDataType operandType =
           validator.getValidatedNodeType(call.operand(0));
       if (null == operandType) {
-        throw Util.newInternal(
-            "operand's type should have been derived");
+        throw new AssertionError("operand's type should have been derived");
       }
       if (SqlTypeUtil.inCharFamily(operandType)) {
         SqlCollation collation = operandType.getCollation();

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlSyntax.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSyntax.java b/core/src/main/java/org/apache/calcite/sql/SqlSyntax.java
index f3e9bbc..50d30ac 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSyntax.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSyntax.java
@@ -141,8 +141,8 @@ public enum SqlSyntax {
         SqlCall call,
         int leftPrec,
         int rightPrec) {
-      throw Util.newInternal("Internal operator '" + operator
-          + "' cannot be un-parsed");
+      throw new UnsupportedOperationException("Internal operator '"
+          + operator + "' " + "cannot be un-parsed");
     }
   };
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
index 86adcc6..d280ac2 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
@@ -698,7 +698,7 @@ public class SqlWindow extends SqlCall {
       }
       break;
     default:
-      throw Util.newInternal("Unexpected node type");
+      throw new AssertionError("Unexpected node type");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/fun/SqlLikeOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLikeOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLikeOperator.java
index 9a0187c..c53740f 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLikeOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLikeOperator.java
@@ -31,7 +31,6 @@ import org.apache.calcite.sql.type.OperandTypes;
 import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlOperandCountRanges;
 import org.apache.calcite.sql.type.SqlTypeUtil;
-import org.apache.calcite.util.Util;
 
 /**
  * An operator describing the <code>LIKE</code> and <code>SIMILAR</code>
@@ -119,8 +118,8 @@ public class SqlLikeOperator extends SqlSpecialOperator {
       // enforce the escape character length to be 1
       break;
     default:
-      throw Util.newInternal(
-          "unexpected number of args to " + callBinding.getCall());
+      throw new AssertionError("unexpected number of args to "
+          + callBinding.getCall() + ": " + callBinding.getOperandCount());
     }
 
     return SqlTypeUtil.isCharTypeComparable(

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
index 391c09a..54af0f8 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
@@ -24,7 +24,6 @@ import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlSplittableAggFunction;
 import org.apache.calcite.sql.type.OperandTypes;
 import org.apache.calcite.sql.type.ReturnTypes;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -113,7 +112,7 @@ public class SqlMinMaxAggFunction extends SqlAggFunction {
     case MINMAX_COMPARATOR:
       return argTypes.subList(1, 2);
     default:
-      throw Util.newInternal("bad kind: " + minMaxKind);
+      throw new AssertionError("bad kind: " + minMaxKind);
     }
   }
 
@@ -125,7 +124,7 @@ public class SqlMinMaxAggFunction extends SqlAggFunction {
     case MINMAX_COMPARATOR:
       return argTypes.get(1);
     default:
-      throw Util.newInternal("bad kind: " + minMaxKind);
+      throw new AssertionError("bad kind: " + minMaxKind);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
index 6c7b167..f4631f6 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
@@ -28,7 +28,6 @@ import org.apache.calcite.sql.SqlUnresolvedFunction;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.validate.SqlConformance;
 import org.apache.calcite.util.Glossary;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -591,8 +590,7 @@ public abstract class SqlAbstractParserImpl {
       parserImpl.ReInit(new StringReader("1"));
       try {
         Object o = virtualCall(parserImpl, name);
-        Util.discard(o);
-        throw Util.newInternal("expected call to fail");
+        throw new AssertionError("expected call to fail, got " + o);
       } catch (SqlParseException parseException) {
         // First time through, build the list of all tokens.
         final String[] tokenImages = parseException.getTokenImages();
@@ -619,9 +617,7 @@ public abstract class SqlAbstractParserImpl {
           }
         }
       } catch (Throwable e) {
-        throw Util.newInternal(
-            e,
-            "Unexpected error while building token lists");
+        throw new RuntimeException("While building token lists", e);
       }
     }
 
@@ -640,10 +636,6 @@ public abstract class SqlAbstractParserImpl {
       try {
         final Method method = clazz.getMethod(name, (Class[]) null);
         return method.invoke(parserImpl, (Object[]) null);
-      } catch (NoSuchMethodException e) {
-        throw Util.newInternal(e);
-      } catch (IllegalAccessException e) {
-        throw Util.newInternal(e);
       } catch (InvocationTargetException e) {
         Throwable cause = e.getCause();
         throw parserImpl.normalizeException(cause);

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
index c9e1ad7..228b5f7 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
@@ -38,6 +38,7 @@ import org.apache.calcite.util.SaffronProperties;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteTrace;
 
+import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 
 import org.slf4j.Logger;
@@ -155,8 +156,7 @@ public final class SqlParserUtil {
   public static long intervalToMillis(
       String literal,
       SqlIntervalQualifier intervalQualifier) {
-    Util.permAssert(
-        !intervalQualifier.isYearMonth(),
+    Preconditions.checkArgument(!intervalQualifier.isYearMonth(),
         "interval must be day time");
     int[] ret;
     try {
@@ -164,8 +164,8 @@ public final class SqlParserUtil {
           intervalQualifier.getParserPosition(), RelDataTypeSystem.DEFAULT);
       assert ret != null;
     } catch (CalciteContextException e) {
-      throw Util.newInternal(
-          e, "while parsing day-to-second interval " + literal);
+      throw new RuntimeException("while parsing day-to-second interval "
+          + literal, e);
     }
     long l = 0;
     long[] conv = new long[5];
@@ -197,8 +197,7 @@ public final class SqlParserUtil {
   public static long intervalToMonths(
       String literal,
       SqlIntervalQualifier intervalQualifier) {
-    Util.permAssert(
-        intervalQualifier.isYearMonth(),
+    Preconditions.checkArgument(intervalQualifier.isYearMonth(),
         "interval must be year month");
     int[] ret;
     try {
@@ -206,8 +205,8 @@ public final class SqlParserUtil {
           intervalQualifier.getParserPosition(), RelDataTypeSystem.DEFAULT);
       assert ret != null;
     } catch (CalciteContextException e) {
-      throw Util.newInternal(
-          e, "error parsing year-to-month interval " + literal);
+      throw new RuntimeException("Error while parsing year-to-month interval "
+          + literal, e);
     }
 
     long l = 0;
@@ -542,8 +541,8 @@ public final class SqlParserUtil {
       int start,
       int end,
       T o) {
-    Util.pre(list != null, "list != null");
-    Util.pre(start < end, "start < end");
+    Preconditions.checkNotNull(list);
+    Preconditions.checkArgument(start < end);
     for (int i = end - 1; i > start; --i) {
       list.remove(i);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
index e212a5d..c2b206a 100644
--- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
@@ -25,7 +25,7 @@ import org.apache.calcite.sql.util.SqlString;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteLogger;
 
-import com.google.common.base.Throwables;
+import com.google.common.base.Preconditions;
 
 import org.slf4j.LoggerFactory;
 
@@ -763,10 +763,8 @@ public class SqlPrettyWriter implements SqlWriter {
 
   public void endList(Frame frame) {
     FrameImpl endedFrame = (FrameImpl) frame;
-    Util.pre(
-        frame == this.frame,
-        "Frame " + endedFrame.frameType
-            + " does not match current frame " + this.frame.frameType);
+    Preconditions.checkArgument(frame == this.frame,
+        "Frame does not match current frame");
     if (this.frame == null) {
       throw new RuntimeException("No list started");
     }
@@ -1159,7 +1157,8 @@ public class SqlPrettyWriter implements SqlWriter {
       try {
         method.invoke(o, value);
       } catch (IllegalAccessException | InvocationTargetException e) {
-        throw Throwables.propagate(e);
+        Util.throwIfUnchecked(e.getCause());
+        throw new RuntimeException(e.getCause());
       }
     }
 
@@ -1168,7 +1167,8 @@ public class SqlPrettyWriter implements SqlWriter {
       try {
         return method.invoke(o);
       } catch (IllegalAccessException | InvocationTargetException e) {
-        throw Throwables.propagate(e);
+        Util.throwIfUnchecked(e.getCause());
+        throw new RuntimeException(e.getCause());
       }
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
index eb699ef..04d1a88 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java
@@ -19,7 +19,6 @@ package org.apache.calcite.sql.type;
 import org.apache.calcite.rel.type.RelDataTypeSystem;
 import org.apache.calcite.sql.SqlCollation;
 import org.apache.calcite.util.SerializableCharset;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Preconditions;
 
@@ -104,7 +103,7 @@ public class BasicSqlType extends AbstractSqlType {
     try {
       ret = (BasicSqlType) this.clone();
     } catch (CloneNotSupportedException e) {
-      throw Util.newInternal(e);
+      throw new AssertionError(e);
     }
     ret.isNullable = nullable;
     ret.computeDigest();
@@ -124,7 +123,7 @@ public class BasicSqlType extends AbstractSqlType {
     try {
       ret = (BasicSqlType) this.clone();
     } catch (CloneNotSupportedException e) {
-      throw Util.newInternal(e);
+      throw new AssertionError(e);
     }
     ret.wrappedCharset = SerializableCharset.forCharset(charset);
     ret.collation = collation;

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 f0c5564..e1c028f 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
@@ -28,7 +28,6 @@ import org.apache.calcite.sql.SqlCollation;
 import org.apache.calcite.sql.SqlOperatorBinding;
 import org.apache.calcite.sql.SqlUtil;
 import org.apache.calcite.util.Glossary;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Preconditions;
 
@@ -627,14 +626,12 @@ public abstract class ReturnTypes {
               .createSqlType(typeName, typePrecision);
           if (null != pickedCollation) {
             RelDataType pickedType;
-            if (argType0.getCollation().equals(
-                pickedCollation)) {
+            if (argType0.getCollation().equals(pickedCollation)) {
               pickedType = argType0;
-            } else if (argType1.getCollation().equals(
-                pickedCollation)) {
+            } else if (argType1.getCollation().equals(pickedCollation)) {
               pickedType = argType1;
             } else {
-              throw Util.newInternal("should never come here");
+              throw new AssertionError("should never come here");
             }
             ret =
                 opBinding.getTypeFactory()

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 efe2bb7..27db0a9 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,8 +16,6 @@
  */
 package org.apache.calcite.sql.type;
 
-import org.apache.calcite.util.Util;
-
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -318,12 +316,11 @@ public class SqlTypeAssignmentRules {
       return true;
     }
 
-    Set<SqlTypeName> rule = ruleset.get(to);
-    if (null == rule) {
+    final Set<SqlTypeName> rule = ruleset.get(to);
+    if (rule == null) {
       // if you hit this assert, see the constructor of this class on how
       // to add new rule
-      throw Util.newInternal(
-          "No assign rules for " + to + " defined");
+      throw new AssertionError("No assign rules for " + to + " defined");
     }
 
     return rule.contains(from);

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 ee7b41a..e2162e1 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
@@ -80,15 +80,15 @@ public abstract class SqlTypeUtil {
       }
 
       if (t0.getCharset() == null) {
-        throw Util.newInternal("RelDataType object should have been assigned a "
-            + "(default) charset when calling deriveType");
+        throw new AssertionError("RelDataType object should have been assigned "
+            + "a (default) charset when calling deriveType");
       } else if (!t0.getCharset().equals(t1.getCharset())) {
         return false;
       }
 
       if (t0.getCollation() == null) {
-        throw Util.newInternal("RelDataType object should have been assigned a "
-            + "(default) collation when calling deriveType");
+        throw new AssertionError("RelDataType object should have been assigned "
+            + "a (default) collation when calling deriveType");
       } else if (!t0.getCollation().getCharset().equals(
           t1.getCollation().getCharset())) {
         return false;
@@ -577,7 +577,7 @@ public abstract class SqlTypeUtil {
     case DECIMAL:
       return NumberUtil.getMinUnscaled(type.getPrecision()).longValue();
     default:
-      throw Util.newInternal("getMinValue(" + typeName + ")");
+      throw new AssertionError("getMinValue(" + typeName + ")");
     }
   }
 
@@ -599,7 +599,7 @@ public abstract class SqlTypeUtil {
     case DECIMAL:
       return NumberUtil.getMaxUnscaled(type.getPrecision()).longValue();
     default:
-      throw Util.newInternal("getMaxValue(" + typeName + ")");
+      throw new AssertionError("getMaxValue(" + typeName + ")");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
index 494e600..a9d2ae1 100644
--- a/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
@@ -25,7 +25,6 @@ import org.apache.calcite.sql.SqlSyntax;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
@@ -72,7 +71,8 @@ public abstract class ReflectiveSqlOperatorTable implements SqlOperatorTable {
           register(op);
         }
       } catch (IllegalArgumentException | IllegalAccessException e) {
-        throw Throwables.propagate(e);
+        Util.throwIfUnchecked(e.getCause());
+        throw new RuntimeException(e.getCause());
       }
     }
   }
@@ -135,12 +135,6 @@ public abstract class ReflectiveSqlOperatorTable implements SqlOperatorTable {
    */
   public void register(SqlOperator op) {
     operators.put(new Key(op.getName(), op.getSyntax()), op);
-    if (op instanceof SqlFunction) {
-      SqlFunction function = (SqlFunction) op;
-      SqlFunctionCategory funcType = function.getFunctionType();
-      assert funcType != null
-          : "Function type for " + function.getName() + " not set";
-    }
   }
 
   public List<SqlOperator> getOperatorList() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
index b6bd058..d0caa7c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
@@ -22,6 +22,7 @@ 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 java.util.List;
@@ -78,12 +79,10 @@ abstract class AbstractNamespace implements SqlValidatorNamespace {
     case UNVALIDATED:
       try {
         status = SqlValidatorImpl.Status.IN_PROGRESS;
-        Util.permAssert(
-            rowType == null,
+        Preconditions.checkArgument(rowType == null,
             "Namespace.rowType must be null before validate has been called");
         RelDataType type = validateImpl(targetRowType);
-        Util.permAssert(
-            type != null,
+        Preconditions.checkArgument(type != null,
             "validateImpl() returned null");
         setType(type);
       } finally {
@@ -91,7 +90,7 @@ abstract class AbstractNamespace implements SqlValidatorNamespace {
       }
       break;
     case IN_PROGRESS:
-      throw Util.newInternal("todo: Cycle detected during type-checking");
+      throw new AssertionError("Cycle detected during type-checking");
     case VALID:
       break;
     default:
@@ -114,7 +113,7 @@ abstract class AbstractNamespace implements SqlValidatorNamespace {
   public RelDataType getRowType() {
     if (rowType == null) {
       validator.validateNamespace(this, validator.unknownType);
-      Util.permAssert(rowType != null, "validate must set rowType");
+      Preconditions.checkArgument(rowType != null, "validate must set rowType");
     }
     return rowType;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql/validate/SetopNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SetopNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/SetopNamespace.java
index adc6e6d..d6f65e1 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SetopNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SetopNamespace.java
@@ -20,7 +20,6 @@ import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.sql.SqlCall;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.util.Util;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -107,7 +106,7 @@ public class SetopNamespace extends AbstractNamespace {
           scope,
           call);
     default:
-      throw Util.newInternal("Not a query: " + call.getKind());
+      throw new AssertionError("Not a query: " + call.getKind());
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 e4f498b..29a75e0 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
@@ -17,7 +17,8 @@
 package org.apache.calcite.sql.validate;
 
 import org.apache.calcite.sql.SqlIdentifier;
-import org.apache.calcite.util.Util;
+
+import com.google.common.base.Preconditions;
 
 import java.util.List;
 
@@ -36,8 +37,7 @@ public class SqlIdentifierMoniker implements SqlMoniker {
    * Creates an SqlIdentifierMoniker.
    */
   public SqlIdentifierMoniker(SqlIdentifier id) {
-    Util.pre(id != null, "id != null");
-    this.id = id;
+    this.id = Preconditions.checkNotNull(id);
   }
 
   //~ Methods ----------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 3766258..f0d0ce9 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
@@ -597,7 +597,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     }
     final SqlValidatorNamespace ns = getNamespace(outermostNode);
     if (ns == null) {
-      throw Util.newInternal("Not a query: " + outermostNode);
+      throw new AssertionError("Not a query: " + outermostNode);
     }
     Collection<SqlMoniker> hintList = Sets.newTreeSet(SqlMoniker.COMPARATOR);
     lookupSelectHints(ns, pos, hintList);
@@ -1492,8 +1492,8 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   }
 
   void setValidatedNodeTypeImpl(SqlNode node, RelDataType type) {
-    Util.pre(type != null, "type != null");
-    Util.pre(node != null, "node != null");
+    Preconditions.checkNotNull(type);
+    Preconditions.checkNotNull(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
@@ -1505,8 +1505,8 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   public RelDataType deriveType(
       SqlValidatorScope scope,
       SqlNode expr) {
-    Util.pre(scope != null, "scope != null");
-    Util.pre(expr != null, "expr != null");
+    Preconditions.checkNotNull(scope);
+    Preconditions.checkNotNull(expr);
 
     // if we already know the type, no need to re-derive
     RelDataType type = nodeToTypeMap.get(expr);
@@ -1518,7 +1518,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       return ns.getType();
     }
     type = deriveTypeImpl(scope, expr);
-    Util.permAssert(
+    Preconditions.checkArgument(
         type != null,
         "SqlValidator.deriveTypeInternal returned null");
     setValidatedNodeTypeImpl(expr, type);
@@ -2842,7 +2842,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       SqlNode node,
       RelDataType targetRowType,
       SqlValidatorScope scope) {
-    Util.pre(targetRowType != null, "targetRowType != null");
+    Preconditions.checkNotNull(targetRowType);
     switch (node.getKind()) {
     case AS:
       validateFrom(
@@ -2870,7 +2870,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   }
 
   protected void validateOver(SqlCall call, SqlValidatorScope scope) {
-    throw Util.newInternal("OVER unexpected in this context");
+    throw new AssertionError("OVER unexpected in this context");
   }
 
   protected void validateJoin(SqlJoin join, SqlValidatorScope scope) {
@@ -2887,10 +2887,10 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     // Validate condition.
     switch (conditionType) {
     case NONE:
-      Util.permAssert(condition == null, "condition == null");
+      Preconditions.checkArgument(condition == null);
       break;
     case ON:
-      Util.permAssert(condition != null, "condition != null");
+      Preconditions.checkArgument(condition != null);
       SqlNode expandedCondition = expand(condition, joinScope);
       join.setOperand(5, expandedCondition);
       condition = join.getCondition();
@@ -2900,7 +2900,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       SqlNodeList list = (SqlNodeList) condition;
 
       // Parser ensures that using clause is not empty.
-      Util.permAssert(list.size() > 0, "Empty USING clause");
+      Preconditions.checkArgument(list.size() > 0, "Empty USING clause");
       for (int i = 0; i < list.size(); i++) {
         SqlIdentifier id = (SqlIdentifier) list.get(i);
         final RelDataType leftColType = validateUsingCol(id, left);
@@ -3375,8 +3375,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       }
     }
     final SqlValidatorScope orderScope = getOrderScope(select);
-
-    Util.permAssert(orderScope != null, "orderScope != null");
+    Preconditions.checkNotNull(orderScope != null);
 
     List<SqlNode> expandList = new ArrayList<>();
     for (SqlNode orderItem : orderList) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java b/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java
index fcd3f4c..4d87df1 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java
@@ -21,7 +21,8 @@ import org.apache.calcite.sql.SqlCall;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.util.Util;
+
+import com.google.common.base.Preconditions;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -38,7 +39,7 @@ import java.util.Map;
 public class ReflectiveConvertletTable implements SqlRexConvertletTable {
   //~ Instance fields --------------------------------------------------------
 
-  private final Map<Object, Object> map = new HashMap<Object, Object>();
+  private final Map<Object, Object> map = new HashMap<>();
 
   //~ Constructors -----------------------------------------------------------
 
@@ -77,25 +78,16 @@ public class ReflectiveConvertletTable implements SqlRexConvertletTable {
     if (!SqlNode.class.isAssignableFrom(parameterType)) {
       return;
     }
-    map.put(
-        parameterType,
+    map.put(parameterType,
         new SqlRexConvertlet() {
           public RexNode convertCall(
               SqlRexContext cx,
               SqlCall call) {
             try {
-              return (RexNode) method.invoke(
-                  ReflectiveConvertletTable.this,
-                  cx,
-                  call);
-            } catch (IllegalAccessException e) {
-              throw Util.newInternal(
-                  e,
-                  "while converting " + call);
-            } catch (InvocationTargetException e) {
-              throw Util.newInternal(
-                  e,
-                  "while converting " + call);
+              return (RexNode) method.invoke(ReflectiveConvertletTable.this,
+                  cx, call);
+            } catch (IllegalAccessException | InvocationTargetException e) {
+              throw new RuntimeException("while converting " + call, e);
             }
           }
         });
@@ -132,26 +124,14 @@ public class ReflectiveConvertletTable implements SqlRexConvertletTable {
     if (!SqlCall.class.isAssignableFrom(parameterType)) {
       return;
     }
-    map.put(
-        opClass,
+    map.put(opClass,
         new SqlRexConvertlet() {
-          public RexNode convertCall(
-              SqlRexContext cx,
-              SqlCall call) {
+          public RexNode convertCall(SqlRexContext cx, SqlCall call) {
             try {
-              return (RexNode) method.invoke(
-                  ReflectiveConvertletTable.this,
-                  cx,
-                  call.getOperator(),
-                  call);
-            } catch (IllegalAccessException e) {
-              throw Util.newInternal(
-                  e,
-                  "while converting " + call);
-            } catch (InvocationTargetException e) {
-              throw Util.newInternal(
-                  e,
-                  "while converting " + call);
+              return (RexNode) method.invoke(ReflectiveConvertletTable.this,
+                  cx, call.getOperator(), call);
+            } catch (IllegalAccessException | InvocationTargetException e) {
+              throw new RuntimeException("while converting " + call, e);
             }
           }
         });
@@ -170,7 +150,7 @@ public class ReflectiveConvertletTable implements SqlRexConvertletTable {
 
     // Is there a convertlet for this class of operator
     // (e.g. SqlBinaryOperator)?
-    Class<? extends Object> clazz = op.getClass();
+    Class<?> clazz = op.getClass();
     while (clazz != null) {
       convertlet = (SqlRexConvertlet) map.get(clazz);
       if (convertlet != null) {
@@ -216,13 +196,10 @@ public class ReflectiveConvertletTable implements SqlRexConvertletTable {
           public RexNode convertCall(
               SqlRexContext cx,
               SqlCall call) {
-            Util.permAssert(
-                call.getOperator() == alias,
+            Preconditions.checkArgument(call.getOperator() == alias,
                 "call to wrong operator");
             final SqlCall newCall =
-                target.createCall(
-                    SqlParserPos.ZERO,
-                    call.getOperandList());
+                target.createCall(SqlParserPos.ZERO, call.getOperandList());
             return cx.convertExpression(newCall);
           }
         });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index 723fb78..853e69b 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -909,7 +909,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
     if (!inputMapping.isIdentity()) {
       // We asked for all fields. Can't believe that the child decided
       // to permute them!
-      throw Util.newInternal(
+      throw new AssertionError(
           "Expected identity mapping, got " + inputMapping);
     }
 


[7/9] calcite git commit: [CALCITE-1569] Code generation for fields of type java.sql.Date (Zhen Wang)

Posted by jh...@apache.org.
[CALCITE-1569] Code generation for fields of type java.sql.Date (Zhen Wang)

Date condition currently generates Integer == Integer, which is
always false.

Review comments from Julian Hyde: The fix isn't ideal. I'd rather
that we convert java.sql.Date values when they enter the system. And,
if we allow java.sql.Date values then we should treat java.util.Date,
java.sql.Time and java.sql.Timestamp values similarly. But, being
pragmatic, I'm going to accept the patch because it fixes cases that
didn't work previously. If we see further problems in this area, we
might back out the changes and do it properly.

Close apache/calcite#356


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/d335e48c
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/d335e48c
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/d335e48c

Branch: refs/heads/master
Commit: d335e48ce62bf124a961343d7b843c045ffb6b15
Parents: 499b55e
Author: zhen wang <zi...@gmail.com>
Authored: Fri Jan 20 19:56:16 2017 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:00:13 2017 -0800

----------------------------------------------------------------------
 .../adapter/enumerable/EnumerableTableScan.java |  3 +-
 .../adapter/enumerable/JavaRowFormat.java       | 59 +++++++++++---------
 .../adapter/enumerable/PhysTypeImpl.java        |  9 ++-
 .../adapter/enumerable/RexToLixTranslator.java  | 20 ++++++-
 .../apache/calcite/runtime/SqlFunctions.java    |  1 +
 .../calcite/test/ReflectiveSchemaTest.java      | 20 +++++++
 6 files changed, 83 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
index 9fd5d34..3b4d8a1 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
@@ -191,7 +191,8 @@ public class EnumerableTableScan
 
   private Expression fieldExpression(ParameterExpression row_, int i,
       PhysType physType, JavaRowFormat format) {
-    final Expression e = format.field(row_, i, physType.getJavaFieldType(i));
+    final Expression e =
+        format.field(row_, i, null, physType.getJavaFieldType(i));
     final RelDataType relFieldType =
         physType.getRowType().getFieldList().get(i).getType();
     switch (relFieldType.getSqlTypeName()) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
index 46a4373..86f0002 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
@@ -20,7 +20,9 @@ import org.apache.calcite.adapter.java.JavaTypeFactory;
 import org.apache.calcite.interpreter.Row;
 import org.apache.calcite.linq4j.tree.Expression;
 import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.IndexExpression;
 import org.apache.calcite.linq4j.tree.MemberExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
 import org.apache.calcite.linq4j.tree.Types;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.runtime.FlatLists;
@@ -58,16 +60,14 @@ public enum JavaRowFormat {
       }
     }
 
-    @Override public MemberExpression field(Expression expression, int field,
-        Type fieldType) {
+    public MemberExpression field(Expression expression, int field,
+        Type fromType, Type fieldType) {
       final Type type = expression.getType();
       if (type instanceof Types.RecordType) {
         Types.RecordType recordType = (Types.RecordType) type;
         Types.RecordField recordField =
             recordType.getRecordFields().get(field);
-        return Expressions.field(
-            expression,
-            recordField.getDeclaringClass(),
+        return Expressions.field(expression, recordField.getDeclaringClass(),
             recordField.getName());
       } else {
         return Expressions.field(expression, Types.nthField(field, type));
@@ -89,13 +89,12 @@ public enum JavaRowFormat {
       return javaRowClass(typeFactory, type);
     }
 
-    public Expression record(
-        Type javaRowClass, List<Expression> expressions) {
+    public Expression record(Type javaRowClass, List<Expression> expressions) {
       assert expressions.size() == 1;
       return expressions.get(0);
     }
 
-    @Override public Expression field(Expression expression, int field,
+    public Expression field(Expression expression, int field, Type fromType,
         Type fieldType) {
       assert field == 0;
       return expression;
@@ -178,13 +177,14 @@ public enum JavaRowFormat {
       }
     }
 
-    @Override public Expression field(Expression expression, int field,
+    public Expression field(Expression expression, int field, Type fromType,
         Type fieldType) {
-      return RexToLixTranslator.convert(
-          Expressions.call(expression,
-              BuiltInMethod.LIST_GET.method,
-              Expressions.constant(field)),
-          fieldType);
+      final MethodCallExpression e = Expressions.call(expression,
+          BuiltInMethod.LIST_GET.method, Expressions.constant(field));
+      if (fromType == null) {
+        fromType = e.getType();
+      }
+      return RexToLixTranslator.convert(e, fromType, fieldType);
     }
   },
 
@@ -206,13 +206,14 @@ public enum JavaRowFormat {
       return Expressions.call(BuiltInMethod.ROW_AS_COPY.method, expressions);
     }
 
-    @Override public Expression field(Expression expression, int field,
+    public Expression field(Expression expression, int field, Type fromType,
         Type fieldType) {
-      return RexToLixTranslator.convert(
-          Expressions.call(expression,
-              BuiltInMethod.ROW_VALUE.method,
-              Expressions.constant(field)),
-          fieldType);
+      final Expression e = Expressions.call(expression,
+          BuiltInMethod.ROW_VALUE.method, Expressions.constant(field));
+      if (fromType == null) {
+        fromType = e.getType();
+      }
+      return RexToLixTranslator.convert(e, fromType, fieldType);
     }
   },
 
@@ -236,11 +237,14 @@ public enum JavaRowFormat {
       return Expressions.call(BuiltInMethod.ARRAY_COMPARER.method);
     }
 
-    @Override public Expression field(Expression expression, int field,
+    public Expression field(Expression expression, int field, Type fromType,
         Type fieldType) {
-      return RexToLixTranslator.convert(
-          Expressions.arrayIndex(expression, Expressions.constant(field)),
-          fieldType);
+      final IndexExpression e = Expressions.arrayIndex(expression,
+          Expressions.constant(field));
+      if (fromType == null) {
+        fromType = e.getType();
+      }
+      return RexToLixTranslator.convert(e, fromType, fieldType);
     }
   };
 
@@ -280,8 +284,13 @@ public enum JavaRowFormat {
     return null;
   }
 
+  /** Returns a reference to a particular field.
+   *
+   * <p>{@code fromType} may be null; if null, uses the natural type of the
+   * field.
+   */
   public abstract Expression field(Expression expression, int field,
-      Type fieldType);
+      Type fromType, Type fieldType);
 }
 
 // End JavaRowFormat.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
index 49b44ba..a1977f5 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
@@ -642,10 +642,17 @@ public class PhysTypeImpl implements PhysType {
 
   public Expression fieldReference(
       Expression expression, int field, Type storageType) {
+    Type fieldType;
     if (storageType == null) {
       storageType = fieldClass(field);
+      fieldType = null;
+    } else {
+      fieldType = fieldClass(field);
+      if (fieldType != java.sql.Date.class) {
+        fieldType = null;
+      }
     }
-    return format.field(expression, field, storageType);
+    return format.field(expression, field, fieldType, storageType);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
index 333e183..b8dc1a9 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
@@ -769,9 +769,13 @@ public class RexToLixTranslator {
         program.getCondition(),
         RexImpTable.NullAs.FALSE);
   }
-
   public static Expression convert(Expression operand, Type toType) {
     final Type fromType = operand.getType();
+    return convert(operand, fromType, toType);
+  }
+
+  public static Expression convert(Expression operand, Type fromType,
+      Type toType) {
     if (fromType.equals(toType)) {
       return operand;
     }
@@ -860,10 +864,22 @@ public class RexToLixTranslator {
         }
       }
       return Expressions.box(operand, toBox);
+    } else if (fromType == java.sql.Date.class) {
+      if (toBox == Primitive.INT) {
+        return Expressions.call(BuiltInMethod.DATE_TO_INT.method, operand);
+      } else {
+        return Expressions.convert_(operand, toType);
+      }
     } else if (toType == java.sql.Date.class) {
       // E.g. from "int" or "Integer" to "java.sql.Date",
       // generate "SqlFunctions.internalToDate".
-      return Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, operand);
+      Boolean isPrimitiveInt = fromPrimitive == Primitive.INT;
+      Boolean isBoxInt = fromBox == Primitive.INT;
+      if (isPrimitiveInt || isBoxInt) {
+        return Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, operand);
+      } else {
+        return Expressions.convert_(operand, java.sql.Date.class);
+      }
     } else if (toType == java.sql.Time.class) {
       // E.g. from "int" or "Integer" to "java.sql.Time",
       // generate "SqlFunctions.internalToTime".

http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index c0f1d55..45c53f3 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -1537,6 +1537,7 @@ public class SqlFunctions {
     return o instanceof Integer ? (Integer) o
         : o instanceof Number ? toInt((Number) o)
         : o instanceof String ? toInt((String) o)
+        : o instanceof java.util.Date ? toInt((java.util.Date) o)
         : (Integer) cannotConvert(o, int.class);
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d335e48c/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
index 41d3e89..ab6b0b8 100644
--- a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
@@ -704,6 +704,26 @@ public class ReflectiveSchemaTest {
         .returnsUnordered("value=2", "value=6", "value=10");
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1569">[CALCITE-1569]
+   * Date condition can generates Integer == Integer, which is always
+   * false</a>. */
+  @Test public void testDateCanCompare() {
+    final String sql = "select a.v\n"
+        + "from (select \"sqlDate\" v\n"
+        + "  from \"s\".\"everyTypes\" "
+        + "  group by \"sqlDate\") a,"
+        + "    (select \"sqlDate\" v\n"
+        + "  from \"s\".\"everyTypes\"\n"
+        + "  group by \"sqlDate\") b\n"
+        + "where a.v >= b.v\n"
+        + "group by a.v";
+    CalciteAssert.that()
+        .withSchema("s", CATCHALL)
+        .query(sql)
+        .returnsUnordered("V=1970-01-01");
+  }
+
   /** Extension to {@link Employee} with a {@code hireDate} column. */
   public static class EmployeeWithHireDate extends Employee {
     public final java.sql.Date hireDate;


[2/9] calcite git commit: [CALCITE-1597] Obsolete Util.newInternal, .pre, .post, .permAssert and Throwables.propagate

Posted by jh...@apache.org.
http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java
index a22963f..3f7b5cb 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java
@@ -34,6 +34,8 @@ import org.apache.calcite.util.BitString;
 import org.apache.calcite.util.NlsString;
 import org.apache.calcite.util.Util;
 
+import com.google.common.base.Preconditions;
+
 import java.math.BigDecimal;
 import java.util.Calendar;
 
@@ -117,8 +119,7 @@ public class SqlNodeToRexConverterImpl implements SqlNodeToRexConverter {
       return rexBuilder.makeLiteral(((Boolean) value).booleanValue());
     case BINARY:
       bitString = (BitString) value;
-      Util.permAssert(
-          (bitString.getBitCount() % 8) == 0,
+      Preconditions.checkArgument((bitString.getBitCount() % 8) == 0,
           "incomplete octet");
 
       // An even number of hexits (e.g. X'ABCD') makes whole number

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 3f3fe34..9ae5436 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -1185,7 +1185,8 @@ public class SqlToRelConverter {
       return;
 
     default:
-      throw Util.newInternal("unexpected kind of sub-query :" + subQuery.node);
+      throw new AssertionError("unexpected kind of sub-query: "
+          + subQuery.node);
     }
   }
 
@@ -1861,7 +1862,8 @@ public class SqlToRelConverter {
       orderKeys.add(new RexFieldCollation(e, flags));
     }
     try {
-      Util.permAssert(bb.window == null, "already in window agg mode");
+      Preconditions.checkArgument(bb.window == null,
+          "already in window agg mode");
       bb.window = window;
       RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
       rexAgg =
@@ -1945,8 +1947,7 @@ public class SqlToRelConverter {
                 tableSampleSpec.getRepeatableSeed());
         bb.setRoot(new Sample(cluster, bb.root, params), false);
       } else {
-        throw Util.newInternal(
-            "unknown TABLESAMPLE type: " + sampleSpec);
+        throw new AssertionError("unknown TABLESAMPLE type: " + sampleSpec);
       }
       return;
 
@@ -2080,7 +2081,7 @@ public class SqlToRelConverter {
       return;
 
     default:
-      throw Util.newInternal("not a join operator " + from);
+      throw new AssertionError("not a join operator " + from);
     }
   }
 
@@ -2508,7 +2509,7 @@ public class SqlToRelConverter {
     final List<Pair<RexNode, String>> projects = Lists.newArrayList();
 
     try {
-      Util.permAssert(bb.agg == null, "already in agg mode");
+      Preconditions.checkArgument(bb.agg == null, "already in agg mode");
       bb.agg = aggConverter;
 
       // convert the select and having expressions, so that the
@@ -2887,7 +2888,7 @@ public class SqlToRelConverter {
     case VALUES:
       return RelRoot.of(convertValues((SqlCall) query, targetRowType), kind);
     default:
-      throw Util.newInternal("not a query: " + query);
+      throw new AssertionError("not a query: " + query);
     }
   }
 
@@ -3646,7 +3647,7 @@ public class SqlToRelConverter {
     }
 
     if (unionRels.size() == 0) {
-      throw Util.newInternal("empty values clause");
+      throw new AssertionError("empty values clause");
     } else if (unionRels.size() == 1) {
       bb.setRoot(
           unionRels.get(0),
@@ -3912,7 +3913,7 @@ public class SqlToRelConverter {
       if (nameToNodeMap != null && qualified.prefixLength == 1) {
         RexNode node = nameToNodeMap.get(qualified.identifier.names.get(0));
         if (node == null) {
-          throw Util.newInternal("Unknown identifier '" + qualified.identifier
+          throw new AssertionError("Unknown identifier '" + qualified.identifier
               + "' encountered while expanding expression");
         }
         return Pair.of(node, null);
@@ -4192,8 +4193,7 @@ public class SqlToRelConverter {
 
       // Apply standard conversions.
       rex = expr.accept(this);
-      Util.permAssert(rex != null, "conversion result not null");
-      return rex;
+      return Preconditions.checkNotNull(rex);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/tools/RelRunners.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RelRunners.java b/core/src/main/java/org/apache/calcite/tools/RelRunners.java
index 9db8e7c..48652a5 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelRunners.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelRunners.java
@@ -18,8 +18,6 @@ package org.apache.calcite.tools;
 
 import org.apache.calcite.rel.RelNode;
 
-import com.google.common.base.Throwables;
-
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -35,7 +33,7 @@ public class RelRunners {
       final RelRunner runner = connection.unwrap(RelRunner.class);
       return runner.prepare(rel);
     } catch (SQLException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/util/Closer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Closer.java b/core/src/main/java/org/apache/calcite/util/Closer.java
index b816d35..68c4622 100644
--- a/core/src/main/java/org/apache/calcite/util/Closer.java
+++ b/core/src/main/java/org/apache/calcite/util/Closer.java
@@ -16,8 +16,6 @@
  */
 package org.apache.calcite.util;
 
-import com.google.common.base.Throwables;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -40,8 +38,10 @@ public final class Closer implements AutoCloseable {
     for (AutoCloseable closeable : list) {
       try {
         closeable.close();
+      } catch (RuntimeException e) {
+        throw e;
       } catch (Exception e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/util/ReflectUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/ReflectUtil.java b/core/src/main/java/org/apache/calcite/util/ReflectUtil.java
index 51b1e6b..04b8a7e 100644
--- a/core/src/main/java/org/apache/calcite/util/ReflectUtil.java
+++ b/core/src/main/java/org/apache/calcite/util/ReflectUtil.java
@@ -258,19 +258,13 @@ public abstract class ReflectUtil {
           visitor,
           visitee);
     } catch (IllegalAccessException ex) {
-      throw Util.newInternal(ex);
+      throw new RuntimeException(ex);
     } catch (InvocationTargetException ex) {
       // visit methods aren't allowed to have throws clauses,
       // so the only exceptions which should come
       // to us are RuntimeExceptions and Errors
-      Throwable t = ex.getTargetException();
-      if (t instanceof RuntimeException) {
-        throw (RuntimeException) t;
-      } else if (t instanceof Error) {
-        throw (Error) t;
-      } else {
-        throw new AssertionError(t.getClass().getName());
-      }
+      Util.throwIfUnchecked(ex.getTargetException());
+      throw new RuntimeException(ex.getTargetException());
     }
     return true;
   }
@@ -531,8 +525,8 @@ public abstract class ReflectUtil {
           final Object o = method.invoke(visitor, args);
           return returnClazz.cast(o);
         } catch (IllegalAccessException | InvocationTargetException e) {
-          throw Util.newInternal(e,
-              "While invoking method '" + method + "'");
+          throw new RuntimeException("While invoking method '" + method + "'",
+              e);
         }
       }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/util/SaffronProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/SaffronProperties.java b/core/src/main/java/org/apache/calcite/util/SaffronProperties.java
index b36a742..8f45d68 100644
--- a/core/src/main/java/org/apache/calcite/util/SaffronProperties.java
+++ b/core/src/main/java/org/apache/calcite/util/SaffronProperties.java
@@ -116,7 +116,7 @@ public interface SaffronProperties {
           try {
             properties.load(new FileInputStream(file));
           } catch (IOException e) {
-            throw Util.newInternal(e, "while reading from " + file);
+            throw new RuntimeException("while reading from " + file, e);
           }
         }
       } catch (AccessControlException e) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/util/Util.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Util.java b/core/src/main/java/org/apache/calcite/util/Util.java
index fee522d..9e011be 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -29,6 +29,8 @@ import org.apache.calcite.sql.fun.SqlRowOperator;
 import org.apache.calcite.sql.util.SqlBasicVisitor;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -88,6 +90,8 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.annotation.Nullable;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Miscellaneous utility functions.
  */
@@ -456,7 +460,7 @@ public class Util {
         try {
           val = field.get(o);
         } catch (IllegalAccessException e) {
-          throw newInternal(e);
+          throw new RuntimeException(e);
         }
         print(pw, val, indent + 1);
       }
@@ -772,29 +776,43 @@ public class Util {
     return DEFAULT_CHARSET;
   }
 
+  /** @deprecated Throw new {@link AssertionError} */
+  @Deprecated // to be removed before 2.0
   public static Error newInternal() {
-    return newInternal("(unknown cause)");
+    return new AssertionError("(unknown cause)");
   }
 
+  /** @deprecated Throw new {@link AssertionError} */
+  @Deprecated // to be removed before 2.0
   public static Error newInternal(String s) {
-    return new AssertionError("Internal error: " + s);
+    return new AssertionError(s);
   }
 
+  /** @deprecated Throw new {@link RuntimeException} if checked; throw raw
+   * exception if unchecked or {@link Error} */
+  @Deprecated // to be removed before 2.0
   public static Error newInternal(Throwable e) {
-    return newInternal(e, "(unknown cause)");
+    return new AssertionError(e);
   }
 
+  /** @deprecated Throw new {@link AssertionError} if applicable;
+   * or {@link RuntimeException} if e is checked;
+   * or raw exception if e is unchecked or {@link Error}. */
   public static Error newInternal(Throwable e, String s) {
-    String message = "Internal error: " + s;
-    if (false) {
-      // TODO re-enable this code when we're no longer throwing spurious
-      //   internal errors (which should be parse errors, for example)
-      System.err.println(message);
-      e.printStackTrace(System.err);
+    return new AssertionError("Internal error: " + s, e);
+  }
+
+  /** As {@link Throwables#throwIfUnchecked(Throwable)}, but we don't require
+   * Guava version 20 yet. */
+  public static void throwIfUnchecked(Throwable throwable) {
+    Bug.upgrade("Remove when minimum Guava version is 20");
+    checkNotNull(throwable);
+    if (throwable instanceof RuntimeException) {
+      throw (RuntimeException) throwable;
+    }
+    if (throwable instanceof Error) {
+      throw (Error) throwable;
     }
-    AssertionError ae = new AssertionError(message);
-    ae.initCause(e);
-    return ae;
   }
 
   /**
@@ -836,60 +854,29 @@ public class Util {
     return sw.toString();
   }
 
-  /**
-   * Checks a pre-condition.
-   *
-   * <p>For example,
-   *
-   * <pre>
-   * /**
-   *   * @ pre x != 0
-   *   * /
-   * void foo(int x) {
-   *     Util.pre(x != 0, "x != 0");
-   * }</pre>
-   *
-   * @param b           Result of evaluating the pre-condition.
-   * @param description Description of the pre-condition.
-   */
+  /** @deprecated Use {@link Preconditions#checkArgument}
+   * or {@link Preconditions#checkNotNull(Object)} */
+  @Deprecated // to be removed before 2.0
   public static void pre(boolean b, String description) {
     if (!b) {
-      throw newInternal("pre-condition failed: " + description);
+      throw new AssertionError("pre-condition failed: " + description);
     }
   }
 
-  /**
-   * Checks a post-condition.
-   *
-   * <p>For example,
-   *
-   * <pre>
-   * /**
-   *   * @ post return != 0
-   *   * /
-   * void foo(int x) {
-   *     int res = bar(x);
-   *     Util.post(res != 0, "return != 0");
-   * }</pre>
-   *
-   * @param b           Result of evaluating the pre-condition.
-   * @param description Description of the pre-condition.
-   */
+  /** @deprecated Use {@link Preconditions#checkArgument}
+   * or {@link Preconditions#checkNotNull(Object)} */
+  @Deprecated // to be removed before 2.0
   public static void post(boolean b, String description) {
     if (!b) {
-      throw newInternal("post-condition failed: " + description);
+      throw new AssertionError("post-condition failed: " + description);
     }
   }
 
-  /**
-   * Checks an invariant.
-   *
-   * <p>This is similar to <code>assert</code> keyword, except that the
-   * condition is always evaluated even if asserts are disabled.
-   */
+  /** @deprecated Use {@link Preconditions#checkArgument} */
+  @Deprecated // to be removed before 2.0
   public static void permAssert(boolean b, String description) {
     if (!b) {
-      throw newInternal("invariant violated: " + description);
+      throw new AssertionError("invariant violated: " + description);
     }
   }
 
@@ -1533,8 +1520,7 @@ public class Util {
     case 3:
       return new Locale(strings[0], strings[1], strings[2]);
     default:
-      throw newInternal(
-          "bad locale string '" + localeString + "'");
+      throw new AssertionError("bad locale string '" + localeString + "'");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
index e508d7d..af170d9 100644
--- a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
+++ b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
@@ -16,8 +16,6 @@
  */
 package org.apache.calcite.util.javac;
 
-import org.apache.calcite.util.Util;
-
 import org.codehaus.janino.JavaSourceClassLoader;
 import org.codehaus.janino.util.ClassFile;
 import org.codehaus.janino.util.resource.MapResourceFinder;
@@ -81,7 +79,7 @@ public class JaninoCompiler implements JavaCompiler {
     try {
       classLoader.loadClass(args.fullClassName);
     } catch (ClassNotFoundException ex) {
-      throw Util.newInternal(ex, "while compiling " + args.fullClassName);
+      throw new RuntimeException("while compiling " + args.fullClassName, ex);
     }
   }
 
@@ -156,12 +154,11 @@ public class JaninoCompiler implements JavaCompiler {
       return nBytes;
     }
 
-    // override JavaSourceClassLoader
-    public Map generateBytecodes(String name)
+    @Override public Map<String, byte[]> generateBytecodes(String name)
         throws ClassNotFoundException {
-      Map<String, byte[]> map = super.generateBytecodes(name);
+      final Map<String, byte[]> map = super.generateBytecodes(name);
       if (map == null) {
-        return map;
+        return null;
       }
 
       if (destDir != null) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/plan/volcano/VolcanoPlannerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/plan/volcano/VolcanoPlannerTest.java b/core/src/test/java/org/apache/calcite/plan/volcano/VolcanoPlannerTest.java
index 041eb2c..b4a2557 100644
--- a/core/src/test/java/org/apache/calcite/plan/volcano/VolcanoPlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/plan/volcano/VolcanoPlannerTest.java
@@ -31,7 +31,6 @@ import org.apache.calcite.rel.convert.ConverterRule;
 import org.apache.calcite.rel.logical.LogicalProject;
 import org.apache.calcite.rel.rules.ProjectRemoveRule;
 import org.apache.calcite.rex.RexInputRef;
-import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 
@@ -520,12 +519,10 @@ public class VolcanoPlannerTest {
               operand(PhysLeafRel.class, any())));
     }
 
-    // implement RelOptRule
-    public Convention getOutConvention() {
+    @Override public Convention getOutConvention() {
       return PHYS_CALLING_CONVENTION;
     }
 
-    // implement RelOptRule
     public void onMatch(RelOptRuleCall call) {
       NoneSingleRel singleRel = call.rel(0);
       RelNode childRel = call.rel(1);
@@ -546,12 +543,10 @@ public class VolcanoPlannerTest {
       super(operand(LogicalProject.class, any()));
     }
 
-    // implement RelOptRule
-    public Convention getOutConvention() {
+    @Override public Convention getOutConvention() {
       return PHYS_CALLING_CONVENTION;
     }
 
-    // implement RelOptRule
     public void onMatch(RelOptRuleCall call) {
       final LogicalProject project = call.rel(0);
       RelNode childRel = project.getInput();
@@ -571,12 +566,10 @@ public class VolcanoPlannerTest {
               operand(PhysLeafRel.class, any())));
     }
 
-    // implement RelOptRule
-    public Convention getOutConvention() {
+    @Override public Convention getOutConvention() {
       return PHYS_CALLING_CONVENTION;
     }
 
-    // implement RelOptRule
     public void onMatch(RelOptRuleCall call) {
       PhysSingleRel singleRel = call.rel(0);
       PhysLeafRel leafRel = call.rel(1);
@@ -596,12 +589,10 @@ public class VolcanoPlannerTest {
               operand(PhysLeafRel.class, any())));
     }
 
-    // implement RelOptRule
     public Convention getOutConvention() {
       return PHYS_CALLING_CONVENTION;
     }
 
-    // implement RelOptRule
     public void onMatch(RelOptRuleCall call) {
       NoneSingleRel singleRel = call.rel(0);
       PhysLeafRel leafRel = call.rel(1);
@@ -628,18 +619,15 @@ public class VolcanoPlannerTest {
       eventList.add(event);
     }
 
-    // implement RelOptListener
     public void relChosen(RelChosenEvent event) {
       recordEvent(event);
     }
 
-    // implement RelOptListener
     public void relDiscarded(RelDiscardedEvent event) {
-      // Volcano is quite a packrat--it never discards anything!
-      throw Util.newInternal(event.toString());
+      // Volcano is quite a pack rat--it never discards anything!
+      throw new AssertionError(event);
     }
 
-    // implement RelOptListener
     public void relEquivalenceFound(RelEquivalenceEvent event) {
       if (!event.isPhysical()) {
         return;
@@ -647,12 +635,10 @@ public class VolcanoPlannerTest {
       recordEvent(event);
     }
 
-    // implement RelOptListener
     public void ruleAttempted(RuleAttemptedEvent event) {
       recordEvent(event);
     }
 
-    // implement RelOptListener
     public void ruleProductionSucceeded(RuleProductionEvent event) {
       recordEvent(event);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index b97ed3f..88c3ffb 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -40,7 +40,6 @@ import org.apache.calcite.tools.RuleSets;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 
 import org.junit.Test;
@@ -567,10 +566,6 @@ public class RelToSqlConverterTest {
       return new Sql(schemaSpec, sql, dialect, transforms);
     }
 
-    Sql planner(Planner planner) {
-      return new Sql(schemaSpec, sql, dialect, transforms);
-    }
-
     Sql optimize(final RuleSet ruleSet, final RelOptPlanner relOptPlanner) {
       return new Sql(schemaSpec, sql, dialect,
           FlatLists.append(transforms, new Function<RelNode, RelNode>() {
@@ -596,8 +591,10 @@ public class RelToSqlConverterTest {
         final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
         assertThat(Util.toLinux(sqlNode.toSqlString(dialect).getSql()),
             is(expectedQuery));
+      } catch (RuntimeException e) {
+        throw e;
       } catch (Exception e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
       return this;
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 38c0e68..54fce65 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -33,7 +33,6 @@ import org.apache.calcite.util.ConversionUtil;
 import org.apache.calcite.util.TestUtil;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedSet;
@@ -7193,7 +7192,7 @@ public class SqlParserTest {
         final SqlNode sqlNode = getSqlParser(sap.sql).parseStmt();
         assertThat(sqlNode, matcher);
       } catch (SqlParseException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
index 4861506..71df5c5 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
@@ -51,7 +51,6 @@ import org.apache.calcite.test.SqlLimitsTest;
 import org.apache.calcite.util.Bug;
 import org.apache.calcite.util.Holder;
 import org.apache.calcite.util.Pair;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.base.Throwables;
@@ -1410,10 +1409,10 @@ public abstract class SqlOperatorBaseTest {
           return cal;
 
         default:
-          throw Util.newInternal("unexpected time unit " + timeUnit);
+          throw new AssertionError("unexpected time unit: " + timeUnit);
         }
       } catch (InterruptedException e) {
-        throw Util.newInternal(e);
+        throw new RuntimeException(e);
       }
     }
   }
@@ -6410,8 +6409,10 @@ public abstract class SqlOperatorBaseTest {
         final ResultSet resultSet =
             statement.executeQuery(query);
         resultChecker.checkResult(resultSet);
+      } catch (RuntimeException e) {
+        throw e;
       } catch (Exception e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/DiffRepository.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/DiffRepository.java b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
index 90ecc83..622c526 100644
--- a/core/src/test/java/org/apache/calcite/test/DiffRepository.java
+++ b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
@@ -217,7 +217,7 @@ public class DiffRepository {
             + "', but found '" + root.getNodeName() + "'");
       }
     } catch (ParserConfigurationException | SAXException e) {
-      throw Util.newInternal(e, "error while creating xml parser");
+      throw new RuntimeException("error while creating xml parser", e);
     }
     indent = logFile.getPath().contains("RelOptRulesTest")
         || logFile.getPath().contains("SqlToRelConverterTest")
@@ -523,23 +523,15 @@ public class DiffRepository {
    * Flushes the reference document to the file system.
    */
   private void flushDoc() {
-    FileWriter w = null;
     try {
       boolean b = logFile.getParentFile().mkdirs();
       Util.discard(b);
-      w = new FileWriter(logFile);
-      write(doc, w, indent);
-    } catch (IOException e) {
-      throw Util.newInternal(e,
-          "error while writing test reference log '" + logFile + "'");
-    } finally {
-      if (w != null) {
-        try {
-          w.close();
-        } catch (IOException e) {
-          // ignore
-        }
+      try (FileWriter w = new FileWriter(logFile)) {
+        write(doc, w, indent);
       }
+    } catch (IOException e) {
+      throw new RuntimeException("error while writing test reference log '"
+          + logFile + "'", e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 3e7c301..61dee87 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
@@ -22,7 +22,6 @@ import org.apache.calcite.test.CalciteAssert.AssertThat;
 import org.apache.calcite.test.CalciteAssert.DatabaseInstance;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 
 import org.hsqldb.jdbcDriver;
 
@@ -579,7 +578,7 @@ public class JdbcAdapterTest {
                   assertFalse(CalciteAssert.toString(resultSet).isEmpty());
                   return null;
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
               }
             });
@@ -677,7 +676,7 @@ public class JdbcAdapterTest {
                   .planUpdateHasSql(jdbcSql, 1);
               return null;
             } catch (SQLException e) {
-              throw Throwables.propagate(e);
+              throw new RuntimeException(e);
             }
           }
         });
@@ -713,7 +712,7 @@ public class JdbcAdapterTest {
                   .planUpdateHasSql(jdbcSql, 2);
               return null;
             } catch (SQLException e) {
-              throw Throwables.propagate(e);
+              throw new RuntimeException(e);
             }
           }
         });
@@ -753,7 +752,7 @@ public class JdbcAdapterTest {
               .planUpdateHasSql(jdbcSql, 1);
           return null;
         } catch (SQLException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     });
@@ -783,7 +782,7 @@ public class JdbcAdapterTest {
               .planUpdateHasSql(jdbcSql, 1);
           return null;
         } catch (SQLException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     });
@@ -810,7 +809,7 @@ public class JdbcAdapterTest {
               .planUpdateHasSql(jdbcSql, 1);
           return null;
         } catch (SQLException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/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 f5ae8c9..73b1bb8 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
@@ -31,7 +31,6 @@ import org.apache.calcite.schema.impl.AbstractSchema;
 import org.apache.calcite.schema.impl.AbstractTableQueryable;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 
 import org.junit.Ignore;
 import org.junit.Test;
@@ -262,7 +261,7 @@ public class JdbcFrontLinqBackTest {
               }
               return null;
             } catch (SQLException e) {
-              throw Throwables.propagate(e);
+              throw new RuntimeException(e);
             }
           }
         });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 25d3dcf..701c8c9 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -98,7 +98,6 @@ import org.apache.calcite.util.TryThreadLocal;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.LinkedListMultimap;
 import com.google.common.collect.Multimap;
@@ -315,7 +314,7 @@ public class JdbcTest {
                 statement.close();
                 return null;
               } catch (SQLException e) {
-                throw Throwables.propagate(e);
+                throw new RuntimeException(e);
               }
             }
           });
@@ -6597,7 +6596,7 @@ public class JdbcTest {
                   }
                   return null;
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
               }
             });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/QuidemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/QuidemTest.java b/core/src/test/java/org/apache/calcite/test/QuidemTest.java
index 88479c6..f15fe13 100644
--- a/core/src/test/java/org/apache/calcite/test/QuidemTest.java
+++ b/core/src/test/java/org/apache/calcite/test/QuidemTest.java
@@ -46,6 +46,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.FilenameFilter;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.sql.Connection;
@@ -111,7 +112,8 @@ public class QuidemTest {
     final File firstFile = new File(x);
     final File dir = firstFile.getParentFile();
     final List<String> paths = new ArrayList<>();
-    for (File f : dir.listFiles(new PatternFilenameFilter(".*\\.iq$"))) {
+    final FilenameFilter filter = new PatternFilenameFilter(".*\\.iq$");
+    for (File f : Util.first(dir.listFiles(filter), new File[0])) {
       assert f.getAbsolutePath().startsWith(base)
           : "f: " + f.getAbsolutePath() + "; base: " + base;
       paths.add(f.getAbsolutePath().substring(base.length()));
@@ -246,7 +248,8 @@ public class QuidemTest {
   }
 
   /** Quidem connection factory for Calcite's built-in test schemas. */
-  private static class QuidemConnectionFactory implements Quidem.NewConnectionFactory {
+  private static class QuidemConnectionFactory
+      implements Quidem.ConnectionFactory {
     public Connection connect(String name) throws Exception {
       return connect(name, false);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
index 606f1d6..41d3e89 100644
--- a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
@@ -37,7 +37,6 @@ import org.apache.calcite.util.Smalls;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 
 import org.junit.Assert;
@@ -347,7 +346,7 @@ public class ReflectiveSchemaTest {
                       ++n;
                     }
                   } catch (SQLException e) {
-                    throw Throwables.propagate(e);
+                    throw new RuntimeException(e);
                   }
                   assertThat(n, equalTo(1));
                   return null;
@@ -580,7 +579,7 @@ public class ReflectiveSchemaTest {
                     buf.append(input.getInt(2)).append("\n");
                   }
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
                 assertThat(buf.toString(), equalTo("0\n2147483647\n"));
                 return null;

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index f11b26a..9bded46 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -75,7 +75,6 @@ import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.ImmutableIntList;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -1074,7 +1073,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
       join = EnumerableMergeJoin.create(project, deptSort,
           rexBuilder.makeLiteral(true), leftKeys, rightKeys, JoinRelType.INNER);
     } catch (InvalidRelException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
     collations =
         RelMdCollation.mergeJoin(mq, project, deptSort, leftKeys,

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index db7d27c..88ca598 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -99,7 +99,6 @@ import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.sql2rel.SqlToRelConverter;
 import org.apache.calcite.tools.RelBuilder;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
@@ -672,7 +671,7 @@ public class RelOptRulesTest extends RelOptTestBase {
         .checkUnchanged();
   }
 
-  @Test public void testSemiJoinTrim() {
+  @Test public void testSemiJoinTrim() throws Exception {
     final DiffRepository diffRepos = getDiffRepos();
     String sql = diffRepos.expand(null, "${sql}");
 
@@ -690,13 +689,7 @@ public class RelOptRulesTest extends RelOptTestBase {
             typeFactory,
             SqlToRelConverter.Config.DEFAULT);
 
-    final SqlNode sqlQuery;
-    try {
-      sqlQuery = t.parseQuery(sql);
-    } catch (Exception e) {
-      throw Util.newInternal(e);
-    }
-
+    final SqlNode sqlQuery = t.parseQuery(sql);
     final SqlNode validatedQuery = validator.validate(sqlQuery);
     RelRoot root =
         converter.convertQuery(validatedQuery, false, true);

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
index 3ca7c44..3be7821 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -419,7 +419,7 @@ public class RexProgramTest {
                   t1));
       break;
     default:
-      throw Util.newInternal("unexpected variant " + variant);
+      throw new AssertionError("unexpected variant " + variant);
     }
     // $t6 = $t4 + $t2 (i.e. (x + y) + (x + 1))
     RexLocalRef t6 =

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
index c5ed8c0..e330efc 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
@@ -24,7 +24,6 @@ import org.apache.calcite.sql.test.SqlTester;
 import org.apache.calcite.sql.test.SqlTesterImpl;
 import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.util.BarfingInvocationHandler;
-import org.apache.calcite.util.Util;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -51,38 +50,20 @@ public class SqlTestGen {
   }
 
   private void genValidatorTest() {
-    FileOutputStream fos = null;
-    PrintWriter pw = null;
-    try {
-      File file = new File("validatorTest.sql");
-      fos = new FileOutputStream(file);
-      pw = new PrintWriter(fos);
+    final File file = new File("validatorTest.sql");
+    try (FileOutputStream fos = new FileOutputStream(file);
+         PrintWriter pw = new PrintWriter(fos)) {
       Method[] methods = getJunitMethods(SqlValidatorSpooler.class);
       for (Method method : methods) {
         final SqlValidatorSpooler test = new SqlValidatorSpooler(pw);
         final Object result = method.invoke(test);
         assert result == null;
       }
-    } catch (IOException e) {
-      throw Util.newInternal(e);
-    } catch (IllegalAccessException e) {
-      throw Util.newInternal(e);
-    } catch (IllegalArgumentException e) {
-      throw Util.newInternal(e);
+    } catch (IOException | IllegalAccessException
+        | IllegalArgumentException e) {
+      throw new RuntimeException(e);
     } catch (InvocationTargetException e) {
-      e.printStackTrace();
-      throw Util.newInternal(e);
-    } finally {
-      if (pw != null) {
-        pw.flush();
-      }
-      if (fos != null) {
-        try {
-          fos.close();
-        } catch (IOException e) {
-          throw Util.newInternal(e);
-        }
-      }
+      throw new RuntimeException(e.getCause());
     }
   }
 
@@ -90,7 +71,7 @@ public class SqlTestGen {
    * Returns a list of all of the Junit methods in a given class.
    */
   private static Method[] getJunitMethods(Class<SqlValidatorSpooler> clazz) {
-    List<Method> list = new ArrayList<Method>();
+    List<Method> list = new ArrayList<>();
     for (Method method : clazz.getMethods()) {
       if (method.getName().startsWith("test")
           && Modifier.isPublic(method.getModifiers())

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
index 7520b4a..a74415c 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
@@ -55,9 +55,9 @@ import org.apache.calcite.sql2rel.SqlToRelConverter;
 import org.apache.calcite.sql2rel.StandardConvertletTable;
 import org.apache.calcite.tools.RelBuilder;
 import org.apache.calcite.util.ImmutableBitSet;
-import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
@@ -522,13 +522,15 @@ public abstract class SqlToRelTestBase {
     }
 
     public RelRoot convertSqlToRel(String sql) {
-      Util.pre(sql != null, "sql != null");
+      Preconditions.checkNotNull(sql);
       final SqlNode sqlQuery;
       final SqlToRelConverter.Config localConfig;
       try {
         sqlQuery = parseQuery(sql);
+      } catch (RuntimeException | Error e) {
+        throw e;
       } catch (Exception e) {
-        throw Util.newInternal(e); // todo: better handling
+        throw new RuntimeException(e);
       }
       final RelDataTypeFactory typeFactory = getTypeFactory();
       final Prepare.CatalogReader catalogReader =

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/core/src/test/java/org/apache/calcite/test/StreamTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/StreamTest.java b/core/src/test/java/org/apache/calcite/test/StreamTest.java
index ebb420f..2740957 100644
--- a/core/src/test/java/org/apache/calcite/test/StreamTest.java
+++ b/core/src/test/java/org/apache/calcite/test/StreamTest.java
@@ -37,7 +37,6 @@ import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.ImmutableBitSet;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
@@ -348,7 +347,7 @@ public class StreamTest {
           }
           return null;
         } catch (SQLException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     };

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
index 872b6e9..07740c2 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
@@ -26,6 +26,7 @@ import org.apache.calcite.linq4j.Enumerator;
 import org.apache.calcite.prepare.CalcitePrepareImpl;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.Holder;
+import org.apache.calcite.util.Util;
 
 import static org.apache.calcite.runtime.HttpUtils.post;
 
@@ -36,7 +37,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.type.CollectionType;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
@@ -120,7 +120,7 @@ class DruidConnectionImpl implements DruidConnection {
         System.out.println("Response: " + new String(bytes));
         in = new ByteArrayInputStream(bytes);
       } catch (IOException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
 
@@ -239,7 +239,7 @@ class DruidConnectionImpl implements DruidConnection {
         }
       }
     } catch (IOException | InterruptedException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 
@@ -483,7 +483,7 @@ class DruidConnectionImpl implements DruidConnection {
         }
       }
     } catch (IOException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 
@@ -505,7 +505,7 @@ class DruidConnectionImpl implements DruidConnection {
       final List<String> list = mapper.readValue(in, listType);
       return ImmutableSet.copyOf(list);
     } catch (IOException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 
@@ -517,7 +517,7 @@ class DruidConnectionImpl implements DruidConnection {
         System.out.println("Response: " + new String(bytes));
         in = new ByteArrayInputStream(bytes);
       } catch (IOException e) {
-        throw Throwables.propagate(e);
+        throw new RuntimeException(e);
       }
     }
     return in;
@@ -559,10 +559,11 @@ class DruidConnectionImpl implements DruidConnection {
     public void reset() {}
 
     public void close() {
-      final Throwable throwable = throwableHolder.get();
-      if (throwable != null) {
+      final Throwable e = throwableHolder.get();
+      if (e != null) {
         throwableHolder.set(null);
-        throw Throwables.propagate(throwable);
+        Util.throwIfUnchecked(e);
+        throw new RuntimeException(e);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
index f5c034e..5a40849 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
@@ -64,7 +64,6 @@ import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
@@ -746,7 +745,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
       generator.writeEndObject();
       generator.close();
     } catch (IOException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
     return sw.toString();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
----------------------------------------------------------------------
diff --git a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
index 97b8188..ea156f4 100644
--- a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
+++ b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
@@ -22,7 +22,6 @@ import org.apache.calcite.config.CalciteConnectionProperty;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Multimap;
@@ -294,7 +293,7 @@ public class DruidAdapterIT {
                   assertThat(map.get("BIGINT").size(), is(1));
                   assertThat(map.get(VARCHAR_TYPE).size(), is(88));
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
                 return null;
               }
@@ -350,7 +349,7 @@ public class DruidAdapterIT {
               assertThat(input.next(), is(false));
               return null;
             } catch (SQLException e) {
-              throw Throwables.propagate(e);
+              throw new RuntimeException(e);
             }
           }
         });
@@ -644,7 +643,7 @@ public class DruidAdapterIT {
                   assertFalse(resultSet.next());
                   return null;
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
               }
             })
@@ -722,7 +721,7 @@ public class DruidAdapterIT {
                   assertFalse(resultSet.next());
                   return null;
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
               }
             })

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
index e59e0a4..d74f3f5 100644
--- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
+++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java
@@ -21,7 +21,6 @@ import org.apache.calcite.schema.impl.AbstractSchema;
 
 import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
@@ -94,8 +93,10 @@ public class ElasticsearchSchema extends AbstractSchema {
       for (ObjectObjectCursor<String, MappingMetaData> c: mapping) {
         builder.put(c.key, new ElasticsearchTable(client, index, c.key));
       }
+    } catch (RuntimeException e) {
+      throw e;
     } catch (Exception e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
     return builder.build();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
----------------------------------------------------------------------
diff --git a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
index 716992c..25a3c38 100644
--- a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
+++ b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvEnumerator.java
@@ -26,8 +26,6 @@ import org.apache.commons.lang3.time.FastDateFormat;
 
 import au.com.bytecode.opencsv.CSVReader;
 
-import com.google.common.base.Throwables;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileReader;
@@ -201,7 +199,7 @@ class CsvEnumerator<E> implements Enumerator<E> {
             try {
               Thread.sleep(CsvStreamReader.DEFAULT_MONITOR_DELAY);
             } catch (InterruptedException e) {
-              throw Throwables.propagate(e);
+              throw new RuntimeException(e);
             }
             continue;
           }

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvStreamReader.java
----------------------------------------------------------------------
diff --git a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvStreamReader.java b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvStreamReader.java
index e97278a..27db047 100644
--- a/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvStreamReader.java
+++ b/example/csv/src/main/java/org/apache/calcite/adapter/csv/CsvStreamReader.java
@@ -23,8 +23,6 @@ import org.apache.commons.io.input.TailerListenerAdapter;
 import au.com.bytecode.opencsv.CSVParser;
 import au.com.bytecode.opencsv.CSVReader;
 
-import com.google.common.base.Throwables;
-
 import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
@@ -88,7 +86,7 @@ class CsvStreamReader extends CSVReader implements Closeable {
       // wait for tailer to capture data
       Thread.sleep(DEFAULT_MONITOR_DELAY);
     } catch (InterruptedException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
----------------------------------------------------------------------
diff --git a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
index 6c381e5..38693ce 100644
--- a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
+++ b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
@@ -24,7 +24,6 @@ import org.apache.calcite.schema.Schema;
 import org.apache.calcite.sql2rel.SqlToRelConverter;
 import org.apache.calcite.util.Util;
 
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 
 import org.junit.Assert;
@@ -198,7 +197,7 @@ public class CsvTest {
           assertThat(resultSet.next(), is(false));
           return null;
         } catch (SQLException e) {
-          throw Throwables.propagate(e);
+          throw new RuntimeException(e);
         }
       }
     });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
index 70c3cde..d60c476 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
@@ -98,7 +98,8 @@ public class MongoRules {
           @Override public int size() {
             return rowType.getFieldCount();
           }
-        });
+        },
+        SqlValidatorUtil.EXPR_SUGGESTER, true);
   }
 
   static String maybeQuote(String s) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
----------------------------------------------------------------------
diff --git a/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java b/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
index 25b39ac..3550711 100644
--- a/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
+++ b/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
@@ -22,7 +22,6 @@ import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Ordering;
@@ -833,7 +832,7 @@ public class MongoAdapterIT {
                   assertThat(input.getInt(1), CoreMatchers.is(29353));
                   return null;
                 } catch (SQLException e) {
-                  throw Throwables.propagate(e);
+                  throw new RuntimeException(e);
                 }
               }
             });

http://git-wip-us.apache.org/repos/asf/calcite/blob/603648bc/piglet/src/test/java/org/apache/calcite/test/CalciteHandler.java
----------------------------------------------------------------------
diff --git a/piglet/src/test/java/org/apache/calcite/test/CalciteHandler.java b/piglet/src/test/java/org/apache/calcite/test/CalciteHandler.java
index 1c83e2f..66cb671 100644
--- a/piglet/src/test/java/org/apache/calcite/test/CalciteHandler.java
+++ b/piglet/src/test/java/org/apache/calcite/test/CalciteHandler.java
@@ -21,8 +21,6 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.tools.PigRelBuilder;
 import org.apache.calcite.tools.RelRunners;
 
-import com.google.common.base.Throwables;
-
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.sql.Array;
@@ -48,7 +46,7 @@ class CalciteHandler extends Handler {
       final ResultSet resultSet = preparedStatement.executeQuery();
       dump(resultSet, true);
     } catch (SQLException e) {
-      throw Throwables.propagate(e);
+      throw new RuntimeException(e);
     }
   }
 


[6/9] calcite git commit: [CALCITE-1582] RelToSqlConverter doesn't handle cartesian join (Jess Balint)

Posted by jh...@apache.org.
[CALCITE-1582] RelToSqlConverter doesn't handle cartesian join (Jess Balint)

Close apache/calcite#360


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/499b55e3
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/499b55e3
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/499b55e3

Branch: refs/heads/master
Commit: 499b55e32b5febe1c88612c3b80ebb71b3b71f88
Parents: 603648b
Author: Jess Balint <jb...@gmail.com>
Authored: Thu Jan 12 14:45:49 2017 -0600
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:00:13 2017 -0800

----------------------------------------------------------------------
 .../calcite/rel/rel2sql/RelToSqlConverter.java  | 22 ++++++++++++++------
 .../rel/rel2sql/RelToSqlConverterTest.java      |  8 +++++++
 .../apache/calcite/test/JdbcAdapterTest.java    | 12 +++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/499b55e3/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
index ba7d4a7..007dbed 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
@@ -25,6 +25,7 @@ import org.apache.calcite.rel.core.Calc;
 import org.apache.calcite.rel.core.Filter;
 import org.apache.calcite.rel.core.Intersect;
 import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Minus;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.core.Sort;
@@ -38,6 +39,7 @@ import org.apache.calcite.rex.RexLocalRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexProgram;
 import org.apache.calcite.sql.JoinConditionType;
+import org.apache.calcite.sql.JoinType;
 import org.apache.calcite.sql.SqlDelete;
 import org.apache.calcite.sql.SqlDialect;
 import org.apache.calcite.sql.SqlIdentifier;
@@ -104,17 +106,25 @@ public class RelToSqlConverter extends SqlImplementor
     final Context leftContext = leftResult.qualifiedContext();
     final Context rightContext =
         rightResult.qualifiedContext();
-    SqlNode sqlCondition = convertConditionToSqlNode(e.getCondition(),
-        leftContext,
-        rightContext,
-        e.getLeft().getRowType().getFieldCount());
+    SqlNode sqlCondition = null;
+    SqlLiteral condType = JoinConditionType.ON.symbol(POS);
+    JoinType joinType = joinType(e.getJoinType());
+    if (e.getJoinType() == JoinRelType.INNER && e.getCondition().isAlwaysTrue()) {
+      joinType = JoinType.COMMA;
+      condType = JoinConditionType.NONE.symbol(POS);
+    } else {
+      sqlCondition = convertConditionToSqlNode(e.getCondition(),
+          leftContext,
+          rightContext,
+          e.getLeft().getRowType().getFieldCount());
+    }
     SqlNode join =
         new SqlJoin(POS,
             leftResult.asFrom(),
             SqlLiteral.createBoolean(false, POS),
-            joinType(e.getJoinType()).symbol(POS),
+            joinType.symbol(POS),
             rightResult.asFrom(),
-            JoinConditionType.ON.symbol(POS),
+            condType,
             sqlCondition);
     return result(join, leftResult, rightResult);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/499b55e3/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 88c3ffb..7050f72 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -316,6 +316,14 @@ public class RelToSqlConverterTest {
     sql(query).ok(expected);
   }
 
+  @Test public void testCartesianProduct() {
+    String query = "select * from \"department\" , \"employee\"";
+    String expected = "SELECT *\n"
+        + "FROM \"foodmart\".\"department\",\n"
+        + "\"foodmart\".\"employee\"";
+    sql(query).ok(expected);
+  }
+
   @Test public void testSimpleIn() {
     String query = "select * from \"department\" where \"department_id\" in (\n"
         + "  select \"department_id\" from \"employee\"\n"

http://git-wip-us.apache.org/repos/asf/calcite/blob/499b55e3/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 61dee87..02db883 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
@@ -360,6 +360,18 @@ public class JdbcAdapterTest {
         .returnsCount(1);
   }
 
+  @Test public void testJoinCartesian() {
+    final String sql = "SELECT *\n"
+        + "FROM Scott.dept, Scott.emp";
+    CalciteAssert.model(JdbcTest.SCOTT_MODEL).query(sql).returnsCount(56);
+  }
+
+  @Test public void testJoinCartesianCount() {
+    final String sql = "SELECT count(*) as c\n"
+        + "FROM Scott.dept, Scott.emp";
+    CalciteAssert.model(JdbcTest.SCOTT_MODEL).query(sql).returns("C=56\n");
+  }
+
   /** Test case for
    * <a href="https://issues.apache.org/jira/browse/CALCITE-657">[CALCITE-657]
    * NullPointerException when executing JdbcAggregate implement method</a>. */


[5/9] calcite git commit: [CALCITE-1586] JDBC adapter generates wrong SQL if UNION has more than two inputs (Zhiqiang He)

Posted by jh...@apache.org.
[CALCITE-1586] JDBC adapter generates wrong SQL if UNION has more than two inputs (Zhiqiang He)

Close apache/calcite#353


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/89f11251
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/89f11251
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/89f11251

Branch: refs/heads/master
Commit: 89f112511ce741c06349015a5f247cfb64ce23a8
Parents: c3288a1
Author: Zhiqiang-He <ab...@qq.com>
Authored: Sat Jan 14 16:21:21 2017 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:00:12 2017 -0800

----------------------------------------------------------------------
 .../calcite/rel/rel2sql/SqlImplementor.java     |  9 ++-
 .../rel/rel2sql/RelToSqlConverterTest.java      | 64 ++++++++++++++++++--
 2 files changed, 65 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/89f11251/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 22c2690..6e6fed4 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -232,12 +232,15 @@ public abstract class SqlImplementor {
   }
 
   public Result setOpToSql(SqlSetOperator operator, RelNode rel) {
-    List<SqlNode> list = Expressions.list();
+    SqlNode node = null;
     for (Ord<RelNode> input : Ord.zip(rel.getInputs())) {
       final Result result = visitChild(input.i, input.e);
-      list.add(result.asSelect());
+      if (node == null) {
+        node = result.asSelect();
+      } else {
+        node = operator.createCall(POS, node, result.asSelect());
+      }
     }
-    final SqlCall node = operator.createCall(new SqlNodeList(list, POS));
     final List<Clause> clauses =
         Expressions.list(Clause.SET_OP);
     return result(node, clauses, rel, null);

http://git-wip-us.apache.org/repos/asf/calcite/blob/89f11251/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 275da82..b97ed3f 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -16,8 +16,14 @@
  */
 package org.apache.calcite.rel.rel2sql;
 
+import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelTraitDef;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.plan.hep.HepProgramBuilder;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.rules.UnionMergeRule;
+import org.apache.calcite.runtime.FlatLists;
 import org.apache.calcite.schema.SchemaPlus;
 import org.apache.calcite.sql.SqlDialect;
 import org.apache.calcite.sql.SqlDialect.DatabaseProduct;
@@ -28,9 +34,14 @@ import org.apache.calcite.tools.FrameworkConfig;
 import org.apache.calcite.tools.Frameworks;
 import org.apache.calcite.tools.Planner;
 import org.apache.calcite.tools.Program;
+import org.apache.calcite.tools.Programs;
+import org.apache.calcite.tools.RuleSet;
+import org.apache.calcite.tools.RuleSets;
 import org.apache.calcite.util.Util;
 
+import com.google.common.base.Function;
 import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
 
 import org.junit.Test;
 
@@ -46,7 +57,7 @@ public class RelToSqlConverterTest {
   /** Initiates a test case with a given SQL query. */
   private Sql sql(String sql) {
     return new Sql(CalciteAssert.SchemaSpec.JDBC_FOODMART, sql,
-        SqlDialect.CALCITE);
+        SqlDialect.CALCITE, ImmutableList.<Function<RelNode, RelNode>>of());
   }
 
   private static Planner getPlanner(List<RelTraitDef> traitDefs,
@@ -510,24 +521,64 @@ public class RelToSqlConverterTest {
     sql(query).ok(expected);
   }
 
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1586">[CALCITE-1586]
+   * JDBC adapter generates wrong SQL if UNION has more than two inputs</a>. */
+  @Test public void testThreeQueryUnion() {
+    String query = "SELECT \"product_id\" FROM \"product\" "
+        + " UNION ALL "
+        + "SELECT \"product_id\" FROM \"sales_fact_1997\" "
+        + " UNION ALL "
+        + "SELECT \"product_class_id\" AS product_id FROM \"product_class\"";
+    String expected = "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "UNION ALL\n"
+        + "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"sales_fact_1997\"\n"
+        + "UNION ALL\n"
+        + "SELECT \"product_class_id\" AS \"PRODUCT_ID\"\n"
+        + "FROM \"foodmart\".\"product_class\"";
+
+    final HepProgram program =
+        new HepProgramBuilder().addRuleClass(UnionMergeRule.class).build();
+    final RuleSet rules = RuleSets.ofList(UnionMergeRule.INSTANCE);
+    sql(query)
+        .optimize(rules, new HepPlanner(program))
+        .ok(expected);
+  }
+
   /** Fluid interface to run tests. */
   private static class Sql {
     private CalciteAssert.SchemaSpec schemaSpec;
     private final String sql;
     private final SqlDialect dialect;
+    private final List<Function<RelNode, RelNode>> transforms;
 
-    Sql(CalciteAssert.SchemaSpec schemaSpec, String sql, SqlDialect dialect) {
+    Sql(CalciteAssert.SchemaSpec schemaSpec, String sql, SqlDialect dialect,
+        List<Function<RelNode, RelNode>> transforms) {
       this.schemaSpec = schemaSpec;
       this.sql = sql;
       this.dialect = dialect;
+      this.transforms = ImmutableList.copyOf(transforms);
     }
 
     Sql dialect(SqlDialect dialect) {
-      return new Sql(schemaSpec, sql, dialect);
+      return new Sql(schemaSpec, sql, dialect, transforms);
     }
 
     Sql planner(Planner planner) {
-      return new Sql(schemaSpec, sql, dialect);
+      return new Sql(schemaSpec, sql, dialect, transforms);
+    }
+
+    Sql optimize(final RuleSet ruleSet, final RelOptPlanner relOptPlanner) {
+      return new Sql(schemaSpec, sql, dialect,
+          FlatLists.append(transforms, new Function<RelNode, RelNode>() {
+            public RelNode apply(RelNode r) {
+              Program program = Programs.of(ruleSet);
+              return program.run(relOptPlanner, r, r.getTraitSet());
+            }
+          }));
     }
 
     Sql ok(String expectedQuery) {
@@ -537,6 +588,9 @@ public class RelToSqlConverterTest {
         SqlNode parse = planner.parse(sql);
         SqlNode validate = planner.validate(parse);
         RelNode rel = planner.rel(validate).rel;
+        for (Function<RelNode, RelNode> transform : transforms) {
+          rel = transform.apply(rel);
+        }
         final RelToSqlConverter converter =
             new RelToSqlConverter(dialect);
         final SqlNode sqlNode = converter.visitChild(0, rel).asStatement();
@@ -549,7 +603,7 @@ public class RelToSqlConverterTest {
     }
 
     public Sql schema(CalciteAssert.SchemaSpec schemaSpec) {
-      return new Sql(schemaSpec, sql, dialect);
+      return new Sql(schemaSpec, sql, dialect, transforms);
     }
   }
 }


[4/9] calcite git commit: [CALCITE-1535] Give error if column referenced in ORDER BY is ambiguous (Zhen Wang)

Posted by jh...@apache.org.
[CALCITE-1535] Give error if column referenced in ORDER BY is ambiguous (Zhen Wang)

Close apache/calcite#359


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/c3288a14
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/c3288a14
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/c3288a14

Branch: refs/heads/master
Commit: c3288a1443f1934db6e081ef691c251ba063edc8
Parents: 0f45481
Author: zhen wang <zi...@gmail.com>
Authored: Sat Jan 21 19:18:42 2017 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:00:12 2017 -0800

----------------------------------------------------------------------
 .../calcite/sql/validate/OrderByScope.java      | 26 +++++++-
 .../apache/calcite/test/SqlValidatorTest.java   | 64 +++++++++++++++-----
 2 files changed, 72 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/c3288a14/core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java b/core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java
index 117390f..e4256c4 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java
@@ -25,6 +25,8 @@ import org.apache.calcite.sql.SqlSelect;
 
 import java.util.List;
 
+import static org.apache.calcite.util.Static.RESOURCE;
+
 /**
  * Represents the name-resolution context for expressions in an ORDER BY clause.
  *
@@ -69,14 +71,20 @@ public class OrderByScope extends DelegatingScope {
     // If it's a simple identifier, look for an alias.
     if (identifier.isSimple()
         && validator.getConformance().isSortByAlias()) {
-      String name = identifier.names.get(0);
+      final String name = identifier.names.get(0);
       final SqlValidatorNamespace selectNs =
           validator.getNamespace(select);
       final RelDataType rowType = selectNs.getRowType();
 
       final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher();
       final RelDataTypeField field = nameMatcher.field(rowType, name);
-      if (field != null && !field.isDynamicStar()) {
+      final int aliasCount = aliasCount(nameMatcher, name);
+      if (aliasCount > 1) {
+        // More than one column has this alias.
+        throw validator.newValidationError(identifier,
+            RESOURCE.columnAmbiguous(name));
+      }
+      if (field != null && !field.isDynamicStar() && aliasCount == 1) {
         // if identifier is resolved to a dynamic star, use super.fullyQualify() for such case.
         return SqlQualified.create(this, 1, selectNs, identifier);
       }
@@ -84,6 +92,20 @@ public class OrderByScope extends DelegatingScope {
     return super.fullyQualify(identifier);
   }
 
+  /** Returns the number of columns in the SELECT clause that have {@code name}
+   * as their implicit (e.g. {@code t.name}) or explicit (e.g.
+   * {@code t.c as name}) alias. */
+  private int aliasCount(SqlNameMatcher nameMatcher, String name) {
+    int n = 0;
+    for (SqlNode s : select.getSelectList()) {
+      final String alias = SqlValidatorUtil.getAlias(s, -1);
+      if (alias != null && nameMatcher.matches(alias, name)) {
+        n++;
+      }
+    }
+    return n;
+  }
+
   public RelDataType resolveColumn(String name, SqlNode ctx) {
     final SqlValidatorNamespace selectNs = validator.getNamespace(select);
     final RelDataType rowType = selectNs.getRowType();

http://git-wip-us.apache.org/repos/asf/calcite/blob/c3288a14/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 898ce80..6c7ccd7 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -4430,6 +4430,36 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
         .fails("Column 'DEPTNO' is ambiguous");
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1535">[CALCITE-1535]
+   * Give error if column referenced in ORDER BY is ambiguous</a>. */
+  @Test public void testOrderByColumn() {
+    sql("select emp.deptno from emp, dept order by emp.deptno")
+        .ok();
+    // Not ambiguous. There are two columns which could be referenced as
+    // "deptno", but the one in the SELECT clause takes priority.
+    sql("select emp.deptno from emp, dept order by deptno")
+        .ok();
+    sql("select emp.deptno as deptno from emp, dept order by deptno")
+        .ok();
+    sql("select emp.empno as deptno from emp, dept order by deptno")
+        .ok();
+    sql("select emp.deptno as n, dept.deptno as n from emp, dept order by ^n^")
+        .fails("Column 'N' is ambiguous");
+    sql("select emp.empno as deptno, dept.deptno from emp, dept\n"
+        + "order by ^deptno^")
+        .fails("Column 'DEPTNO' is ambiguous");
+    sql("select emp.empno as deptno, dept.deptno from emp, dept\n"
+        + "order by emp.deptno")
+        .ok();
+    sql("select emp.empno as deptno, dept.deptno from emp, dept order by 1, 2")
+        .ok();
+    sql("select empno as \"deptno\", deptno from emp order by deptno")
+        .ok();
+    sql("select empno as \"deptno\", deptno from emp order by \"deptno\"")
+        .ok();
+  }
+
   @Test public void testWindowNegative() {
     // Do not fail when window has negative size. Allow
     final String negSize = null;
@@ -7375,9 +7405,9 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
   }
 
   @Test public void testRewriteWithColumnReferenceExpansion() {
-    // NOTE jvs 9-Apr-2007:  This tests illustrates that
-    // ORDER BY is still a special case.  Update expected
-    // output if that gets fixed in the future.
+    // The names in the ORDER BY clause are not qualified.
+    // This is because ORDER BY references columns in the SELECT clause
+    // in preference to columns in tables in the FROM clause.
 
     SqlValidator validator = tester.getValidator();
     validator.setIdentifierExpansion(true);
@@ -7395,25 +7425,27 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
   }
 
   @Test public void testRewriteWithColumnReferenceExpansionAndFromAlias() {
-    // NOTE jvs 9-Apr-2007:  This tests illustrates that
-    // ORDER BY is still a special case.  Update expected
-    // output if that gets fixed in the future.
+    // In the ORDER BY clause, 'ename' is not qualified but 'deptno' and 'sal'
+    // are. This is because 'ename' appears as an alias in the SELECT clause.
+    // 'sal' is qualified in the ORDER BY clause, so remains qualified.
 
     SqlValidator validator = tester.getValidator();
     validator.setIdentifierExpansion(true);
     validator.setColumnReferenceExpansion(true);
     tester.checkRewrite(
         validator,
-        "select name from (select * from dept)"
-            + " where name = 'Moonracer' group by name"
-            + " having sum(deptno) > 3 order by name",
-        "SELECT `EXPR$0`.`NAME`\n"
-            + "FROM (SELECT `DEPT`.`DEPTNO`, `DEPT`.`NAME`\n"
-            + "FROM `CATALOG`.`SALES`.`DEPT` AS `DEPT`) AS `EXPR$0`\n"
-            + "WHERE `EXPR$0`.`NAME` = 'Moonracer'\n"
-            + "GROUP BY `EXPR$0`.`NAME`\n"
-            + "HAVING SUM(`EXPR$0`.`DEPTNO`) > 3\n"
-            + "ORDER BY `NAME`");
+        "select ename, sal from (select * from emp) as e"
+            + " where ename = 'Moonracer' group by ename, deptno, sal"
+            + " having sum(deptno) > 3 order by ename, deptno, e.sal",
+        "SELECT `E`.`ENAME`, `E`.`SAL`\n"
+            + "FROM (SELECT `EMP`.`EMPNO`, `EMP`.`ENAME`, `EMP`.`JOB`,"
+            + " `EMP`.`MGR`, `EMP`.`HIREDATE`, `EMP`.`SAL`, `EMP`.`COMM`,"
+            + " `EMP`.`DEPTNO`, `EMP`.`SLACKER`\n"
+            + "FROM `CATALOG`.`SALES`.`EMP` AS `EMP`) AS `E`\n"
+            + "WHERE `E`.`ENAME` = 'Moonracer'\n"
+            + "GROUP BY `E`.`ENAME`, `E`.`DEPTNO`, `E`.`SAL`\n"
+            + "HAVING SUM(`E`.`DEPTNO`) > 3\n"
+            + "ORDER BY `ENAME`, `E`.`DEPTNO`, `E`.`SAL`");
   }
 
   @Test public void testCoalesceWithoutRewrite() {


[9/9] calcite git commit: [CALCITE-1602] Remove uses of deprecated APIs

Posted by jh...@apache.org.
[CALCITE-1602] Remove uses of deprecated APIs


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/5181563f
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/5181563f
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/5181563f

Branch: refs/heads/master
Commit: 5181563f9f26d1533a7d98ecca8443077e7b7efa
Parents: d335e48
Author: Julian Hyde <jh...@apache.org>
Authored: Tue Jan 24 11:49:40 2017 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Jan 25 11:21:36 2017 -0800

----------------------------------------------------------------------
 .../avatica/AvaticaPreparedStatement.java       |  1 +
 .../calcite/avatica/AvaticaResultSet.java       |  4 ++
 .../apache/calcite/avatica/AvaticaUtils.java    |  2 +-
 .../calcite/avatica/UnregisteredDriver.java     |  8 +--
 .../calcite/avatica/remote/RemoteMeta.java      |  2 +
 .../apache/calcite/avatica/remote/Service.java  |  4 +-
 .../calcite/avatica/util/AbstractCursor.java    |  2 +-
 .../AvaticaResultSetConversionsTest.java        |  2 +
 .../calcite/avatica/MetaResultSetTest.java      |  2 +
 .../avatica/remote/KerberosConnectionTest.java  |  2 +-
 .../noop/AvaticaNoopPreparedStatement.java      |  1 +
 .../avatica/noop/AvaticaNoopResultSet.java      |  4 ++
 avatica/pom.xml                                 |  1 +
 .../apache/calcite/avatica/jdbc/JdbcMeta.java   |  2 +
 .../server/DelegatingAvaticaHandler.java        |  2 +-
 .../calcite/avatica/server/HttpServer.java      |  2 +-
 .../org/apache/calcite/avatica/server/Main.java | 22 +++++----
 .../calcite/adapter/enumerable/RexImpTable.java |  3 +-
 .../calcite/adapter/java/ReflectiveSchema.java  | 22 ++++-----
 .../calcite/interpreter/AggregateNode.java      |  8 ++-
 .../apache/calcite/interpreter/Interpreter.java |  1 +
 .../apache/calcite/jdbc/CalciteMetaImpl.java    |  2 +
 .../calcite/plan/AbstractRelOptPlanner.java     |  2 +
 .../calcite/prepare/CalciteCatalogReader.java   |  3 ++
 .../org/apache/calcite/prepare/PlannerImpl.java |  1 +
 .../org/apache/calcite/rel/AbstractRelNode.java |  8 +++
 .../java/org/apache/calcite/rel/core/Sort.java  |  1 +
 .../org/apache/calcite/rel/core/TableScan.java  |  1 +
 .../rel/type/RelDataTypeFactoryImpl.java        | 24 +++++----
 .../java/org/apache/calcite/rex/RexBuilder.java |  7 +--
 .../org/apache/calcite/rex/RexCallBinding.java  |  2 +
 .../org/apache/calcite/rex/RexExecutable.java   |  9 +++-
 .../apache/calcite/runtime/SqlFunctions.java    | 10 ++--
 .../calcite/schema/impl/TableFunctionImpl.java  | 10 ++--
 .../calcite/schema/impl/TableMacroImpl.java     | 12 ++---
 .../org/apache/calcite/sql/SqlCallBinding.java  |  2 +
 .../apache/calcite/sql/SqlFilterOperator.java   |  5 +-
 .../apache/calcite/sql/SqlIntervalLiteral.java  |  1 +
 .../apache/calcite/sql/SqlJdbcFunctionCall.java |  3 +-
 .../org/apache/calcite/sql/SqlOperator.java     |  5 +-
 .../org/apache/calcite/sql/SqlOverOperator.java |  5 +-
 .../apache/calcite/sql/fun/SqlCaseOperator.java |  5 +-
 .../apache/calcite/sql/fun/SqlCastFunction.java |  7 +--
 .../calcite/sql/fun/SqlCountAggFunction.java    |  2 +
 .../sql/fun/SqlFirstLastValueAggFunction.java   |  2 +
 .../sql/fun/SqlHistogramAggFunction.java        |  2 +
 .../apache/calcite/sql/fun/SqlInOperator.java   |  5 +-
 .../calcite/sql/fun/SqlMinMaxAggFunction.java   |  2 +
 .../sql/fun/SqlSingleValueAggFunction.java      |  2 +
 .../calcite/sql/fun/SqlSumAggFunction.java      |  2 +
 .../sql/fun/SqlSumEmptyIsZeroAggFunction.java   |  2 +
 .../calcite/sql/validate/AbstractNamespace.java |  1 +
 .../sql/validate/DelegatingNamespace.java       |  1 +
 .../calcite/sql/validate/DelegatingScope.java   |  2 +
 .../apache/calcite/sql/validate/EmptyScope.java |  2 +
 .../apache/calcite/sql/validate/ListScope.java  |  2 +-
 .../sql/validate/SqlUserDefinedAggFunction.java |  2 +
 .../calcite/sql/validate/SqlValidatorImpl.java  | 52 ++++++++++----------
 .../calcite/sql2rel/SqlToRelConverter.java      |  3 +-
 .../sql2rel/StandardConvertletTable.java        |  3 +-
 .../org/apache/calcite/util/NumberUtil.java     |  3 +-
 .../concurrent/ConcurrentTestCommandScript.java | 16 +++---
 .../org/apache/calcite/tools/PlannerTest.java   |  2 +
 .../apache/calcite/util/ReflectVisitorTest.java | 30 ++++++-----
 .../java/org/apache/calcite/util/UtilTest.java  | 17 ++++---
 .../adapter/druid/DruidConnectionImpl.java      |  1 +
 .../elasticsearch/ElasticsearchRules.java       | 26 +++++-----
 .../org/apache/calcite/linq4j/tree/Types.java   |  4 +-
 .../apache/calcite/linq4j/test/Linq4jTest.java  |  9 ++--
 pom.xml                                         |  1 +
 .../calcite/adapter/spark/SparkHandlerImpl.java | 20 ++++----
 71 files changed, 267 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
index 5e25a03..31cdfd2 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaPreparedStatement.java
@@ -197,6 +197,7 @@ public abstract class AvaticaPreparedStatement
     getSite(parameterIndex).setAsciiStream(x, length);
   }
 
+  @SuppressWarnings("deprecation")
   public void setUnicodeStream(int parameterIndex, InputStream x, int length)
       throws SQLException {
     getSite(parameterIndex).setUnicodeStream(x, length);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
index cfeff03..a102eba 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java
@@ -273,6 +273,7 @@ public class AvaticaResultSet implements ResultSet, ArrayImpl.Factory {
     return getAccessor(columnIndex).getDouble();
   }
 
+  @SuppressWarnings("deprecation")
   public BigDecimal getBigDecimal(
       int columnIndex, int scale) throws SQLException {
     return getAccessor(columnIndex).getBigDecimal(scale);
@@ -298,6 +299,7 @@ public class AvaticaResultSet implements ResultSet, ArrayImpl.Factory {
     return getAccessor(columnIndex).getAsciiStream();
   }
 
+  @SuppressWarnings("deprecation")
   public InputStream getUnicodeStream(int columnIndex) throws SQLException {
     return getAccessor(columnIndex).getUnicodeStream();
   }
@@ -338,6 +340,7 @@ public class AvaticaResultSet implements ResultSet, ArrayImpl.Factory {
     return getAccessor(columnLabel).getDouble();
   }
 
+  @SuppressWarnings("deprecation")
   public BigDecimal getBigDecimal(
       String columnLabel, int scale) throws SQLException {
     return getAccessor(columnLabel).getBigDecimal(scale);
@@ -363,6 +366,7 @@ public class AvaticaResultSet implements ResultSet, ArrayImpl.Factory {
     return getAccessor(columnLabel).getAsciiStream();
   }
 
+  @SuppressWarnings("deprecation")
   public InputStream getUnicodeStream(String columnLabel) throws SQLException {
     return getAccessor(columnLabel).getUnicodeStream();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java
index 8c16959..53aff83 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java
@@ -234,7 +234,7 @@ public class AvaticaUtils {
       } catch (NoSuchFieldException e) {
         // ignore
       }
-      return clazz.newInstance();
+      return clazz.getConstructor().newInstance();
     } catch (Exception e) {
       throw new RuntimeException("Property '" + className
           + "' not valid for plugin type " + pluginClass.getName(), e);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java b/avatica/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
index b1fe787..4118fd7 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
@@ -113,13 +113,7 @@ public abstract class UnregisteredDriver implements java.sql.Driver {
   protected static AvaticaFactory instantiateFactory(String factoryClassName) {
     try {
       final Class<?> clazz = Class.forName(factoryClassName);
-      return (AvaticaFactory) clazz.newInstance();
-    } catch (ClassNotFoundException e) {
-      throw handle("Error loading factory " + factoryClassName, e);
-    } catch (IllegalAccessException e) {
-      throw handle("Error loading factory " + factoryClassName, e);
-    } catch (InstantiationException e) {
-      throw handle("Error loading factory " + factoryClassName, e);
+      return (AvaticaFactory) clazz.getConstructor().newInstance();
     } catch (Throwable e) {
       // It is not usually good to catch Throwable. But class loading can fail
       // with serious errors such as java.lang.NoClassDefFoundError

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
index 7ee2226..75b9d58 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/RemoteMeta.java
@@ -244,6 +244,7 @@ class RemoteMeta extends MetaImpl {
         });
   }
 
+  @SuppressWarnings("deprecation")
   @Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount,
       PrepareCallback callback) throws NoSuchStatementException {
     // The old semantics were that maxRowCount was also treated as the maximum number of
@@ -327,6 +328,7 @@ class RemoteMeta extends MetaImpl {
     }
   }
 
+  @SuppressWarnings("deprecation")
   @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues,
       long maxRowCount) throws NoSuchStatementException {
     return execute(h, parameterValues, AvaticaUtils.toSaturatedInt(maxRowCount));

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/Service.java b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
index 1f398ef..786d07a 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/remote/Service.java
@@ -1776,7 +1776,7 @@ public interface Service {
         connectionId = msg.getConnectionId();
       }
 
-      Map<String, String> info = msg.getInfo();
+      Map<String, String> info = msg.getInfoMap();
       if (info.isEmpty()) {
         info = null;
       }
@@ -1790,7 +1790,7 @@ public interface Service {
         builder.setConnectionId(connectionId);
       }
       if (null != info) {
-        builder.getMutableInfo().putAll(info);
+        builder.putAllInfo(info);
       }
 
       return builder.build();

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java b/avatica/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
index 74fb803..3bf69d6 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
@@ -704,7 +704,7 @@ public abstract class AbstractCursor implements Cursor {
       }
       BigDecimal decimal = AvaticaSite.toBigDecimal(n);
       if (0 != scale) {
-        return decimal.setScale(scale, BigDecimal.ROUND_UNNECESSARY);
+        return decimal.setScale(scale, RoundingMode.UNNECESSARY);
       }
       return decimal;
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java
index 79b1dca..95d160b 100644
--- a/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java
+++ b/avatica/core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetConversionsTest.java
@@ -85,6 +85,7 @@ public class AvaticaResultSetConversionsTest {
       throw new UnsupportedOperationException();
     }
 
+    @SuppressWarnings("deprecation")
     @Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql,
         long maxRowCount, PrepareCallback callback) throws NoSuchStatementException {
       throw new UnsupportedOperationException();
@@ -190,6 +191,7 @@ public class AvaticaResultSetConversionsTest {
       throw new UnsupportedOperationException();
     }
 
+    @SuppressWarnings("deprecation")
     @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues,
         long maxRowCount) throws NoSuchStatementException {
       throw new UnsupportedOperationException();

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/test/java/org/apache/calcite/avatica/MetaResultSetTest.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/MetaResultSetTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/MetaResultSetTest.java
index 64eebda..6ec1dc7 100644
--- a/avatica/core/src/test/java/org/apache/calcite/avatica/MetaResultSetTest.java
+++ b/avatica/core/src/test/java/org/apache/calcite/avatica/MetaResultSetTest.java
@@ -68,6 +68,7 @@ public class MetaResultSetTest {
       throw new UnsupportedOperationException();
     }
 
+    @SuppressWarnings("deprecation")
     @Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql,
         long maxRowCount, PrepareCallback callback) throws NoSuchStatementException {
       throw new UnsupportedOperationException();
@@ -94,6 +95,7 @@ public class MetaResultSetTest {
       throw new UnsupportedOperationException();
     }
 
+    @SuppressWarnings("deprecation")
     @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues,
         long maxRowCount) throws NoSuchStatementException {
       throw new UnsupportedOperationException();

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java
index 4122afd..a57b95b 100644
--- a/avatica/core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java
+++ b/avatica/core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.nullable;
 import static org.mockito.Mockito.verify;

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopPreparedStatement.java
----------------------------------------------------------------------
diff --git a/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopPreparedStatement.java b/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopPreparedStatement.java
index b8ad8cc..0d936ed 100644
--- a/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopPreparedStatement.java
+++ b/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopPreparedStatement.java
@@ -243,6 +243,7 @@ public class AvaticaNoopPreparedStatement implements PreparedStatement {
   @Override public void setAsciiStream(int parameterIndex, InputStream x, int length)
       throws SQLException {}
 
+  @SuppressWarnings("deprecation")
   @Override public void setUnicodeStream(int parameterIndex, InputStream x, int length)
       throws SQLException {}
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopResultSet.java
----------------------------------------------------------------------
diff --git a/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopResultSet.java b/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopResultSet.java
index 2d71184..022f610 100644
--- a/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopResultSet.java
+++ b/avatica/noop-driver/src/main/java/org/apache/calcite/avatica/noop/AvaticaNoopResultSet.java
@@ -105,6 +105,7 @@ public class AvaticaNoopResultSet implements ResultSet {
     throw unsupported();
   }
 
+  @SuppressWarnings("deprecation")
   @Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
     throw unsupported();
   }
@@ -129,6 +130,7 @@ public class AvaticaNoopResultSet implements ResultSet {
     throw unsupported();
   }
 
+  @SuppressWarnings("deprecation")
   @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException {
     throw unsupported();
   }
@@ -169,6 +171,7 @@ public class AvaticaNoopResultSet implements ResultSet {
     throw unsupported();
   }
 
+  @SuppressWarnings("deprecation")
   @Override public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
     throw unsupported();
   }
@@ -193,6 +196,7 @@ public class AvaticaNoopResultSet implements ResultSet {
     throw unsupported();
   }
 
+  @SuppressWarnings("deprecation")
   @Override public InputStream getUnicodeStream(String columnLabel) throws SQLException {
     throw unsupported();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/pom.xml
----------------------------------------------------------------------
diff --git a/avatica/pom.xml b/avatica/pom.xml
index 02a5d20..d8952aa 100644
--- a/avatica/pom.xml
+++ b/avatica/pom.xml
@@ -357,6 +357,7 @@ limitations under the License.
         <configuration>
           <source>1.7</source>
           <target>1.7</target>
+          <compilerArgument>-Xlint:deprecation</compilerArgument>
         </configuration>
       </plugin>
       <plugin>

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
----------------------------------------------------------------------
diff --git a/avatica/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java b/avatica/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
index 204421f..e90d78a 100644
--- a/avatica/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
+++ b/avatica/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
@@ -708,6 +708,7 @@ public class JdbcMeta implements ProtobufMeta {
     }
   }
 
+  @SuppressWarnings("deprecation")
   public ExecuteResult prepareAndExecute(StatementHandle h, String sql,
       long maxRowCount, PrepareCallback callback) throws NoSuchStatementException {
     return prepareAndExecute(h, sql, maxRowCount, AvaticaUtils.toSaturatedInt(maxRowCount),
@@ -817,6 +818,7 @@ public class JdbcMeta implements ProtobufMeta {
     return typeList.toArray(new String[typeList.size()]);
   }
 
+  @SuppressWarnings("deprecation")
   @Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues,
       long maxRowCount) throws NoSuchStatementException {
     return execute(h, parameterValues, AvaticaUtils.toSaturatedInt(maxRowCount));

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/server/src/main/java/org/apache/calcite/avatica/server/DelegatingAvaticaHandler.java
----------------------------------------------------------------------
diff --git a/avatica/server/src/main/java/org/apache/calcite/avatica/server/DelegatingAvaticaHandler.java b/avatica/server/src/main/java/org/apache/calcite/avatica/server/DelegatingAvaticaHandler.java
index a574985..fff176d 100644
--- a/avatica/server/src/main/java/org/apache/calcite/avatica/server/DelegatingAvaticaHandler.java
+++ b/avatica/server/src/main/java/org/apache/calcite/avatica/server/DelegatingAvaticaHandler.java
@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
  * <p>This implementation provides a no-op implementation for
  * {@link #setServerRpcMetadata(org.apache.calcite.avatica.remote.Service.RpcMetadataResponse)}.
  *
- * Does not implement {@link MetricsAwareAvaticaHandler} as this implementation is only presented
+ * <p>Does not implement {@link MetricsAwareAvaticaHandler} as this implementation is only presented
  * for backwards compatibility.
  */
 public class DelegatingAvaticaHandler implements AvaticaHandler {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java
----------------------------------------------------------------------
diff --git a/avatica/server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java b/avatica/server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java
index a8524ec..911d359 100644
--- a/avatica/server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java
+++ b/avatica/server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java
@@ -142,7 +142,7 @@ public class HttpServer {
     this.sslFactory = sslFactory;
   }
 
-  private static AvaticaHandler wrapJettyHandler(Handler handler) {
+  static AvaticaHandler wrapJettyHandler(Handler handler) {
     if (handler instanceof AvaticaHandler) {
       return (AvaticaHandler) handler;
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/avatica/server/src/main/java/org/apache/calcite/avatica/server/Main.java
----------------------------------------------------------------------
diff --git a/avatica/server/src/main/java/org/apache/calcite/avatica/server/Main.java b/avatica/server/src/main/java/org/apache/calcite/avatica/server/Main.java
index 8b05931..f2d546b 100644
--- a/avatica/server/src/main/java/org/apache/calcite/avatica/server/Main.java
+++ b/avatica/server/src/main/java/org/apache/calcite/avatica/server/Main.java
@@ -22,6 +22,7 @@ import org.apache.calcite.avatica.remote.Service;
 
 import org.eclipse.jetty.server.handler.AbstractHandler;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 
 /**
@@ -30,9 +31,9 @@ import java.util.Arrays;
 public class Main {
   private Main() {}
 
-  public static void main(String[] args)
-      throws InterruptedException, ClassNotFoundException,
-      IllegalAccessException, InstantiationException {
+  public static void main(String[] args) throws InterruptedException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException, NoSuchMethodException,
+      InvocationTargetException {
     HttpServer server = start(args);
     server.join();
   }
@@ -64,7 +65,8 @@ public class Main {
    * @param args Command-line arguments
    */
   public static HttpServer start(String[] args) throws ClassNotFoundException,
-         InstantiationException, IllegalAccessException {
+      InstantiationException, IllegalAccessException, NoSuchMethodException,
+      InvocationTargetException {
     return start(args, 8765, JSON_HANDLER_FACTORY);
   }
 
@@ -84,14 +86,16 @@ public class Main {
    * @param handlerFactory Factory to create the handler used by the server
    */
   public static HttpServer start(String[] args, int port, HandlerFactory handlerFactory)
-      throws ClassNotFoundException, InstantiationException,
-      IllegalAccessException {
+      throws ClassNotFoundException, InstantiationException, IllegalAccessException,
+      NoSuchMethodException, InvocationTargetException {
     String factoryClassName = args[0];
-    Class<?> factoryClass = Class.forName(factoryClassName);
-    Meta.Factory factory = (Meta.Factory) factoryClass.newInstance();
+    @SuppressWarnings("unchecked") Class<Meta.Factory> factoryClass =
+        (Class<Meta.Factory>) Class.forName(factoryClassName);
+    Meta.Factory factory = factoryClass.getConstructor().newInstance();
     Meta meta = factory.create(Arrays.asList(args).subList(1, args.length));
     Service service = new LocalService(meta);
-    HttpServer server = new HttpServer(port, handlerFactory.createHandler(service));
+    HttpServer server = new HttpServer(port,
+        HttpServer.wrapJettyHandler(handlerFactory.createHandler(service)));
     server.start();
     return server;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 3d87041..eff8cc1 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -65,6 +65,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -1035,7 +1036,7 @@ public class RexImpTable {
           Expressions.constant(divider.intValueExact()));
     }
     final BigDecimal x =
-        multiplier.divide(divider, BigDecimal.ROUND_UNNECESSARY);
+        multiplier.divide(divider, RoundingMode.UNNECESSARY);
     switch (x.compareTo(BigDecimal.ONE)) {
     case 0:
       return e;

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java b/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
index a7155a1..91fe3e7 100644
--- a/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/java/ReflectiveSchema.java
@@ -49,6 +49,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Multimap;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -62,7 +63,7 @@ import java.util.Map;
  */
 public class ReflectiveSchema
     extends AbstractSchema {
-  final Class clazz;
+  private final Class clazz;
   private Object target;
 
   /**
@@ -148,7 +149,7 @@ public class ReflectiveSchema
     }
     @SuppressWarnings("unchecked")
     final Enumerable<T> enumerable = toEnumerable(o);
-    return new FieldTable<T>(field, elementType, enumerable);
+    return new FieldTable<>(field, elementType, enumerable);
   }
 
   /** Deduces the element type of a collection;
@@ -185,7 +186,7 @@ public class ReflectiveSchema
     private final Type elementType;
     private final Enumerable enumerable;
 
-    public ReflectiveTable(Type elementType, Enumerable enumerable) {
+    ReflectiveTable(Type elementType, Enumerable enumerable) {
       super(elementType);
       this.elementType = elementType;
       this.enumerable = enumerable;
@@ -254,7 +255,7 @@ public class ReflectiveSchema
   public static class Factory implements SchemaFactory {
     public Schema create(SchemaPlus parentSchema, String name,
         Map<String, Object> operand) {
-      Class clazz;
+      Class<?> clazz;
       Object target;
       final Object className = operand.get("class");
       if (className != null) {
@@ -277,7 +278,8 @@ public class ReflectiveSchema
         }
       } else {
         try {
-          target = clazz.newInstance();
+          final Constructor<?> constructor = clazz.getConstructor();
+          target = constructor.newInstance();
         } catch (Exception e) {
           throw new RuntimeException("Error instantiating class " + className,
               e);
@@ -292,7 +294,7 @@ public class ReflectiveSchema
       implements TableMacro {
     private final ReflectiveSchema schema;
 
-    public MethodTableMacro(ReflectiveSchema schema, Method method) {
+    MethodTableMacro(ReflectiveSchema schema, Method method) {
       super(method);
       this.schema = schema;
       assert TranslatableTable.class.isAssignableFrom(method.getReturnType())
@@ -308,9 +310,7 @@ public class ReflectiveSchema
       try {
         final Object o = method.invoke(schema.getTarget(), arguments.toArray());
         return (TranslatableTable) o;
-      } catch (IllegalAccessException e) {
-        throw new RuntimeException(e);
-      } catch (InvocationTargetException e) {
+      } catch (IllegalAccessException | InvocationTargetException e) {
         throw new RuntimeException(e);
       }
     }
@@ -320,7 +320,7 @@ public class ReflectiveSchema
   private static class FieldTable<T> extends ReflectiveTable {
     private final Field field;
 
-    public FieldTable(Field field, Type elementType, Enumerable<T> enumerable) {
+    FieldTable(Field field, Type elementType, Enumerable<T> enumerable) {
       super(elementType, enumerable);
       this.field = field;
     }
@@ -341,7 +341,7 @@ public class ReflectiveSchema
   private static class FieldSelector implements Function1<Object, Object[]> {
     private final Field[] fields;
 
-    public FieldSelector(Class elementType) {
+    FieldSelector(Class elementType) {
       this.fields = elementType.getFields();
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
index a342b25..5a5d265 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java
@@ -45,6 +45,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -448,8 +449,11 @@ public class AggregateNode extends AbstractSingleNode<Aggregate> {
         instance = null;
       } else {
         try {
-          instance = aggFunction.declaringClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+          final Constructor<?> constructor =
+              aggFunction.declaringClass.getConstructor();
+          instance = constructor.newInstance();
+        } catch (InstantiationException | IllegalAccessException
+            | NoSuchMethodException | InvocationTargetException e) {
           throw new RuntimeException(e);
         }
       }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
index 5b2752c..0e154eb 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
@@ -369,6 +369,7 @@ public class Interpreter extends AbstractEnumerable<Object[]>
     public void end() throws InterruptedException {
     }
 
+    @SuppressWarnings("deprecation")
     @Override public void setSourceEnumerable(Enumerable<Row> enumerable)
         throws InterruptedException {
       // just copy over the source into the local list

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
index daf6e8b..1cd88e4 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
@@ -575,6 +575,7 @@ public class CalciteMetaImpl extends MetaImpl {
     return h;
   }
 
+  @SuppressWarnings("deprecation")
   @Override public ExecuteResult prepareAndExecute(StatementHandle h,
       String sql, long maxRowCount, PrepareCallback callback)
       throws NoSuchStatementException {
@@ -629,6 +630,7 @@ public class CalciteMetaImpl extends MetaImpl {
     return new Meta.Frame(offset, done, rows1);
   }
 
+  @SuppressWarnings("deprecation")
   @Override public ExecuteResult execute(StatementHandle h,
       List<TypedValue> parameterValues, long maxRowCount)
       throws NoSuchStatementException {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
index eaed2ef..698c790 100644
--- a/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/AbstractRelOptPlanner.java
@@ -108,6 +108,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
     return costFactory;
   }
 
+  @SuppressWarnings("deprecation")
   public void setCancelFlag(CancelFlag cancelFlag) {
     // ignored
   }
@@ -242,6 +243,7 @@ public abstract class AbstractRelOptPlanner implements RelOptPlanner {
     return mq.getCumulativeCost(rel);
   }
 
+  @SuppressWarnings("deprecation")
   public RelOptCost getCost(RelNode rel) {
     final RelMetadataQuery mq = RelMetadataQuery.instance();
     return getCost(rel, mq);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
index 277a6f9..b03f44b 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
@@ -250,10 +250,12 @@ public class CalciteCatalogReader implements Prepare.CatalogReader {
     return getTable(names);
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataTypeField field(RelDataType rowType, String alias) {
     return nameMatcher.field(rowType, alias);
   }
 
+  @SuppressWarnings("deprecation")
   public boolean matches(String string, String name) {
     return nameMatcher.matches(string, name);
   }
@@ -394,6 +396,7 @@ public class CalciteCatalogReader implements Prepare.CatalogReader {
   public void registerRules(RelOptPlanner planner) throws Exception {
   }
 
+  @SuppressWarnings("deprecation")
   @Override public boolean isCaseSensitive() {
     return nameMatcher.isCaseSensitive();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
index 635b2c5..a143e1a 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -210,6 +210,7 @@ public class PlannerImpl implements Planner {
     return Pair.of(validatedNode, type);
   }
 
+  @SuppressWarnings("deprecation")
   public final RelNode convert(SqlNode sql) throws RelConversionException {
     return rel(sql).rel;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
index 78ac0da..3b6be13 100644
--- a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
+++ b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
@@ -140,6 +140,7 @@ public abstract class AbstractRelNode implements RelNode {
     return collection.get(0);
   }
 
+  @SuppressWarnings("deprecation")
   public List<RexNode> getChildExps() {
     return ImmutableList.of();
   }
@@ -160,11 +161,13 @@ public abstract class AbstractRelNode implements RelNode {
     return null;
   }
 
+  @SuppressWarnings("deprecation")
   public boolean isDistinct() {
     final RelMetadataQuery mq = RelMetadataQuery.instance();
     return Boolean.TRUE.equals(mq.areRowsUnique(this));
   }
 
+  @SuppressWarnings("deprecation")
   public boolean isKey(ImmutableBitSet columns) {
     final RelMetadataQuery mq = RelMetadataQuery.instance();
     return Boolean.TRUE.equals(mq.areColumnsUnique(this, columns));
@@ -179,6 +182,7 @@ public abstract class AbstractRelNode implements RelNode {
     return inputs.get(i);
   }
 
+  @SuppressWarnings("deprecation")
   public final RelOptQuery getQuery() {
     return getCluster().getQuery();
   }
@@ -204,6 +208,7 @@ public abstract class AbstractRelNode implements RelNode {
     return litmus.succeed();
   }
 
+  @SuppressWarnings("deprecation")
   public boolean isValid(boolean fail) {
     return isValid(Litmus.THROW, null);
   }
@@ -236,6 +241,7 @@ public abstract class AbstractRelNode implements RelNode {
     return Collections.emptyList();
   }
 
+  @SuppressWarnings("deprecation")
   public final double getRows() {
     return estimateRowCount(RelMetadataQuery.instance());
   }
@@ -244,6 +250,7 @@ public abstract class AbstractRelNode implements RelNode {
     return 1.0;
   }
 
+  @SuppressWarnings("deprecation")
   public final Set<String> getVariablesStopped() {
     return CorrelationId.names(getVariablesSet());
   }
@@ -276,6 +283,7 @@ public abstract class AbstractRelNode implements RelNode {
     return this;
   }
 
+  @SuppressWarnings("deprecation")
   public final RelOptCost computeSelfCost(RelOptPlanner planner) {
     return computeSelfCost(planner, RelMetadataQuery.instance());
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rel/core/Sort.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Sort.java b/core/src/main/java/org/apache/calcite/rel/core/Sort.java
index ec42fbf..001fcd2 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Sort.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Sort.java
@@ -173,6 +173,7 @@ public abstract class Sort extends SingleRel {
     return collation;
   }
 
+  @SuppressWarnings("deprecation")
   @Override public List<RelCollation> getCollationList() {
     return Collections.singletonList(getCollation());
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
index 27f842d..d87715b 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/TableScan.java
@@ -79,6 +79,7 @@ public abstract class TableScan extends AbstractRelNode {
     return table;
   }
 
+  @SuppressWarnings("deprecation")
   @Override public List<RelCollation> getCollationList() {
     return table.getCollationList();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
index 949c9eb..5457289 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
@@ -147,7 +147,7 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
     return canonize(kind, fieldNameList, typeList);
   }
 
-  // implement RelDataTypeFactory
+  @SuppressWarnings("deprecation")
   public RelDataType createStructType(
       final RelDataTypeFactory.FieldInfo fieldInfo) {
     return canonize(StructKind.FULLY_QUALIFIED,
@@ -171,22 +171,26 @@ public abstract class RelDataTypeFactoryImpl implements RelDataTypeFactory {
         });
   }
 
-  // implement RelDataTypeFactory
   public final RelDataType createStructType(
       final List<? extends Map.Entry<String, RelDataType>> fieldList) {
-    return createStructType(
-        new FieldInfo() {
-          public int getFieldCount() {
-            return fieldList.size();
-          }
-
-          public String getFieldName(int index) {
+    return canonize(StructKind.FULLY_QUALIFIED,
+        new AbstractList<String>() {
+          @Override public String get(int index) {
             return fieldList.get(index).getKey();
           }
 
-          public RelDataType getFieldType(int index) {
+          @Override public int size() {
+            return fieldList.size();
+          }
+        },
+        new AbstractList<RelDataType>() {
+          @Override public RelDataType get(int index) {
             return fieldList.get(index).getValue();
           }
+
+          @Override public int size() {
+            return fieldList.size();
+          }
         });
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index d8edee9..b6ef396 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -54,6 +54,7 @@ import com.google.common.collect.Lists;
 
 import java.math.BigDecimal;
 import java.math.MathContext;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -536,7 +537,7 @@ public class RexBuilder {
             final BigDecimal divider =
                 literal.getTypeName().getEndUnit().multiplier;
             value = value2.multiply(multiplier)
-                .divide(divider, 0, BigDecimal.ROUND_HALF_DOWN);
+                .divide(divider, 0, RoundingMode.HALF_DOWN);
           }
 
           // Not all types are allowed for literals
@@ -663,12 +664,12 @@ public class RexBuilder {
       // E.g. multiplyDivide(e, 1000, 10) ==> e * 100
       return makeCall(SqlStdOperatorTable.MULTIPLY, e,
           makeExactLiteral(
-              multiplier.divide(divider, BigDecimal.ROUND_UNNECESSARY)));
+              multiplier.divide(divider, RoundingMode.UNNECESSARY)));
     case -1:
       // E.g. multiplyDivide(e, 10, 1000) ==> e / 100
       return makeCall(SqlStdOperatorTable.DIVIDE_INTEGER, e,
           makeExactLiteral(
-              divider.divide(multiplier, BigDecimal.ROUND_UNNECESSARY)));
+              divider.divide(multiplier, RoundingMode.UNNECESSARY)));
     default:
       throw new AssertionError(multiplier + "/" + divider);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rex/RexCallBinding.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexCallBinding.java b/core/src/main/java/org/apache/calcite/rex/RexCallBinding.java
index 96ce806..4b21ec4 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexCallBinding.java
@@ -71,10 +71,12 @@ public class RexCallBinding extends SqlOperatorBinding {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   @Override public String getStringLiteralOperand(int ordinal) {
     return RexLiteral.stringValue(operands.get(ordinal));
   }
 
+  @SuppressWarnings("deprecation")
   @Override public int getIntLiteralOperand(int ordinal) {
     return RexLiteral.intValue(operands.get(ordinal));
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexExecutable.java b/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
index 365dd1d..03047f3 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
@@ -29,6 +29,8 @@ import org.codehaus.janino.Scanner;
 import java.io.IOException;
 import java.io.Serializable;
 import java.io.StringReader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -58,9 +60,12 @@ public class RexExecutable {
       cbe.cook(new Scanner(null, new StringReader(code)));
       Class c = cbe.getClazz();
       //noinspection unchecked
-      return (Function1<DataContext, Object[]>) c.newInstance();
+      final Constructor<Function1<DataContext, Object[]>> constructor =
+          c.getConstructor();
+      return constructor.newInstance();
     } catch (CompileException | IOException | InstantiationException
-        | IllegalAccessException e) {
+        | IllegalAccessException | InvocationTargetException
+        | NoSuchMethodException e) {
       throw new RuntimeException("While compiling " + reason, e);
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 45c53f3..634067c 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -724,12 +724,12 @@ public class SqlFunctions {
 
   public static int divide(int b0, BigDecimal b1) {
     return BigDecimal.valueOf(b0)
-        .divide(b1, BigDecimal.ROUND_HALF_DOWN).intValue();
+        .divide(b1, RoundingMode.HALF_DOWN).intValue();
   }
 
   public static long divide(long b0, BigDecimal b1) {
     return BigDecimal.valueOf(b0)
-        .divide(b1, BigDecimal.ROUND_HALF_DOWN).longValue();
+        .divide(b1, RoundingMode.HALF_DOWN).longValue();
   }
 
   // *
@@ -917,7 +917,7 @@ public class SqlFunctions {
   }
 
   public static BigDecimal floor(BigDecimal b0) {
-    return b0.setScale(0, BigDecimal.ROUND_FLOOR);
+    return b0.setScale(0, RoundingMode.FLOOR);
   }
 
   /** SQL <code>FLOOR</code> operator applied to byte values. */
@@ -978,7 +978,7 @@ public class SqlFunctions {
   }
 
   public static BigDecimal ceil(BigDecimal b0) {
-    return b0.setScale(0, BigDecimal.ROUND_CEILING);
+    return b0.setScale(0, RoundingMode.CEILING);
   }
 
   /** SQL <code>CEIL</code> operator applied to byte values. */
@@ -2178,7 +2178,7 @@ public class SqlFunctions {
         i += a.length;
       }
       if (withOrdinality) {
-        flatElements[i] = (E) new Integer(++ordinality); // 1-based
+        flatElements[i] = (E) Integer.valueOf(++ordinality); // 1-based
       }
       return FlatLists.ofComparable(list);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/schema/impl/TableFunctionImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/TableFunctionImpl.java b/core/src/main/java/org/apache/calcite/schema/impl/TableFunctionImpl.java
index 1ef3dfd..7ee55ab 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/TableFunctionImpl.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/TableFunctionImpl.java
@@ -35,6 +35,7 @@ import org.apache.calcite.schema.Table;
 import org.apache.calcite.schema.TableFunction;
 import org.apache.calcite.util.BuiltInMethod;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -143,7 +144,9 @@ public class TableFunctionImpl extends ReflectiveFunctionBase implements
     try {
       Object o = null;
       if (!Modifier.isStatic(method.getModifiers())) {
-        o = method.getDeclaringClass().newInstance();
+        final Constructor<?> constructor =
+            method.getDeclaringClass().getConstructor();
+        o = constructor.newInstance();
       }
       //noinspection unchecked
       final Object table = method.invoke(o, arguments.toArray());
@@ -152,10 +155,9 @@ public class TableFunctionImpl extends ReflectiveFunctionBase implements
       throw RESOURCE.illegalArgumentForTableFunctionCall(
           method.toString(),
           Arrays.toString(method.getParameterTypes()),
-          arguments.toString()
-      ).ex(e);
+          arguments.toString()).ex(e);
     } catch (IllegalAccessException | InvocationTargetException
-        | InstantiationException e) {
+        | InstantiationException | NoSuchMethodException e) {
       throw new RuntimeException(e);
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/schema/impl/TableMacroImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/TableMacroImpl.java b/core/src/main/java/org/apache/calcite/schema/impl/TableMacroImpl.java
index 609a16f..017a457 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/TableMacroImpl.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/TableMacroImpl.java
@@ -19,6 +19,7 @@ package org.apache.calcite.schema.impl;
 import org.apache.calcite.schema.TableMacro;
 import org.apache.calcite.schema.TranslatableTable;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -74,7 +75,9 @@ public class TableMacroImpl extends ReflectiveFunctionBase
     try {
       Object o = null;
       if (!Modifier.isStatic(method.getModifiers())) {
-        o = method.getDeclaringClass().newInstance();
+        final Constructor<?> constructor =
+            method.getDeclaringClass().getConstructor();
+        o = constructor.newInstance();
       }
       //noinspection unchecked
       return (TranslatableTable) method.invoke(o, arguments.toArray());
@@ -83,11 +86,8 @@ public class TableMacroImpl extends ReflectiveFunctionBase
           + Arrays.toString(method.getParameterTypes()) + " actual "
           + arguments,
           e);
-    } catch (IllegalAccessException e) {
-      throw new RuntimeException(e);
-    } catch (InvocationTargetException e) {
-      throw new RuntimeException(e);
-    } catch (InstantiationException e) {
+    } catch (IllegalAccessException | InvocationTargetException
+        | NoSuchMethodException | InstantiationException e) {
       throw new RuntimeException(e);
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
index 77e4b52..91b2ece 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
@@ -192,12 +192,14 @@ public class SqlCallBinding extends SqlOperatorBinding {
     return call.getOperandList().get(ordinal).getMonotonicity(scope);
   }
 
+  @SuppressWarnings("deprecation")
   @Override public String getStringLiteralOperand(int ordinal) {
     SqlNode node = call.operand(ordinal);
     final Object o = SqlLiteral.value(node);
     return o instanceof NlsString ? ((NlsString) o).getValue() : null;
   }
 
+  @SuppressWarnings("deprecation")
   @Override public int getIntLiteralOperand(int ordinal) {
     SqlNode node = call.operand(ordinal);
     final Object o = SqlLiteral.value(node);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
index 5661da3..3c0b527 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java
@@ -21,6 +21,7 @@ import org.apache.calcite.sql.type.OperandTypes;
 import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -112,8 +113,8 @@ public class SqlFilterOperator extends SqlBinaryOperator {
     RelDataType ret = aggCall.getOperator().inferReturnType(opBinding);
 
     // Copied from validateOperands
-    validator.setValidatedNodeType(call, ret);
-    validator.setValidatedNodeType(agg, ret);
+    ((SqlValidatorImpl) validator).setValidatedNodeType(call, ret);
+    ((SqlValidatorImpl) validator).setValidatedNodeType(agg, ret);
     return ret;
   }
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
index a31b8ba..bd2969c 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlIntervalLiteral.java
@@ -84,6 +84,7 @@ public class SqlIntervalLiteral extends SqlLiteral {
     writer.keyword(interval.intervalQualifier.toString());
   }
 
+  @SuppressWarnings("deprecation")
   public int signum() {
     return ((IntervalValue) value).signum();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
index 936d2c2..71a7e47 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.fun.SqlTrimFunction;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.OperandTypes;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 
 import com.google.common.base.Preconditions;
@@ -456,7 +457,7 @@ public class SqlJdbcFunctionCall extends SqlFunction {
 
     for (SqlNode operand : call.getOperandList()) {
       RelDataType nodeType = validator.deriveType(scope, operand);
-      validator.setValidatedNodeType(operand, nodeType);
+      ((SqlValidatorImpl) validator).setValidatedNodeType(operand, nodeType);
     }
     return validateOperands(validator, scope, call);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
index d558fce..7a65b10 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
@@ -28,6 +28,7 @@ import org.apache.calcite.sql.util.SqlBasicVisitor;
 import org.apache.calcite.sql.util.SqlVisitor;
 import org.apache.calcite.sql.validate.SqlMonotonicity;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.util.Litmus;
@@ -434,7 +435,7 @@ public abstract class SqlOperator {
 
     // Now infer the result type.
     RelDataType ret = inferReturnType(opBinding);
-    validator.setValidatedNodeType(call, ret);
+    ((SqlValidatorImpl) validator).setValidatedNodeType(call, ret);
     return ret;
   }
 
@@ -581,7 +582,7 @@ public abstract class SqlOperator {
       } else {
         nodeType = validator.deriveType(operandScope, operand);
       }
-      validator.setValidatedNodeType(operand, nodeType);
+      ((SqlValidatorImpl) validator).setValidatedNodeType(operand, nodeType);
       argTypeBuilder.add(nodeType);
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/SqlOverOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOverOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlOverOperator.java
index 0c9accc..23ebbc4 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlOverOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlOverOperator.java
@@ -23,6 +23,7 @@ import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.util.SqlBasicVisitor;
 import org.apache.calcite.sql.util.SqlVisitor;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -105,8 +106,8 @@ public class SqlOverOperator extends SqlBinaryOperator {
     RelDataType ret = aggCall.getOperator().inferReturnType(opBinding);
 
     // Copied from validateOperands
-    validator.setValidatedNodeType(call, ret);
-    validator.setValidatedNodeType(agg, ret);
+    ((SqlValidatorImpl) validator).setValidatedNodeType(call, ret);
+    ((SqlValidatorImpl) validator).setValidatedNodeType(agg, ret);
     return ret;
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
index 0b060a6..1e5e738 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
@@ -35,6 +35,7 @@ import org.apache.calcite.sql.type.InferTypes;
 import org.apache.calcite.sql.type.SqlOperandCountRanges;
 import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.util.Pair;
 
@@ -250,8 +251,10 @@ public class SqlCaseOperator extends SqlOperator {
     if (null == ret) {
       throw callBinding.newValidationError(RESOURCE.illegalMixingOfTypes());
     }
+    final SqlValidatorImpl validator =
+        (SqlValidatorImpl) callBinding.getValidator();
     for (SqlNode node : nullList) {
-      callBinding.getValidator().setValidatedNodeType(node, ret);
+      validator.setValidatedNodeType(node, ret);
     }
     return ret;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
index a502a01..8092806 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
@@ -37,6 +37,7 @@ import org.apache.calcite.sql.type.SqlOperandCountRanges;
 import org.apache.calcite.sql.type.SqlTypeFamily;
 import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.sql.validate.SqlMonotonicity;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.SetMultimap;
@@ -101,9 +102,9 @@ public class SqlCastFunction extends SqlFunction {
       if (((operand0 instanceof SqlLiteral)
           && (((SqlLiteral) operand0).getValue() == null))
           || (operand0 instanceof SqlDynamicParam)) {
-        callBinding.getValidator().setValidatedNodeType(
-            operand0,
-            ret);
+        final SqlValidatorImpl validator =
+            (SqlValidatorImpl) callBinding.getValidator();
+        validator.setValidatedNodeType(operand0, ret);
       }
     }
     return ret;

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlCountAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCountAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlCountAggFunction.java
index dac4b21..ebfa084 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCountAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCountAggFunction.java
@@ -65,12 +65,14 @@ public class SqlCountAggFunction extends SqlAggFunction {
     return SqlSyntax.FUNCTION_STAR;
   }
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(
         typeFactory.createTypeWithNullability(
             typeFactory.createSqlType(SqlTypeName.ANY), true));
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return typeFactory.createSqlType(SqlTypeName.BIGINT);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java
index edc6499..72dccd1 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java
@@ -60,12 +60,14 @@ public class SqlFirstLastValueAggFunction extends SqlAggFunction {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(
         typeFactory.createTypeWithNullability(
             typeFactory.createSqlType(SqlTypeName.ANY), true));
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return typeFactory.createTypeWithNullability(
         typeFactory.createSqlType(SqlTypeName.ANY), true);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlHistogramAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlHistogramAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlHistogramAggFunction.java
index 1ba3821..a3fb5f2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlHistogramAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlHistogramAggFunction.java
@@ -59,6 +59,7 @@ public class SqlHistogramAggFunction extends SqlAggFunction {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(type);
   }
@@ -68,6 +69,7 @@ public class SqlHistogramAggFunction extends SqlAggFunction {
     return type;
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return type;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
index 2b80173..4639fbc 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
@@ -33,6 +33,7 @@ import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
 import org.apache.calcite.util.Litmus;
 
@@ -126,9 +127,7 @@ public class SqlInOperator extends SqlBinaryOperator {
       }
 
       // Record the RHS type for use by SqlToRelConverter.
-      validator.setValidatedNodeType(
-          nodeList,
-          rightType);
+      ((SqlValidatorImpl) validator).setValidatedNodeType(nodeList, rightType);
     } else {
       // Handle the 'IN (query)' form.
       rightType = validator.deriveType(scope, right);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
index 54af0f8..438c7f1 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java
@@ -104,6 +104,7 @@ public class SqlMinMaxAggFunction extends SqlAggFunction {
     return minMaxKind;
   }
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     switch (minMaxKind) {
     case MINMAX_PRIMITIVE:
@@ -116,6 +117,7 @@ public class SqlMinMaxAggFunction extends SqlAggFunction {
     }
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     switch (minMaxKind) {
     case MINMAX_PRIMITIVE:

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
index c0c977c..6e745df 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlSingleValueAggFunction.java
@@ -57,10 +57,12 @@ public class SqlSingleValueAggFunction extends SqlAggFunction {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(type);
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return type;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlSumAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlSumAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlSumAggFunction.java
index 5bf124d..eac5731 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlSumAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlSumAggFunction.java
@@ -60,6 +60,7 @@ public class SqlSumAggFunction extends SqlAggFunction {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(type);
   }
@@ -69,6 +70,7 @@ public class SqlSumAggFunction extends SqlAggFunction {
     return type;
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return type;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/fun/SqlSumEmptyIsZeroAggFunction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlSumEmptyIsZeroAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlSumEmptyIsZeroAggFunction.java
index 6f18c08..daa66e2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlSumEmptyIsZeroAggFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlSumEmptyIsZeroAggFunction.java
@@ -53,12 +53,14 @@ public class SqlSumEmptyIsZeroAggFunction extends SqlAggFunction {
 
   //~ Methods ----------------------------------------------------------------
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
     return ImmutableList.of(
         typeFactory.createTypeWithNullability(
             typeFactory.createSqlType(SqlTypeName.ANY), true));
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return typeFactory.createTypeWithNullability(
         typeFactory.createSqlType(SqlTypeName.ANY), true);

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
index d0caa7c..687f26e 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java
@@ -159,6 +159,7 @@ abstract class AbstractNamespace implements SqlValidatorNamespace {
     return SqlMonotonicity.NOT_MONOTONIC;
   }
 
+  @SuppressWarnings("deprecation")
   public void makeNullable() {
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java
index 0aba477..c5754e8 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java
@@ -97,6 +97,7 @@ public abstract class DelegatingNamespace implements SqlValidatorNamespace {
     return namespace.getMonotonicity(columnName);
   }
 
+  @SuppressWarnings("deprecation")
   public void makeNullable() {
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/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 8b004cd..02823be 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
@@ -173,6 +173,7 @@ public abstract class DelegatingScope implements SqlValidatorScope {
     parent.findAliases(result);
   }
 
+  @SuppressWarnings("deprecation")
   public Pair<String, SqlValidatorNamespace>
   findQualifyingTableName(String columnName, SqlNode ctx) {
     //noinspection deprecation
@@ -197,6 +198,7 @@ public abstract class DelegatingScope implements SqlValidatorScope {
     return parent.nullifyType(node, type);
   }
 
+  @SuppressWarnings("deprecation")
   public SqlValidatorNamespace getTableNamespace(List<String> names) {
     return parent.getTableNamespace(names);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql/validate/EmptyScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/EmptyScope.java b/core/src/main/java/org/apache/calcite/sql/validate/EmptyScope.java
index b9a38cf..0dc9131 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/EmptyScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/EmptyScope.java
@@ -80,6 +80,7 @@ class EmptyScope implements SqlValidatorScope {
       boolean deep, Resolved resolved) {
   }
 
+  @SuppressWarnings("deprecation")
   public SqlValidatorNamespace getTableNamespace(List<String> names) {
     SqlValidatorTable table = validator.catalogReader.getTable(names);
     return table != null
@@ -195,6 +196,7 @@ class EmptyScope implements SqlValidatorScope {
     // valid
   }
 
+  @SuppressWarnings("deprecation")
   public Pair<String, SqlValidatorNamespace>
   findQualifyingTableName(String columnName, SqlNode ctx) {
     throw validator.newValidationError(ctx,

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/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 7228f63..e0f3427 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
@@ -127,6 +127,7 @@ public abstract class ListScope extends DelegatingScope {
     parent.findAliases(result);
   }
 
+  @SuppressWarnings("deprecation")
   @Override public Pair<String, SqlValidatorNamespace>
   findQualifyingTableName(final String columnName, SqlNode ctx) {
     final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher();
@@ -134,7 +135,6 @@ public abstract class ListScope extends DelegatingScope {
         findQualifyingTables(columnName, nameMatcher);
     switch (map.size()) {
     case 0:
-      //noinspection deprecation
       return parent.findQualifyingTableName(columnName, ctx);
     case 1:
       final Map.Entry<String, ScopeChild> entry =

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/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 a5592f3..f7b19f0 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
@@ -53,6 +53,7 @@ public class SqlUserDefinedAggFunction extends SqlAggFunction {
     this.function = function;
   }
 
+  @SuppressWarnings("deprecation")
   public List<RelDataType> getParameterTypes(
       final RelDataTypeFactory typeFactory) {
     return Lists.transform(function.getParameters(),
@@ -63,6 +64,7 @@ public class SqlUserDefinedAggFunction extends SqlAggFunction {
         });
   }
 
+  @SuppressWarnings("deprecation")
   public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
     return function.getReturnType(typeFactory);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/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 f0d0ce9..0d0a608 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
@@ -427,7 +427,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
 
     inferUnknownTypes(targetType, scope, expanded);
     final RelDataType type = deriveType(selectScope, expanded);
-    setValidatedNodeTypeImpl(expanded, type);
+    setValidatedNodeType(expanded, type);
     types.add(Pair.of(alias, type));
     return false;
   }
@@ -1481,17 +1481,17 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     return null;
   }
 
-  public void setValidatedNodeType(
-      SqlNode node,
-      RelDataType type) {
-    setValidatedNodeTypeImpl(node, type);
-  }
-
-  public void removeValidatedNodeType(SqlNode node) {
-    nodeToTypeMap.remove(node);
-  }
-
-  void setValidatedNodeTypeImpl(SqlNode node, RelDataType type) {
+  /**
+   * Saves the type of a {@link SqlNode}, now that it has been validated.
+   *
+   * <p>Unlike the base class method, this method is not deprecated.
+   * It is available from within Calcite, but is not part of the public API.
+   *
+   * @param node A SQL parse tree node, never null
+   * @param type Its type; must not be null
+   */
+  @SuppressWarnings("deprecation")
+  public final void setValidatedNodeType(SqlNode node, RelDataType type) {
     Preconditions.checkNotNull(type);
     Preconditions.checkNotNull(node);
     if (type.equals(unknownType)) {
@@ -1502,6 +1502,10 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     nodeToTypeMap.put(node, type);
   }
 
+  public void removeValidatedNodeType(SqlNode node) {
+    nodeToTypeMap.remove(node);
+  }
+
   public RelDataType deriveType(
       SqlValidatorScope scope,
       SqlNode expr) {
@@ -1521,7 +1525,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     Preconditions.checkArgument(
         type != null,
         "SqlValidator.deriveTypeInternal returned null");
-    setValidatedNodeTypeImpl(expr, type);
+    setValidatedNodeType(expr, type);
     return type;
   }
 
@@ -1648,7 +1652,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
                 inferredType.getCharset(),
                 inferredType.getCollation());
       }
-      setValidatedNodeTypeImpl(node, newInferredType);
+      setValidatedNodeType(node, newInferredType);
     } else if (node instanceof SqlNodeList) {
       SqlNodeList nodeList = (SqlNodeList) node;
       if (inferredType.isStruct()) {
@@ -1689,9 +1693,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
             scope,
             caseCall.getElseOperand());
       } else {
-        setValidatedNodeTypeImpl(
-            caseCall.getElseOperand(),
-            returnType);
+        setValidatedNodeType(caseCall.getElseOperand(), returnType);
       }
     } else if (node instanceof SqlCall) {
       final SqlCall call = (SqlCall) node;
@@ -1790,19 +1792,14 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
    *                      this namespace)
    * @param alias         Alias by which parent will refer to this namespace
    * @param ns            Namespace
-   * @param forceNullable Whether to force the type of namespace to be
+   * @param forceNullable Whether to force the type of namespace to be nullable
    */
   protected void registerNamespace(
       SqlValidatorScope usingScope,
       String alias,
       SqlValidatorNamespace ns,
       boolean forceNullable) {
-    if (forceNullable) {
-      ns.makeNullable();
-    }
-    namespaces.put(
-        ns.getNode(),
-        ns);
+    namespaces.put(ns.getNode(), ns);
     if (usingScope != null) {
       usingScope.addChild(ns, alias, forceNullable);
     }
@@ -2609,6 +2606,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     return aggFinder.findAgg(select.getSelectList());
   }
 
+  @SuppressWarnings("deprecation")
   public boolean isAggregate(SqlNode selectNode) {
     return aggFinder.findAgg(selectNode) != null;
   }
@@ -3420,7 +3418,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       final SqlValidatorScope scope = getOrderScope(select);
       inferUnknownTypes(unknownType, scope, newSqlNode);
       final RelDataType type = deriveType(scope, newSqlNode);
-      setValidatedNodeTypeImpl(newSqlNode, type);
+      setValidatedNodeType(newSqlNode, type);
     }
     return newSqlNode;
   }
@@ -3498,7 +3496,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
         break;
       }
       final RelDataType type = deriveType(groupScope, groupItem);
-      setValidatedNodeTypeImpl(groupItem, type);
+      setValidatedNodeType(groupItem, type);
     }
   }
 
@@ -3679,7 +3677,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
 
     final SelectScope scope = (SelectScope) getWhereScope(parentSelect);
     final RelDataType type = deriveType(scope, selectItem);
-    setValidatedNodeTypeImpl(selectItem, type);
+    setValidatedNodeType(selectItem, type);
 
     // we do not want to pass on the RelRecordType returned
     // by the sub query.  Just the type of the single expression

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 9ae5436..b6df686 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -3402,8 +3402,7 @@ public class SqlToRelConverter {
               }, null, false);
         }
         RelDataType multisetType = validator.getValidatedNodeType(call);
-        validator.setValidatedNodeType(
-            list,
+        ((SqlValidatorImpl) validator).setValidatedNodeType(list,
             multisetType.getComponentType());
         input = convertQueryOrInList(usedBb, list, null);
         break;

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java
index da28296..f1c2e1e 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java
@@ -78,6 +78,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -818,7 +819,7 @@ public class StandardConvertletTable extends ReflectiveConvertletTable {
         && val.signum() == 1) {
       try {
         final BigDecimal reciprocal =
-            BigDecimal.ONE.divide(val, BigDecimal.ROUND_UNNECESSARY);
+            BigDecimal.ONE.divide(val, RoundingMode.UNNECESSARY);
         return rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, res,
             rexBuilder.makeExactLiteral(reciprocal));
       } catch (ArithmeticException e) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/main/java/org/apache/calcite/util/NumberUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NumberUtil.java b/core/src/main/java/org/apache/calcite/util/NumberUtil.java
index 7e9d532..a33b416 100644
--- a/core/src/main/java/org/apache/calcite/util/NumberUtil.java
+++ b/core/src/main/java/org/apache/calcite/util/NumberUtil.java
@@ -18,6 +18,7 @@ package org.apache.calcite.util;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 
@@ -81,7 +82,7 @@ public class NumberUtil {
 
   public static BigDecimal rescaleBigDecimal(BigDecimal bd, int scale) {
     if (bd != null) {
-      bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
+      bd = bd.setScale(scale, RoundingMode.HALF_UP);
     }
     return bd;
   }


[8/9] calcite git commit: [CALCITE-1602] Remove uses of deprecated APIs

Posted by jh...@apache.org.
http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
index 6c53bc7..eebb79c 100644
--- a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
+++ b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.java
@@ -28,6 +28,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.lang.reflect.Constructor;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -1197,14 +1198,15 @@ public class ConcurrentTestCommandScript
 
     private void plugin(String pluginName) throws IOException {
       try {
-        Class<?> pluginClass = Class.forName(pluginName);
-        ConcurrentTestPlugin plugin =
-            (ConcurrentTestPlugin) pluginClass.newInstance();
+        @SuppressWarnings("unchecked")
+        Class<ConcurrentTestPlugin> pluginClass =
+            (Class<ConcurrentTestPlugin>) Class.forName(pluginName);
+        final Constructor<ConcurrentTestPlugin> constructor =
+            pluginClass.getConstructor();
+        final ConcurrentTestPlugin plugin = constructor.newInstance();
         plugins.add(plugin);
-        addExtraCommands(
-            plugin.getSupportedThreadCommands(), THREAD_STATE);
-        addExtraCommands(
-            plugin.getSupportedThreadCommands(), REPEAT_STATE);
+        addExtraCommands(plugin.getSupportedThreadCommands(), THREAD_STATE);
+        addExtraCommands(plugin.getSupportedThreadCommands(), REPEAT_STATE);
         for (String commandName : plugin.getSupportedThreadCommands()) {
           pluginForCommand.put(commandName, plugin);
         }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
index 01c8f94..0efd0e4 100644
--- a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
@@ -1038,10 +1038,12 @@ public class PlannerTest {
           OperandTypes.ANY, SqlFunctionCategory.NUMERIC, false, false);
     }
 
+    @SuppressWarnings("deprecation")
     public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
       return ImmutableList.of(typeFactory.createSqlType(SqlTypeName.ANY));
     }
 
+    @SuppressWarnings("deprecation")
     public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
       return typeFactory.createSqlType(SqlTypeName.BIGINT);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/test/java/org/apache/calcite/util/ReflectVisitorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/ReflectVisitorTest.java b/core/src/test/java/org/apache/calcite/util/ReflectVisitorTest.java
index 877f446..b04d63f 100644
--- a/core/src/test/java/org/apache/calcite/util/ReflectVisitorTest.java
+++ b/core/src/test/java/org/apache/calcite/util/ReflectVisitorTest.java
@@ -45,7 +45,7 @@ public class ReflectVisitorTest {
     Number result;
 
     // verify that negater is capable of handling integers
-    result = negater.negate(new Integer(5));
+    result = negater.negate(5);
     assertEquals(
         -5,
         result.intValue());
@@ -60,7 +60,7 @@ public class ReflectVisitorTest {
 
     // verify that negater is capable of handling integers,
     // and that result comes back with same type
-    result = negater.negate(new Integer(5));
+    result = negater.negate(5);
     assertEquals(
         -5,
         result.intValue());
@@ -69,9 +69,9 @@ public class ReflectVisitorTest {
     // verify that negater is capable of handling longs;
     // even though it doesn't provide an explicit implementation,
     // it should inherit the one from CarelessNumberNegater
-    result = negater.negate(new Long(5));
+    result = negater.negate(5L);
     assertEquals(
-        -5,
+        -5L,
         result.longValue());
   }
 
@@ -84,14 +84,14 @@ public class ReflectVisitorTest {
 
     // verify that negater is capable of handling shorts,
     // and that result comes back with same type
-    result = negater.negate(new Short((short) 5));
+    result = negater.negate((short) 5);
     assertEquals(
         -5,
         result.shortValue());
     assertTrue(result instanceof Short);
 
     // verify that negater is NOT capable of handling integers
-    result = negater.negate(new Integer(5));
+    result = negater.negate(5);
     assertEquals(null, result);
   }
 
@@ -106,7 +106,7 @@ public class ReflectVisitorTest {
       result = negater.negate(new AmbiguousNumber());
     } catch (IllegalArgumentException ex) {
       // expected
-      assertTrue(ex.getMessage().indexOf("ambiguity") > -1);
+      assertTrue(ex.getMessage().contains("ambiguity"));
       return;
     }
     fail("Expected failure due to ambiguity");
@@ -207,7 +207,7 @@ public class ReflectVisitorTest {
    */
   public class CarelessNumberNegater extends NumberNegater {
     public void visit(Number n) {
-      result = new Double(-n.doubleValue());
+      result = -n.doubleValue();
     }
   }
 
@@ -219,11 +219,13 @@ public class ReflectVisitorTest {
    */
   public class CarefulNumberNegater extends CarelessNumberNegater {
     public void visit(Integer i) {
-      result = new Integer(-i.intValue());
+      result = -i;
+      assert result instanceof Integer;
     }
 
     public void visit(Short s) {
-      result = new Short((short) (-s.shortValue()));
+      result = -s;
+      assert result instanceof Short;
     }
 
     // ... imagine implementations for other Number subclasses here ...
@@ -237,11 +239,12 @@ public class ReflectVisitorTest {
    */
   public class CluelessNumberNegater extends NumberNegater {
     public void visit(Object obj) {
-      result = new Integer(42);
+      result = 42;
     }
 
     public void visit(Short s) {
-      result = new Short((short) (-s.shortValue()));
+      result = (short) -s;
+      assert result instanceof Short;
     }
   }
 
@@ -266,7 +269,8 @@ public class ReflectVisitorTest {
     }
 
     public void visit(AmbiguousNumber n) {
-      result = new Double(-n.doubleValue());
+      result = -n.doubleValue();
+      assert result instanceof Double;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/core/src/test/java/org/apache/calcite/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 42f06c6..8afc09b 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -371,24 +371,24 @@ public class UtilTest {
    */
   @Test public void testCastingList() {
     final List<Number> numberList = new ArrayList<>();
-    numberList.add(new Integer(1));
+    numberList.add(1);
     numberList.add(null);
-    numberList.add(new Integer(2));
+    numberList.add(2);
     List<Integer> integerList = Util.cast(numberList, Integer.class);
     assertEquals(3, integerList.size());
-    assertEquals(new Integer(2), integerList.get(2));
+    assertEquals(Integer.valueOf(2), integerList.get(2));
 
     // Nulls are OK.
     assertNull(integerList.get(1));
 
     // Can update the underlying list.
     integerList.set(1, 345);
-    assertEquals(new Integer(345), integerList.get(1));
+    assertEquals(Integer.valueOf(345), integerList.get(1));
     integerList.set(1, null);
     assertNull(integerList.get(1));
 
     // Can add a member of the wrong type to the underlying list.
-    numberList.add(new Double(3.1415));
+    numberList.add(3.1415D);
     assertEquals(4, integerList.size());
 
     // Access a member which is of the wrong type.
@@ -1470,11 +1470,12 @@ public class UtilTest {
   }
 
   public void checkHash(double v) {
-    assertThat(new Double(v).hashCode(), is(Utilities.hashCode(v)));
+    assertThat(Double.valueOf(v).hashCode(), is(Utilities.hashCode(v)));
     final long long_ = (long) v;
-    assertThat(new Long(long_).hashCode(), is(Utilities.hashCode(long_)));
+    assertThat(Long.valueOf(long_).hashCode(), is(Utilities.hashCode(long_)));
     final float float_ = (float) v;
-    assertThat(new Float(float_).hashCode(), is(Utilities.hashCode(float_)));
+    assertThat(Float.valueOf(float_).hashCode(),
+        is(Utilities.hashCode(float_)));
     final boolean boolean_ = v != 0;
     assertThat(Boolean.valueOf(boolean_).hashCode(),
         is(Utilities.hashCode(boolean_)));

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
index 07740c2..788866c 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
@@ -410,6 +410,7 @@ class DruidConnectionImpl implements DruidConnection {
             enumerator.done.set(true);
           }
 
+          @SuppressWarnings("deprecation")
           public void setSourceEnumerable(Enumerable<Row> enumerable)
               throws InterruptedException {
             for (Row row : enumerable) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java
index 2e68156..3fc0fd2 100644
--- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java
+++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java
@@ -39,9 +39,6 @@ import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
-import org.apache.calcite.util.trace.CalciteTrace;
-
-import org.slf4j.Logger;
 
 import java.util.AbstractList;
 import java.util.ArrayList;
@@ -53,8 +50,6 @@ import java.util.List;
  * calling convention.
  */
 class ElasticsearchRules {
-  protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();
-
   static final RelOptRule[] RULES = {
     ElasticsearchSortRule.INSTANCE,
     ElasticsearchFilterRule.INSTANCE,
@@ -84,16 +79,17 @@ class ElasticsearchRules {
 
   static List<String> elasticsearchFieldNames(final RelDataType rowType) {
     return SqlValidatorUtil.uniquify(
-      new AbstractList<String>() {
-        @Override public String get(int index) {
-          final String name = rowType.getFieldList().get(index).getName();
-          return name.startsWith("$") ? "_" + name.substring(2) : name;
-        }
-
-        @Override public int size() {
-          return rowType.getFieldCount();
-        }
-      });
+        new AbstractList<String>() {
+          @Override public String get(int index) {
+            final String name = rowType.getFieldList().get(index).getName();
+            return name.startsWith("$") ? "_" + name.substring(2) : name;
+          }
+
+          @Override public int size() {
+            return rowType.getFieldCount();
+          }
+        },
+        SqlValidatorUtil.EXPR_SUGGESTER, true);
   }
 
   static String quote(String s) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
index 9f26d87..d178a44 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
@@ -251,8 +251,8 @@ public abstract class Types {
       return className(clazz.getComponentType()) + "[]";
     }
     String className = clazz.getName();
-    if (clazz.getPackage() == Package.getPackage("java.lang")
-        && !clazz.isPrimitive()) {
+    if (!clazz.isPrimitive()
+        && clazz.getPackage().getName().equals("java.lang")) {
       return className.substring("java.lang.".length());
     }
     return className.replace('$', '.');

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
index 0d59b63..f19bdd0 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
@@ -61,6 +61,8 @@ import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
@@ -733,9 +735,10 @@ public class Linq4jTest {
 
   @SuppressWarnings("UnnecessaryBoxing")
   @Test public void testIdentityEqualityComparer() {
-    final Integer one = new Integer(1);
-    final Integer one2 = new Integer(1);
-    final Integer two = new Integer(2);
+    final Integer one = 1000;
+    final Integer one2 = Integer.valueOf(one.toString());
+    assertThat(one, not(sameInstance(one2)));
+    final Integer two = 2;
     final EqualityComparer<Integer> idComparer = Functions.identityComparer();
     assertTrue(idComparer.equal(one, one));
     assertTrue(idComparer.equal(one, one2));

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 853698e..6f683ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -493,6 +493,7 @@ limitations under the License.
         <configuration>
           <source>1.7</source>
           <target>1.7</target>
+          <compilerArgument>-Xlint:deprecation</compilerArgument>
         </configuration>
       </plugin>
       <plugin>

http://git-wip-us.apache.org/repos/asf/calcite/blob/5181563f/spark/src/main/java/org/apache/calcite/adapter/spark/SparkHandlerImpl.java
----------------------------------------------------------------------
diff --git a/spark/src/main/java/org/apache/calcite/adapter/spark/SparkHandlerImpl.java b/spark/src/main/java/org/apache/calcite/adapter/spark/SparkHandlerImpl.java
index 5086dad..b67f096 100644
--- a/spark/src/main/java/org/apache/calcite/adapter/spark/SparkHandlerImpl.java
+++ b/spark/src/main/java/org/apache/calcite/adapter/spark/SparkHandlerImpl.java
@@ -31,6 +31,8 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Calendar;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -124,16 +126,14 @@ public class SparkHandlerImpl implements CalcitePrepare.SparkHandler {
       compiler.getArgs().setSource(source, file.getAbsolutePath());
       compiler.getArgs().setFullClassName(className);
       compiler.compile();
-      Class<?> clazz = Class.forName(className);
-      Object o = clazz.newInstance();
-      return (ArrayBindable) o;
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    } catch (ClassNotFoundException e) {
-      throw new RuntimeException(e);
-    } catch (InstantiationException e) {
-      throw new RuntimeException(e);
-    } catch (IllegalAccessException e) {
+      @SuppressWarnings("unchecked")
+      final Class<ArrayBindable> clazz =
+          (Class<ArrayBindable>) Class.forName(className);
+      final Constructor<ArrayBindable> constructor = clazz.getConstructor();
+      return constructor.newInstance();
+    } catch (IOException | ClassNotFoundException | InstantiationException
+        | IllegalAccessException | NoSuchMethodException
+        | InvocationTargetException e) {
       throw new RuntimeException(e);
     }
   }