DRILL-1634: Fix issue in complex type expression type resolution, when Drill queries a nested array.
code clean up. add comment of code change. Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/3b8dd3b4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/3b8dd3b4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/3b8dd3b4 Branch: refs/heads/master Commit: 3b8dd3b48d52c7499bcdff407d4b407d80fa1720 Parents: 0f069ba Author: Jinfeng Ni <j...@maprtech.com> Authored: Tue Nov 4 16:55:24 2014 -0800 Committer: Jinfeng Ni <j...@maprtech.com> Committed: Fri Nov 7 10:50:55 2014 -0800 ---------------------------------------------------------------------- .../exec/vector/complex/AbstractContainerVector.java | 14 ++++++++++---- .../drill/exec/store/json/JsonRecordReader2Test.java | 7 +++++++ .../src/test/resources/jsoninput/nestedArray.json | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3b8dd3b4/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/AbstractContainerVector.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/AbstractContainerVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/AbstractContainerVector.java index 096db6e..1210d90 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/AbstractContainerVector.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/AbstractContainerVector.java @@ -55,11 +55,17 @@ public abstract class AbstractContainerVector implements ValueVector{ if (seg.isArray()) { if (seg.isLastPath()) { - return builder // - .remainder(seg) // + builder // .withIndex() // - .finalType(getLastPathType()) // - .build(); + .finalType(getLastPathType()); + + // remainder starts with the 1st array segment in SchemaPath. + // only set remainder when it's the only array segment. + if (addToBreadCrumb) { + addToBreadCrumb = false; + builder.remainder(seg); + } + return builder.build(); } else { if (addToBreadCrumb) { addToBreadCrumb = false; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3b8dd3b4/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java index c83a3ab..9df6cf0 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java @@ -44,4 +44,11 @@ public class JsonRecordReader2Test extends BaseTestQuery{ public void trySimpleQueryWithLimit() throws Exception{ test("select * from cp.`limit/test1.json` limit 10"); } + + @Test// DRILL-1634 : retrieve an element in a nested array in a repeated map. RepeatedMap (Repeated List (Repeated varchar)) + public void testNestedArrayInRepeatedMap() throws Exception { + test("select a[0].b[0] from cp.`jsoninput/nestedArray.json`"); + test("select a[0].b[1] from cp.`jsoninput/nestedArray.json`"); + test("select a[1].b[1] from cp.`jsoninput/nestedArray.json`"); // index out of the range. Should return empty list. + } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3b8dd3b4/exec/java-exec/src/test/resources/jsoninput/nestedArray.json ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/resources/jsoninput/nestedArray.json b/exec/java-exec/src/test/resources/jsoninput/nestedArray.json new file mode 100644 index 0000000..ffd3e9f --- /dev/null +++ b/exec/java-exec/src/test/resources/jsoninput/nestedArray.json @@ -0,0 +1,2 @@ +{ "a":[{"b": [["str1","str2"], ["str3", "str4"]]}] } +{ "a":[{"b": [["str10","str20"], ["str30", "str40"]]}] }