You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/10/08 12:44:15 UTC

[GitHub] asfgit closed pull request #1487: DRILL-6764: Query fails with IOB when Unnest has reference to deep ne…

asfgit closed pull request #1487: DRILL-6764: Query fails with IOB when Unnest has reference to deep ne…
URL: https://github.com/apache/drill/pull/1487
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ComplexUnnestVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ComplexUnnestVisitor.java
index b8d62f5fc7a..60e46ef46c1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ComplexUnnestVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ComplexUnnestVisitor.java
@@ -82,15 +82,18 @@ public RelNode visit(LogicalCorrelate correlate) {
     builder.push(newCorrelate);
 
     List<RexNode> topProjectExpressions = left.getRowType().getFieldList().stream()
-        .map(field -> builder.getRexBuilder().makeInputRef(left, field.getIndex()))
-        .collect(Collectors.toList());
+            .map(field -> builder.getRexBuilder().makeInputRef(newCorrelate, field.getIndex()))
+            .collect(Collectors.toList());
 
+    //Accommodate the new $COMPLEX_FIELD_NAME column.
+    int rightStartIndex = left.getRowType().getFieldList().size() + 1;
     switch (correlate.getJoinType()) {
       case LEFT:
       case INNER:
         // adds field from the right input of correlate to the top project
-        topProjectExpressions.add(
-            builder.getRexBuilder().makeInputRef(newCorrelate, topProjectExpressions.size() + 1));
+        topProjectExpressions.addAll(right.getRowType().getFieldList().stream()
+                .map(field -> builder.getRexBuilder().makeInputRef(newCorrelate, field.getIndex() + rightStartIndex))
+                .collect(Collectors.toList()));
         // fall through
       case ANTI:
       case SEMI:
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/lateraljoin/TestLateralPlans.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/lateraljoin/TestLateralPlans.java
index 9adc3b5b1fa..ea78dddbb8e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/lateraljoin/TestLateralPlans.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/lateraljoin/TestLateralPlans.java
@@ -549,4 +549,24 @@ public void testMultiUnnestQuery() throws Exception {
               .go();
     }
   }
+
+  @Test
+  public void testNestedColumnQuery() throws Exception {
+    String sql = "select dt.area_code as area_code, dt.ph as ph from cp.`lateraljoin/nested-customer-map.json` t," +
+                 " lateral (select t2.ord.area_code as area_code , t2.ord.phone as ph from unnest(t.c_address.c_phone) t2(ord)) dt";
+
+    String baselineQuery = "select dt.c_ph.area_code as area_code, dt.c_ph.phone as ph from (select flatten(t.c_address.c_phone) as c_ph from cp.`lateraljoin/nested-customer-map.json` t) dt";
+
+    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher)
+            .setOptionDefault(PlannerSettings.ENABLE_UNNEST_LATERAL_KEY, true);
+
+    try (ClusterFixture cluster = builder.build();
+         ClientFixture client = cluster.clientFixture()) {
+      client.testBuilder()
+              .ordered()
+              .sqlBaselineQuery(baselineQuery)
+              .sqlQuery(sql)
+              .go();
+    }
+  }
 }
diff --git a/exec/java-exec/src/test/resources/lateraljoin/nested-customer-map.json b/exec/java-exec/src/test/resources/lateraljoin/nested-customer-map.json
new file mode 100644
index 00000000000..07de0541c80
--- /dev/null
+++ b/exec/java-exec/src/test/resources/lateraljoin/nested-customer-map.json
@@ -0,0 +1,134 @@
+{
+  "c_name" : "customer1",
+  "c_id" : 1,
+  "c_phone" : ["6505200001", "4085201234", "6125205678"],
+  "orders" : [{"o_id": 1, "o_shop": "Meno Park 1st", "o_amount": 4.5,
+               "items" : [ {"i_name" : "paper towel", "i_number": 2, "i_supplier": "oregan"},
+                           {"i_name" : "map", "i_number": 1, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 9, "i_supplier": "california"}
+                         ]
+
+              },
+              {"o_id": 2, "o_shop": "Mountain View 1st", "o_amount": 104.5,
+               "items" : [ {"i_name" : "beef", "i_number": 3, "i_supplier": "montana"},
+                           {"i_name" : "tooth paste", "i_number": 4, "i_supplier": "washington"},
+                           {"i_name" : "hat", "i_number": 7, "i_supplier": "california"}
+                         ]
+
+              },
+              {"o_id": 3, "o_shop": "Sunnyvale 1st", "o_amount": 294.5,
+               "items" : [ {"i_name" : "paper towel", "i_number": 5, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 6, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 8, "i_supplier": "california"}
+                         ]
+              }
+             ],
+  "c_address" : {
+              "Area": "bay area",
+	      "City": "Santa Clara",
+              "State" : "CA",
+              "c_phone": [{"area_code": "650", "phone": "5200001"}, {"area_code": "408", "phone": "5201234"}, {"area_code" : "612", "phone": "5205678"}]
+            }
+}
+{
+  "c_name" : "customer2",
+  "c_id" : 2,
+  "c_phone" : ["1505200001", "7085201234", "2125205678"],
+  "orders" : [{"o_id": 10, "o_shop": "Mountain View 1st", "o_amount": 724.5,
+               "items" : [ {"i_name" : "beef", "i_number": 12, "i_supplier": "montana"},
+                           {"i_name" : "tooth paste", "i_number": 11, "i_supplier": "washington"},
+                           {"i_name" : "hat", "i_number": 10, "i_supplier": "california"}
+                         ]
+
+              },
+
+              {"o_id": 11, "o_shop": "Sunnyvale 1st", "o_amount": 179.5,
+               "items" : [ {"i_name" : "paper towel", "i_number": 13, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 14, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 15, "i_supplier": "california"}
+                         ]
+              },
+              {"o_id": 12, "o_shop": "Meno Park 1st", "o_amount": 80.0,
+               "items" : [ {"i_name" : "paper towel", "i_number": 13, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 14, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 15, "i_supplier": "california"}
+                         ]
+              }
+             ],
+  "c_address" : {
+               "Area": "Greater LA",
+               "City": "LA",
+               "State" : "CA",
+               "c_phone": [{"area_code": "150", "phone" : "5200001"}, {"area_code": "708", "phone": "5201234"}, {"area_code" : "212", "phone": "5205678"}]
+              }
+}
+{
+  "c_name" : "customer3",
+  "c_id" : 3,
+  "c_phone" : ["1205200001", "7285201234", "2325205678"],
+  "orders" : [{"o_id": 21, "o_shop": "Meno Park 1st", "o_amount": 192.5,
+               "items" : [ {"i_name" : "beef", "i_number": 22, "i_supplier": "montana"},
+                           {"i_name" : "tooth paste", "i_number": 21, "i_supplier": "washington"},
+                           {"i_name" : "hat", "i_number": 20, "i_supplier": "california"}
+                         ]
+
+              },
+
+              {"o_id": 22, "o_shop": "Mountain View 1st", "o_amount": 680.9,
+               "items" : [ {"i_name" : "paper towel", "i_number": 23, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 24, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 25, "i_supplier": "california"}
+                         ]
+              },
+
+              {"o_id": 23, "o_shop": "Sunnyvale 1st", "o_amount": 772.2,
+               "items" : [ {"i_name" : "paper towel", "i_number": 26, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 27, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 28, "i_supplier": "california"}
+                         ]
+              }
+
+             ],
+  "c_address" : {
+                "Area": "bay area, CA",
+                "City": "Milpitas",
+                "State": "CA",
+                "c_phone": [{"area_code" : "120", "phone": "5200001"}, {"area_code": "728", "phone": "5201234"}, {"area_code": "232", "phone" :"5205678"}]
+             }
+}
+{
+  "c_name" : "customer4",
+  "c_id" : 4,
+  "c_phone" : ["6509200001", "4088201234", "6127205678"],
+  "orders" : [{"o_id": 30, "o_shop": "Mountain View 1st", "o_amount": 870.2,
+               "items" : [ {"i_name" : "beef", "i_number": 32, "i_supplier": "montana"},
+                           {"i_name" : "tooth paste", "i_number": 31, "i_supplier": "washington"},
+                           {"i_name" : "hat", "i_number": 30, "i_supplier": "california"}
+                         ]
+
+              },
+
+              {"o_id": 31, "o_shop": "Sunnyvale 1st", "o_amount": 970.5,
+               "items" : [ {"i_name" : "beef", "i_number": 32, "i_supplier": "montana"},
+                           {"i_name" : "tooth paste", "i_number": 31, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 30, "i_supplier": "california"}
+                         ]
+
+              },
+
+              {"o_id": 32, "o_shop": "Meno Park 1st", "o_amount": 1030.1,
+               "items" : [ {"i_name" : "paper towel", "i_number": 36, "i_supplier": "oregan"},
+                           {"i_name" : "tooth paste", "i_number": 37, "i_supplier": "washington"},
+                           {"i_name" : "cheese", "i_number": 38, "i_supplier": "california"}
+                         ]
+              }
+
+             ],
+  "c_address" : {
+               "Area": "Greater Sandiego",
+               "City": "Sandiego",
+               "State": "CA",
+               "c_phone": [{"area_code": "650", "phone": "9200001"}, {"area_code": "408", "phone": "8201234"}, {"area_code": "612", "phone": "7205678"}]
+              } 
+}
+


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services