You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vo...@apache.org on 2018/10/08 12:43:54 UTC
[drill] 04/06: DRILL-6764: Query fails with IOB when Unnest has
reference to deep nested field like (t.c_orders.o_lineitems).
This is an automated email from the ASF dual-hosted git repository.
volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
commit 778e043f284921792403f6dc595050793a47ee02
Author: Hanumath Rao Maduri <ha...@gmail.com>
AuthorDate: Tue Oct 2 16:32:38 2018 -0700
DRILL-6764: Query fails with IOB when Unnest has reference to deep nested field like (t.c_orders.o_lineitems).
closes #1487
---
.../planner/sql/handlers/ComplexUnnestVisitor.java | 11 +-
.../impl/lateraljoin/TestLateralPlans.java | 20 +++
.../resources/lateraljoin/nested-customer-map.json | 134 +++++++++++++++++++++
3 files changed, 161 insertions(+), 4 deletions(-)
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 b8d62f5..60e46ef 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 class ComplexUnnestVisitor extends RelShuttleImpl {
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 9adc3b5..ea78ddd 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 class TestLateralPlans extends BaseTestQuery {
.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 0000000..07de054
--- /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"}]
+ }
+}
+