andygrove opened a new issue, #2415:
URL: https://github.com/apache/arrow-datafusion/issues/2415

   **Describe the bug**
   
   The following query fails with `SchemaError(FieldNotFound { qualifier: None, 
name: "j2_id", valid_fields: Some(["j1.j1_id", "j1.j1_string", "j3.j3_id", 
"j3.j3_string", "j1.j1_id", "j1.j1_string", "j3.j3_id", "j3.j3_string"]) }`
   
   ``` sql
   SELECT j1_string, j2_string 
           FROM j1, j2 
           WHERE j1_id = j2_id - 1 
           AND j2_id < (SELECT count(*) 
               FROM j1, j3 
               WHERE j2_id = j1_id 
               AND j1_id = j3_id)
   ```
   
   
   **To Reproduce**
   
   Add this test to `sql/planner.rs`:
   
   ``` rust
   #[test]
   fn scalar_subquery_reference_outer_field() {
       let sql = "SELECT j1_string, j2_string \
       FROM j1, j2 \
       WHERE j1_id = j2_id - 1 \
       AND j2_id < (SELECT count(*) \
           FROM j1, j3 \
           WHERE j2_id = j1_id \
           AND j1_id = j3_id)";
   
       let expected = "TBD";
   
       quick_test(sql, &expected);
   }
   ```
   
   Also, add these tables to `MockContextProvider` in the same file.
   
   ``` rust
   "j1" => Some(Schema::new(vec![
       Field::new("j1_id", DataType::Int32, false),
       Field::new("j1_string", DataType::Utf8, false),
   ])),
   "j2" => Some(Schema::new(vec![
       Field::new("j2_id", DataType::Int32, false),
       Field::new("j2_string", DataType::Utf8, false),
   ])),
   "j3" => Some(Schema::new(vec![
       Field::new("j3_id", DataType::Int32, false),
       Field::new("j3_string", DataType::Utf8, false),
   ])),
   ```
   
   **Expected behavior**
   Query should produce a valid plan.
   
   **Additional context**
   None
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to