[ 
https://issues.apache.org/jira/browse/DRILL-3476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16498290#comment-16498290
 ] 

ASF GitHub Bot commented on DRILL-3476:
---------------------------------------

ilooner closed pull request #83: DRILL-3476: Merge paths in FieldSelection
URL: https://github.com/apache/drill/pull/83
 
 
   

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/vector/complex/fn/FieldSelection.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/FieldSelection.java
index 60c1dee7ec..aecff05f43 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/FieldSelection.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/FieldSelection.java
@@ -42,7 +42,7 @@
 
   private final Map<String, FieldSelection> children;
   private final Map<String, FieldSelection> childrenInsensitive;
-  private final ValidityMode mode;
+  private ValidityMode mode;
 
   private FieldSelection(){
     this(new HashMap<String, FieldSelection>(), ValidityMode.CHECK_CHILDREN);
@@ -87,8 +87,12 @@ private FieldSelection addChild(String name){
 
   private void add(PathSegment segment){
     if(segment.isNamed()){
+      boolean lastPath = segment.isLastPath();
       FieldSelection child = addChild(segment.getNameSegment().getPath());
-      if(!segment.isLastPath()){
+      if (lastPath) {
+        child.setAlwaysValid();
+      }
+      if (!lastPath && !child.isAlwaysValid()) {
         child.add(segment.getChild());
       }
     }
@@ -98,6 +102,14 @@ public boolean isNeverValid(){
     return mode == ValidityMode.NEVER_VALID;
   }
 
+  private void setAlwaysValid() {
+    mode = ValidityMode.ALWAYS_VALID;
+  }
+
+  public boolean isAlwaysValid() {
+    return mode == ValidityMode.ALWAYS_VALID;
+  }
+
   public FieldSelection getChild(String name){
     switch(mode){
     case ALWAYS_VALID:
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/TestJsonRecordReader.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/TestJsonRecordReader.java
index bb1af9eb2e..34676a6949 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/TestJsonRecordReader.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/TestJsonRecordReader.java
@@ -154,4 +154,15 @@ public void 
testMixedNumberTypesWhenReadingNumbersAsDouble() throws Exception {
       testNoResult("alter session set `store.json.read_numbers_as_double`= 
false");
     }
   }
+
+  @Test // See DRILL-3476
+  public void testNestedFilter() throws Exception {
+    String query = "select a from cp.`jsoninput/nestedFilter.json` t where 
t.a.b = 1";
+    String baselineQuery = "select * from cp.`jsoninput/nestedFilter.json` t 
where t.a.b = 1";
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .sqlBaselineQuery(baselineQuery)
+        .go();
+  }
 }
diff --git a/exec/java-exec/src/test/resources/jsoninput/nestedFilter.json 
b/exec/java-exec/src/test/resources/jsoninput/nestedFilter.json
new file mode 100644
index 0000000000..a6c5b0c246
--- /dev/null
+++ b/exec/java-exec/src/test/resources/jsoninput/nestedFilter.json
@@ -0,0 +1 @@
+{ a : { b : 1, c : 1 } }
\ No newline at end of file


 

----------------------------------------------------------------
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:
[email protected]


> Filter on nested element gives wrong results
> --------------------------------------------
>
>                 Key: DRILL-3476
>                 URL: https://issues.apache.org/jira/browse/DRILL-3476
>             Project: Apache Drill
>          Issue Type: Bug
>            Reporter: Steven Phillips
>            Assignee: Chun Chang
>            Priority: Critical
>             Fix For: 1.2.0
>
>
> Take this query for example:
> {code}
> 0: jdbc:drill:drillbit=localhost> select * from t;
> +----------------+
> |       a        |
> +----------------+
> | {"b":1,"c":1}  |
> +----------------+
> {code}
> if I instead run:
> {code}
> 0: jdbc:drill:drillbit=localhost> select a from t where t.a.b = 1;
> +----------------+
> |       a        |
> +----------------+
> | {"b":1}  |
> +----------------+
> {code}
> Only a.b was returned, but the select specified a. In this case, it should 
> have returned all of the elements of a, not just the one specified in the 
> filter.
> This is because the logic in FieldSelection does not correctly handle the 
> case where a selected column is a child of another selected column. In such a 
> case, the record reader should ignore the child column, and just return the 
> full selected parent column.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to