You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2018/04/22 02:11:05 UTC

[3/3] calcite git commit: [CALCITE-2164] Fix alerts raised by lgtm.com (Malcolm Taylor)

[CALCITE-2164] Fix alerts raised by lgtm.com (Malcolm Taylor)

Close apache/calcite#621


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

Branch: refs/heads/master
Commit: 09be7e74a6a4d1b1c4f640c8e69b5ebdd467d811
Parents: b1e3c82
Author: Malcolm Taylor <ma...@semmle.com>
Authored: Sun Feb 4 20:42:21 2018 +0000
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Apr 21 09:59:24 2018 -0700

----------------------------------------------------------------------
 .../adapter/enumerable/RexToLixTranslator.java  |  3 +-
 .../rel/metadata/RelMdDistinctRowCount.java     |  6 +-
 .../rel/metadata/RelMdPopulationSize.java       |  2 +-
 .../apache/calcite/rel/metadata/RelMdSize.java  |  4 +-
 .../calcite/rel/rules/JoinToMultiJoinRule.java  |  2 +
 .../rel/rules/LoptSemiJoinOptimizer.java        |  2 +-
 .../calcite/rel/rules/ReduceDecimalsRule.java   |  3 +-
 .../calcite/sql/validate/SqlValidatorUtil.java  |  2 +-
 .../calcite/sql2rel/SqlToRelConverter.java      |  1 -
 .../org/apache/calcite/util/StackWriter.java    |  2 +-
 .../org/apache/calcite/linq4j/LookupImpl.java   |  3 +-
 .../apache/calcite/linq4j/test/Linq4jSuite.java |  2 +-
 .../calcite/linq4j/test/LookupImplTest.java     | 65 ++++++++++++++++++++
 13 files changed, 80 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/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 805216b..e1c53b8 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
@@ -541,8 +541,7 @@ public class RexToLixTranslator {
           }
           // If this is a widening cast, no need to pad.
           if (SqlTypeUtil.comparePrecision(sourcePrecision, targetPrecision)
-              >= 0
-              && targetPrecision != RelDataType.PRECISION_NOT_SPECIFIED) {
+              >= 0) {
             pad = false;
           }
           // fall through

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
index bf3fc3a..6959a20 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
@@ -82,7 +82,7 @@ public class RelMdDistinctRowCount
 
   public Double getDistinctRowCount(Union rel, RelMetadataQuery mq,
       ImmutableBitSet groupKey, RexNode predicate) {
-    Double rowCount = 0.0;
+    double rowCount = 0.0;
     int[] adjustments = new int[rel.getRowType().getFieldCount()];
     RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
     for (RelNode input : rel.getInputs()) {
@@ -215,10 +215,10 @@ public class RelMdDistinctRowCount
         return 1D;
       }
     }
-    Double selectivity = RelMdUtil.guessSelectivity(predicate);
+    double selectivity = RelMdUtil.guessSelectivity(predicate);
 
     // assume half the rows are duplicates
-    Double nRows = rel.estimateRowCount(mq) / 2;
+    double nRows = rel.estimateRowCount(mq) / 2;
     return RelMdUtil.numDistinctVals(nRows, nRows * selectivity);
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
index 67b3fe9..a0d17bb 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
@@ -69,7 +69,7 @@ public class RelMdPopulationSize
 
   public Double getPopulationSize(Union rel, RelMetadataQuery mq,
       ImmutableBitSet groupKey) {
-    Double population = 0.0;
+    double population = 0.0;
     for (RelNode input : rel.getInputs()) {
       Double subPop = mq.getPopulationSize(input, groupKey);
       if (subPop == null) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSize.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSize.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSize.java
index 085fd7c..63c27b1 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSize.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSize.java
@@ -88,7 +88,7 @@ public class RelMdSize implements MetadataHandler<BuiltInMetadata.Size> {
     if (averageColumnSizes == null) {
       return null;
     }
-    Double d = 0d;
+    double d = 0d;
     final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
     for (Pair<Double, RelDataTypeField> p
         : Pair.zip(averageColumnSizes, fields)) {
@@ -312,7 +312,7 @@ public class RelMdSize implements MetadataHandler<BuiltInMetadata.Size> {
       // Even in large (say VARCHAR(2000)) columns most strings are small
       return Math.min((double) type.getPrecision() * BYTES_PER_CHARACTER, 100d);
     case ROW:
-      Double average = 0.0;
+      double average = 0.0;
       for (RelDataTypeField field : type.getFieldList()) {
         average += averageTypeValueSize(field.getType());
       }

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
index ecccad1..90a98bf 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/JoinToMultiJoinRule.java
@@ -348,6 +348,8 @@ public class JoinToMultiJoinRule extends RelOptRule {
     if (adjustmentAmount == 0) {
       destJoinSpecs.addAll(srcJoinSpecs);
     } else {
+      assert srcFields != null;
+      assert destFields != null;
       int nFields = srcFields.size();
       int[] adjustments = new int[nFields];
       for (int idx = 0; idx < nFields; idx++) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
index 17a158e..05196d4 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
@@ -671,7 +671,7 @@ public class LoptSemiJoinOptimizer {
       return 0;
     }
 
-    Double dimRows = dimCost.getRows();
+    double dimRows = dimCost.getRows();
     if (dimRows < 1.0) {
       dimRows = 1.0;
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/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 2d27fc5..7af2264 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
@@ -801,8 +801,7 @@ public class ReduceDecimalsRule extends RelOptRule {
         if (fromScale <= toScale) {
           scaled = ensureScale(value, fromScale, toScale);
         } else {
-          if ((toDigits == fromDigits)
-              && (toScale < fromScale)) {
+          if (toDigits == fromDigits) {
             // rounding away from zero may cause an overflow
             // for example: cast(9.99 as decimal(2,1))
             checkOverflow = true;

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
index d4c082d..f38825d 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java
@@ -512,7 +512,7 @@ public class SqlValidatorUtil {
    *
    * @param typeFactory     Type factory
    * @param leftType        Type of left input to join
-   * @param rightType       Type of right input to join
+   * @param rightType       Type of right input to join, or null for semi-join
    * @param fieldNameList   If not null, overrides the original names of the
    *                        fields
    * @param systemFieldList List of system fields that will be prefixed to

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/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 4a96172..466919f 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -4771,7 +4771,6 @@ public class SqlToRelConverter {
     /** Expressions to be evaluated as rows are being placed into the
      * aggregate's hash table. This is when group functions such as TUMBLE
      * cause rows to be expanded. */
-    private final List<RexNode> midExprs = new ArrayList<>();
 
     private final List<AggregateCall> aggCalls = new ArrayList<>();
     private final Map<SqlNode, RexNode> aggMapping = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/core/src/main/java/org/apache/calcite/util/StackWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/StackWriter.java b/core/src/main/java/org/apache/calcite/util/StackWriter.java
index ccf73cc..14ce5ef 100644
--- a/core/src/main/java/org/apache/calcite/util/StackWriter.java
+++ b/core/src/main/java/org/apache/calcite/util/StackWriter.java
@@ -154,7 +154,7 @@ public class StackWriter extends FilterWriter {
 
   private void popQuote(Character quoteChar) throws IOException {
     final Character pop = quoteStack.pop();
-    assert pop == quoteChar;
+    assert pop.equals(quoteChar);
     writeQuote(quoteChar);
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/linq4j/src/main/java/org/apache/calcite/linq4j/LookupImpl.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/LookupImpl.java b/linq4j/src/main/java/org/apache/calcite/linq4j/LookupImpl.java
index b5bf65c..0451d10 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/LookupImpl.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/LookupImpl.java
@@ -88,8 +88,7 @@ class LookupImpl<K, V> extends AbstractEnumerable<Grouping<K, V>>
   public boolean containsValue(Object value) {
     @SuppressWarnings("unchecked")
     List<V> list = (List<V>) value;
-    Enumerable<V> enumerable = Linq4j.asEnumerable(list);
-    return map.containsValue(enumerable);
+    return map.containsValue(list);
   }
 
   public Enumerable<V> get(Object key) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
index 17d8b46..8a0cbb9 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
@@ -22,7 +22,6 @@ import org.apache.calcite.linq4j.tree.TypeTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
-
 /**
  * Suite of all Linq4j tests.
  */
@@ -33,6 +32,7 @@ import org.junit.runners.Suite;
     ExpressionTest.class,
     OptimizerTest.class,
     InlinerTest.class,
+    LookupImplTest.class,
     DeterministicTest.class,
     BlockBuilderTest.class,
     FunctionTest.class,

http://git-wip-us.apache.org/repos/asf/calcite/blob/09be7e74/linq4j/src/test/java/org/apache/calcite/linq4j/test/LookupImplTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/LookupImplTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/LookupImplTest.java
new file mode 100644
index 0000000..9b11464
--- /dev/null
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/LookupImplTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.linq4j.test;
+
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.Lookup;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for LookupImpl.java
+ *
+ */
+public class LookupImplTest extends TestCase {
+
+  private Lookup<Integer, String> impl;
+
+  @Before
+  public void setUp() {
+    impl = Linq4j.asEnumerable(Linq4jTest.emps).toLookup(
+      Linq4jTest.EMP_DEPTNO_SELECTOR,
+      Linq4jTest.EMP_NAME_SELECTOR);
+  }
+
+  @Test
+  public void testPut() {
+    int initSize = impl.size();
+    impl.put(99, Linq4j.asEnumerable(new String[]{"A", "B"}));
+    assertTrue(impl.containsKey(99));
+    assertTrue(impl.size() == initSize + 1);
+  }
+
+  @Test
+  public void testContainsValue() {
+    List<String> list = new ArrayList<>();
+    list.add("C");
+    list.add("D");
+    List<String> list2 = new ArrayList<>(list);
+    impl.put(100, Linq4j.asEnumerable(list));
+    assertTrue(impl.containsValue(list));
+    assertTrue(impl.containsValue(list2));
+  }
+}
+
+// End LookupImplTest.java