forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/11982: resolves projection issue found in with_column window fn u…
…sage Signed-off-by: Devan <devandbenz@gmail.com>
- Loading branch information
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
datafusion-examples/examples/testing_window_bug_will_delete.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use arrow::array::{Int32Array, RecordBatch}; | ||
use arrow_schema::{DataType, Field, Schema}; | ||
use datafusion::datasource::MemTable; | ||
use datafusion::error::Result; | ||
use datafusion::prelude::SessionContext; | ||
use datafusion_expr::expr::WindowFunction; | ||
use datafusion_expr::{col, BuiltInWindowFunction, Expr, WindowFunctionDefinition}; | ||
use std::sync::Arc; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]); | ||
|
||
let batch = RecordBatch::try_new( | ||
Arc::new(schema.clone()), | ||
vec![Arc::new(Int32Array::from(vec![5, 4, 3, 2, 1]))], | ||
)?; | ||
|
||
let ctx = SessionContext::new(); | ||
|
||
let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]])?; | ||
ctx.register_table("t", Arc::new(provider))?; | ||
|
||
let df = ctx.table("t").await?; | ||
|
||
let func = Expr::WindowFunction(WindowFunction::new( | ||
WindowFunctionDefinition::BuiltInWindowFunction(BuiltInWindowFunction::RowNumber), | ||
vec![], | ||
)) | ||
.alias("row_num"); | ||
|
||
df.clone() | ||
.select(vec![col("a"), func.clone()])? | ||
.show() | ||
.await?; | ||
|
||
df.with_column("r", func)?.show().await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters