You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2013/05/23 18:01:28 UTC

git commit: Fixing outer join and add test cases

Updated Branches:
  refs/heads/master 0f8cccb3d -> d162e1338


Fixing outer join and add test cases


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

Branch: refs/heads/master
Commit: d162e13383f4001ab5e6e4b9d27288e0dfaee22d
Parents: 0f8cccb
Author: Timothy Chen <tn...@gmail.com>
Authored: Wed May 22 23:03:49 2013 -0700
Committer: Timothy Chen <tn...@gmail.com>
Committed: Thu May 23 01:10:01 2013 -0700

----------------------------------------------------------------------
 .../org/apache/drill/exec/ref/rops/JoinROP.java    |   11 ++-
 .../java/org/apache/drill/exec/ref/TestUtils.java  |    2 +-
 .../apache/drill/exec/ref/rops/JoinROPTest.java    |   12 ++-
 .../ref/src/test/resources/join/employees.json     |    4 +-
 .../ref/src/test/resources/join/full_join.json     |   74 +++++++++++++++
 .../ref/src/test/resources/join/left_join.json     |   74 +++++++++++++++
 6 files changed, 170 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/JoinROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/JoinROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/JoinROP.java
index f24a21d..44fc3df 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/JoinROP.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/JoinROP.java
@@ -206,9 +206,9 @@ public class JoinROP extends ROPBase<Join> {
                     }
                 });
 
-              if (curIdx >= bufferLength) {
-                  curIdx = 0;
-              }
+                if (curIdx >= bufferLength) {
+                   curIdx = 0;
+                }
 
                 if (option.isPresent()) {
                     setOutputRecord(rightPointer, bufferObj.pointer);
@@ -235,6 +235,10 @@ public class JoinROP extends ROPBase<Join> {
         public NextOutcome getNext() {
             final RecordPointer leftPointer = left.getRecordPointer();
             boolean isFound = true;
+            if(curIdx >= bufferLength) {
+                return NextOutcome.NONE_LEFT;
+            }
+
             while (true) {
                 if (curIdx == 0) {
                     if (!isFound) {
@@ -262,6 +266,7 @@ public class JoinROP extends ROPBase<Join> {
 
                 if (option.isPresent()) {
                     setOutputRecord(leftPointer, bufferObj.pointer);
+                    bufferObj.setHasJoined(true);
                     return (bufferObj.schemaChanged || leftOutcome == NextOutcome.INCREMENTED_SCHEMA_CHANGED) ?
                             NextOutcome.INCREMENTED_SCHEMA_CHANGED :
                             NextOutcome.INCREMENTED_SCHEMA_UNCHANGED;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
index fe9c239..d7cc690 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
@@ -51,7 +51,7 @@ public class TestUtils {
   public static void assertProduceCount(String resourcePath, int recordCount) throws Exception {
     DrillConfig config = getConfigWithQueue(0);
     Collection<RunOutcome> outcomes = getOutcome(config, resourcePath);
-    assertEquals(outcomes.iterator().next().records, recordCount);
+    assertEquals(recordCount, outcomes.iterator().next().records);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/JoinROPTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/JoinROPTest.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/JoinROPTest.java
index c334fc4..43dc719 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/JoinROPTest.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/JoinROPTest.java
@@ -23,7 +23,17 @@ import org.junit.Test;
 public class JoinROPTest {
 
   @Test
-  public void testJoin() throws Exception{
+  public void testInnerJoin() throws Exception {
     TestUtils.assertProduceCount("/join/simple_join.json", 5);
   }
+
+  @Test
+  public void testOuterJoin() throws Exception {
+    TestUtils.assertProduceCount("/join/full_join.json", 7);
+  }
+
+  @Test
+  public void testLeftJoin() throws Exception {
+    TestUtils.assertProduceCount("/join/left_join.json", 6);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/test/resources/join/employees.json
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/resources/join/employees.json b/sandbox/prototype/exec/ref/src/test/resources/join/employees.json
index 567793b..562ea4d 100644
--- a/sandbox/prototype/exec/ref/src/test/resources/join/employees.json
+++ b/sandbox/prototype/exec/ref/src/test/resources/join/employees.json
@@ -16,9 +16,9 @@
 }
 {
     "lastName": "Smith",
-    "deptId": 36
+    "deptId": 34
 }
 {
-    "deptId": 35,
+    "deptId": null,
     "lastName": "John"
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/test/resources/join/full_join.json
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/resources/join/full_join.json b/sandbox/prototype/exec/ref/src/test/resources/join/full_join.json
new file mode 100644
index 0000000..d565a08
--- /dev/null
+++ b/sandbox/prototype/exec/ref/src/test/resources/join/full_join.json
@@ -0,0 +1,74 @@
+{
+   head: {
+      type: "apache_drill_logical_plan",
+      version: "1",
+      generator: {
+         type: "manual",
+         info: "na"
+      }
+   },
+   storage:[
+       {
+         type:"console",
+         name:"console"
+       },
+       {
+         type:"fs",
+         name:"fs1",
+         root:"file:///"
+       },
+       {
+         type:"classpath",
+         name:"cp"
+       },
+       {
+         type: "queue",
+         name: "queue"
+       }
+   ],
+   query: [
+      {
+         @id: 1,
+         op: "scan",
+         memo: "initial_scan",
+         ref: "employees",
+         storageengine: "cp",
+         selection: {
+         	 path: "/join/employees.json",
+         	 type: "JSON"
+         }
+      },
+      {
+         @id: 2,
+         op: "scan",
+         memo: "second_scan",
+         ref: "departments",
+         storageengine: "cp",
+         selection: {
+             path: "/join/departments.json",
+             type: "JSON"
+         }
+      },
+      {
+         @id: 3,
+         op: "join",
+         left: 1,
+         right: 2,
+         type: "outer",
+         conditions: [
+            {
+               relationship: "==",
+               left: "employees.deptId",
+               right: "departments.deptId"
+            }
+         ]
+      },
+      {
+         input: 3,
+         op: "store",
+         memo: "output sink",
+         storageengine: "queue",
+         target: {number: 0}
+      }
+   ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d162e133/sandbox/prototype/exec/ref/src/test/resources/join/left_join.json
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/resources/join/left_join.json b/sandbox/prototype/exec/ref/src/test/resources/join/left_join.json
new file mode 100644
index 0000000..ac43be4
--- /dev/null
+++ b/sandbox/prototype/exec/ref/src/test/resources/join/left_join.json
@@ -0,0 +1,74 @@
+{
+   head: {
+      type: "apache_drill_logical_plan",
+      version: "1",
+      generator: {
+         type: "manual",
+         info: "na"
+      }
+   },
+   storage:[
+       {
+         type:"console",
+         name:"console"
+       },
+       {
+         type:"fs",
+         name:"fs1",
+         root:"file:///"
+       },
+       {
+         type:"classpath",
+         name:"cp"
+       },
+       {
+         type: "queue",
+         name: "queue"
+       }
+   ],
+   query: [
+      {
+         @id: 1,
+         op: "scan",
+         memo: "initial_scan",
+         ref: "employees",
+         storageengine: "cp",
+         selection: {
+         	 path: "/join/employees.json",
+         	 type: "JSON"
+         }
+      },
+      {
+         @id: 2,
+         op: "scan",
+         memo: "second_scan",
+         ref: "departments",
+         storageengine: "cp",
+         selection: {
+             path: "/join/departments.json",
+             type: "JSON"
+         }
+      },
+      {
+         @id: 3,
+         op: "join",
+         left: 1,
+         right: 2,
+         type: "left",
+         conditions: [
+            {
+               relationship: "==",
+               left: "employees.deptId",
+               right: "departments.deptId"
+            }
+         ]
+      },
+      {
+         input: 3,
+         op: "store",
+         memo: "output sink",
+         storageengine: "queue",
+         target: {number: 0}
+      }
+   ]
+}
\ No newline at end of file