You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vl...@apache.org on 2020/09/05 17:16:35 UTC

[calcite] branch master updated (86b42f3 -> eb4011b)

This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


    from 86b42f3  [CALCITE-4217] Unlock RelCrossType#getFieldCount()
     new ff169fb  [CALCITE-4228] FlatLists.Flat6List#append should not throw NPE if there are null elements in the list
     new 9422fd4  [CALCITE-4226] Add Mappings#asListNonNull as a null-safe alternative for Mappings#asList
     new ad164ed  [CALCITE-4227] ImmutableIntList#toArray(Integer[]) should support arguments larger than the collection itself
     new fb2a02f  Remove ArrayList allocation from Mappings#bijection, and add helpful message in case NPE is thrown
     new eb4011b  Update org.nosphere.apache.rat plugin from 0.5.2 to 0.7.0, and print files with unapproved licenses to console

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 build.gradle.kts                                   |  1 +
 .../java/org/apache/calcite/runtime/FlatLists.java |  2 +-
 .../org/apache/calcite/util/ImmutableIntList.java  |  2 +-
 .../org/apache/calcite/util/mapping/Mappings.java  | 37 ++++++++++++++++++++--
 .../java/org/apache/calcite/util/UtilTest.java     |  4 +++
 .../apache/calcite/util/mapping/MappingTest.java   | 13 +++++++-
 gradle.properties                                  |  2 +-
 7 files changed, 54 insertions(+), 7 deletions(-)


[calcite] 05/05: Update org.nosphere.apache.rat plugin from 0.5.2 to 0.7.0, and print files with unapproved licenses to console

Posted by vl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit eb4011bb4b9d962c2f8e6767cbee8c23435ef939
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Sat Sep 5 00:15:18 2020 +0300

    Update org.nosphere.apache.rat plugin from 0.5.2 to 0.7.0, and print files with unapproved licenses to console
---
 build.gradle.kts  | 1 +
 gradle.properties | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/build.gradle.kts b/build.gradle.kts
index 59e883b..2aa49f1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -86,6 +86,7 @@ val gitProps by tasks.registering(FindGitAttributes::class) {
 
 val rat by tasks.getting(org.nosphere.apache.rat.RatTask::class) {
     gitignore(gitProps)
+    verbose.set(true)
     // Note: patterns are in non-standard syntax for RAT, so we use exclude(..) instead of excludeFile
     exclude(rootDir.resolve(".ratignore").readLines())
 }
diff --git a/gradle.properties b/gradle.properties
index 867ef45..ebd316b 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -50,7 +50,7 @@ de.thetaphi.forbiddenapis.version=2.7
 kotlin.version=1.3.50
 me.champeau.gradle.jmh.version=0.5.0
 org.jetbrains.gradle.plugin.idea-ext.version=0.5
-org.nosphere.apache.rat.version=0.5.2
+org.nosphere.apache.rat.version=0.7.0
 org.owasp.dependencycheck.version=5.2.2
 
 # TODO


[calcite] 02/05: [CALCITE-4226] Add Mappings#asListNonNull as a null-safe alternative for Mappings#asList

Posted by vl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit 9422fd444f0cb01cf5659045d1bb3bc71b59b73e
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Fri Sep 4 23:29:30 2020 +0300

    [CALCITE-4226] Add Mappings#asListNonNull as a null-safe alternative for Mappings#asList
---
 .../org/apache/calcite/util/mapping/Mappings.java  | 27 ++++++++++++++++++++++
 .../apache/calcite/util/mapping/MappingTest.java   | 13 ++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
index 9162d40..88d2c7e 100644
--- a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
+++ b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
@@ -326,6 +326,33 @@ public abstract class Mappings {
   }
 
   /**
+   * Returns a mapping as a list such that {@code list.get(source)} is
+   * {@code mapping.getTarget(source)} and {@code list.size()} is
+   * {@code mapping.getSourceCount()}.
+   *
+   * <p>The resulting list never contains null elements</p>
+   *
+   * <p>Converse of {@link #target(List, int)}</p>
+   * @see #asList(TargetMapping)
+   */
+  public static List<Integer> asListNonNull(final TargetMapping mapping) {
+    return new AbstractList<Integer>() {
+      public Integer get(int source) {
+        int target = mapping.getTargetOpt(source);
+        if (target < 0) {
+          throw new IllegalArgumentException("Element " + source + " is not found in mapping "
+              + mapping);
+        }
+        return target;
+      }
+
+      public int size() {
+        return mapping.getSourceCount();
+      }
+    };
+  }
+
+  /**
    * Converts a {@link Map} of integers to a {@link TargetMapping}.
    */
   public static TargetMapping target(
diff --git a/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java b/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
index 9be5938..42a41a7 100644
--- a/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
+++ b/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
@@ -171,7 +171,10 @@ class MappingTest {
     assertThrows(IndexOutOfBoundsException.class, () -> mapping.getTarget(-1));
 
     final List<Integer> integers = Mappings.asList(mapping);
-    assertThat(integers, equalTo(targets));
+    assertThat("Mappings.asList" + mapping + ")", integers, equalTo(targets));
+    assertThat(
+        "Mappings.asListNonNull(" + mapping + ")",
+        Mappings.asListNonNull(mapping), equalTo(targets));
 
     final Mapping inverse = mapping.inverse();
     assertThat(inverse.toString(),
@@ -200,6 +203,14 @@ class MappingTest {
     final List<Integer> integers = Mappings.asList(mapping);
     assertThat(integers,
         equalTo(Arrays.asList(null, 1, null, 0, 2, 3, null, null, 4, null)));
+
+    // Note: exception is thrown on list.get, so it is needed to trigger the exception
+    IllegalArgumentException exception =
+        assertThrows(IllegalArgumentException.class, () ->
+            Mappings.asListNonNull(mapping).get(0));
+    assertThat(exception.getMessage(),
+        equalTo("Element 0 is not found in mapping [size=5, sourceCount=10, targetCount=5"
+            + ", elements=[1:1, 3:0, 4:2, 5:3, 8:4]]"));
   }
 
   /** Unit test for {@link Mappings#bijection(List)}. */


[calcite] 03/05: [CALCITE-4227] ImmutableIntList#toArray(Integer[]) should support arguments larger than the collection itself

Posted by vl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit ad164ededa78a4b5383e636006e41ed98409ba7b
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Fri Sep 4 23:31:06 2020 +0300

    [CALCITE-4227] ImmutableIntList#toArray(Integer[]) should support arguments larger than the collection itself
---
 core/src/main/java/org/apache/calcite/util/ImmutableIntList.java | 2 +-
 core/src/test/java/org/apache/calcite/util/UtilTest.java         | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java b/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
index 46f32b5..e0f8e4c 100644
--- a/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
+++ b/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
@@ -151,7 +151,7 @@ public class ImmutableIntList extends FlatLists.AbstractFlatList<Integer> {
     }
     if ((Class) a.getClass() == Integer[].class) {
       final Integer[] integers = (Integer[]) a;
-      for (int i = 0; i < integers.length; i++) {
+      for (int i = 0; i < size; i++) {
         integers[i] = ints[i];
       }
     } else {
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 e681446..98f99b4 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -1153,6 +1153,10 @@ class UtilTest {
     assertThat(list2.appendAll(list), sameInstance(list2));
     //noinspection CollectionAddedToSelf
     assertThat(list2.appendAll(list2), is(Arrays.asList(1, 3, 5, 1, 3, 5)));
+    assertThat(
+        Arrays.toString(ImmutableIntList.of(1).toArray(new Integer[]{5, 6, 7})),
+        is("[1, null, 7]")
+    );
   }
 
   /** Unit test for {@link IdPair}. */


[calcite] 04/05: Remove ArrayList allocation from Mappings#bijection, and add helpful message in case NPE is thrown

Posted by vl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit fb2a02fb78f4e5b9b887645651b4b285ed68dacd
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Fri Sep 4 23:39:27 2020 +0300

    Remove ArrayList allocation from Mappings#bijection, and add helpful message in case NPE is thrown
    
    bijection requires all indices from [0..targets.size()-1) to be mapped
    to non-null, and NPE was thrown if that is not the case.
    
    The change adds extra message, so it is easier to see what aas the mapping.
---
 .../main/java/org/apache/calcite/util/mapping/Mappings.java    | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
index 88d2c7e..269c6cd 100644
--- a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
+++ b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
@@ -426,11 +426,15 @@ public abstract class Mappings {
    *
    * <p>Throws if sources and targets are not one to one. */
   public static Mapping bijection(Map<Integer, Integer> targets) {
-    final List<Integer> targetList = new ArrayList<>();
+    int[] ints = new int[targets.size()];
     for (int i = 0; i < targets.size(); i++) {
-      targetList.add(targets.get(i));
+      Integer value = targets.get(i);
+      if (value == null) {
+        throw new NullPointerException("Index " + i + " is not mapped in " + targets);
+      }
+      ints[i] = value;
     }
-    return new Permutation(Ints.toArray(targetList));
+    return new Permutation(ints);
   }
 
   /**


[calcite] 01/05: [CALCITE-4228] FlatLists.Flat6List#append should not throw NPE if there are null elements in the list

Posted by vl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit ff169fb9b34e2357566850f8ba4e74b0bfef5755
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Fri Sep 4 22:20:10 2020 +0300

    [CALCITE-4228] FlatLists.Flat6List#append should not throw NPE if there are null elements in the list
---
 core/src/main/java/org/apache/calcite/runtime/FlatLists.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
index c8c7d07..84c4b3b 100644
--- a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
+++ b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
@@ -1244,7 +1244,7 @@ public class FlatLists {
     }
 
     public List<T> append(T e) {
-      return ImmutableList.of(t0, t1, t2, t3, t5, e);
+      return ImmutableNullableList.of(t0, t1, t2, t3, t5, e);
     }
   }