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 2014/11/21 03:30:28 UTC
[3/3] incubator-calcite git commit: Fix Linq4j.product;
the cartesian product of 0 attributes is one row of 0 attributes.
Fix Linq4j.product; the cartesian product of 0 attributes is one row of 0 attributes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/b87f66b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/b87f66b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/b87f66b0
Branch: refs/heads/master
Commit: b87f66b08e90fdbf570b48cba5dc1f751ea399f4
Parents: dc662db
Author: Julian Hyde <jh...@apache.org>
Authored: Thu Nov 20 15:53:38 2014 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Nov 20 16:45:57 2014 -0800
----------------------------------------------------------------------
.../calcite/linq4j/CartesianProductEnumerator.java | 13 ++-----------
.../org/apache/calcite/linq4j/test/Linq4jTest.java | 6 ++++++
2 files changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/b87f66b0/linq4j/src/main/java/org/apache/calcite/linq4j/CartesianProductEnumerator.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/CartesianProductEnumerator.java b/linq4j/src/main/java/org/apache/calcite/linq4j/CartesianProductEnumerator.java
index 88fbd5c..9bf3da1 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/CartesianProductEnumerator.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/CartesianProductEnumerator.java
@@ -41,9 +41,6 @@ class CartesianProductEnumerator<T> implements Enumerator<List<T>> {
public boolean moveNext() {
if (first) {
- if (enumerators.isEmpty()) {
- return false;
- }
int i = 0;
for (Enumerator<T> enumerator : enumerators) {
if (!enumerator.moveNext()) {
@@ -54,8 +51,7 @@ class CartesianProductEnumerator<T> implements Enumerator<List<T>> {
first = false;
return true;
}
- int ordinal = enumerators.size() - 1;
- for (;;) {
+ for (int ordinal = enumerators.size() - 1; ordinal >= 0; --ordinal) {
final Enumerator<T> enumerator = enumerators.get(ordinal);
if (enumerator.moveNext()) {
elements[ordinal] = enumerator.current();
@@ -69,13 +65,8 @@ class CartesianProductEnumerator<T> implements Enumerator<List<T>> {
return false;
}
elements[ordinal] = enumerator.current();
-
- // Advance higher rank enumerator.
- if (ordinal == 0) {
- return false;
- }
- --ordinal;
}
+ return false;
}
public void reset() {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/b87f66b0/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 5c92e9e..27ee715 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
@@ -993,6 +993,12 @@ public class Linq4jTest {
final Enumerable<String> xy =
Linq4j.asEnumerable(Arrays.asList("x", "y"));
+ final Enumerator<List<String>> productEmpty =
+ Linq4j.product(Arrays.<Enumerator<String>>asList());
+ assertTrue(productEmpty.moveNext());
+ assertEquals(Arrays.<String>asList(), productEmpty.current());
+ assertFalse(productEmpty.moveNext());
+
final Enumerator<List<String>> product0 =
Linq4j.product(
Arrays.asList(Linq4j.<String>emptyEnumerator()));