calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [8/9] calcite git commit: [CALCITE-1602] Remove uses of deprecated APIs
Date Wed, 25 Jan 2017 21:25:22 GMT
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);
     }
   }


Mime
View raw message