You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/19 05:05:32 UTC

[GitHub] [arrow-datafusion] hengfeiyang opened a new issue, #4288: Field alias can't work in where clause

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

   **Describe the bug**
   It can't work like this:
   
   ```sql
   SELECT foo AS bar FROM t WHERE bar > 10
   ```
   
   I have the field `foo` just give it an alias `bar` then as a where clause, it will report the error:
   
   ```
   Error: SchemaError(FieldNotFound { qualifier: None, name: "bar", valid_fields: Some(["t.foo"]) })
   ```
   
   **To Reproduce**
   Steps to reproduce the behavior:
   
   **Expected behavior**
   
   It can work.
   
   **Additional context**
   
   My demo code:
   
   ```rust
   use std::sync::Arc;
   
   use datafusion::arrow::array::Int32Array;
   use datafusion::arrow::datatypes::{DataType, Field, Schema};
   use datafusion::arrow::record_batch::RecordBatch;
   use datafusion::datasource::MemTable;
   use datafusion::error::Result;
   use datafusion::from_slice::FromSlice;
   use datafusion::prelude::SessionContext;
   
   /// This example demonstrates how to use the DataFrame API against in-memory data.
   #[tokio::main]
   async fn main() -> Result<()> {
       // define a schema.
       let schema = Arc::new(Schema::new(vec![Field::new("foo", DataType::Int32, false)]));
   
       // define data.
       let batch = RecordBatch::try_new(
           schema.clone(),
           vec![Arc::new(Int32Array::from_slice([1, 10, 10, 100]))],
       )?;
   
       // declare a new context. In spark API, this corresponds to a new spark SQLsession
       let ctx = SessionContext::new();
   
       // declare a table in memory. In spark API, this corresponds to createDataFrame(...).
       let provider = MemTable::try_new(schema.clone(), vec![vec![batch]])?;
       ctx.register_table("t", Arc::new(provider))?;
       let df = ctx.sql("SELECT foo AS bar FROM t WHERE bar > 10").await?;
   
       // print the results
       df.show().await?;
   
       Ok(())
   }
   ```
   


-- 
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-unsubscribe@arrow.apache.org.apache.org

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


[GitHub] [arrow-datafusion] hengfeiyang commented on issue #4288: Field alias can't work in where clause

Posted by GitBox <gi...@apache.org>.
hengfeiyang commented on issue #4288:
URL: https://github.com/apache/arrow-datafusion/issues/4288#issuecomment-1320828657

   Okay, thanks, my bad i tested in MySQL it also can't work.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on issue #4288: Field alias can't work in where clause

Posted by GitBox <gi...@apache.org>.
jackwener commented on issue #4288:
URL: https://github.com/apache/arrow-datafusion/issues/4288#issuecomment-1320812223

   I will fix it.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on issue #4288: Field alias can't work in where clause

Posted by GitBox <gi...@apache.org>.
jackwener commented on issue #4288:
URL: https://github.com/apache/arrow-datafusion/issues/4288#issuecomment-1320815793

   It isn't bug. `select` is after `where`.
   Your sql is wrong.
   


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] hengfeiyang closed issue #4288: Field alias can't work in where clause

Posted by GitBox <gi...@apache.org>.
hengfeiyang closed issue #4288: Field alias can't work in where clause
URL: https://github.com/apache/arrow-datafusion/issues/4288


-- 
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-unsubscribe@arrow.apache.org

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