-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: failed to create ValuesExec with non-nullable schema #8776
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -27,9 +27,8 @@ use crate::{ | |
PhysicalExpr, | ||
}; | ||
|
||
use arrow::array::new_null_array; | ||
use arrow::datatypes::SchemaRef; | ||
use arrow::record_batch::RecordBatch; | ||
use arrow::datatypes::{Schema, SchemaRef}; | ||
use arrow::record_batch::{RecordBatch, RecordBatchOptions}; | ||
use datafusion_common::{internal_err, plan_err, DataFusionError, Result, ScalarValue}; | ||
use datafusion_execution::TaskContext; | ||
|
||
|
@@ -53,15 +52,14 @@ impl ValuesExec { | |
} | ||
let n_row = data.len(); | ||
let n_col = schema.fields().len(); | ||
// we have this single row, null, typed batch as a placeholder to satisfy evaluation argument | ||
let batch = RecordBatch::try_new( | ||
schema.clone(), | ||
schema | ||
.fields() | ||
.iter() | ||
.map(|field| new_null_array(field.data_type(), 1)) | ||
.collect::<Vec<_>>(), | ||
// we have this single row batch as a placeholder to satisfy evaluation argument | ||
// and generate a single output row | ||
let batch = RecordBatch::try_new_with_options( | ||
Arc::new(Schema::empty()), | ||
vec![], | ||
&RecordBatchOptions::new().with_row_count(Some(1)), | ||
)?; | ||
|
||
let arr = (0..n_col) | ||
.map(|j| { | ||
(0..n_row) | ||
|
@@ -71,7 +69,7 @@ impl ValuesExec { | |
match r { | ||
Ok(ColumnarValue::Scalar(scalar)) => Ok(scalar), | ||
Ok(ColumnarValue::Array(a)) if a.len() == 1 => { | ||
Ok(ScalarValue::List(a)) | ||
ScalarValue::try_from_array(&a, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning DataFusion CLI v34.0.0
❯ select * from (values(random()));
Internal error: Inconsistent types in ScalarValue::iter_to_array. Expected Float64, got List(0.5174512019067328).
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker Related to pr #7629. I think it's a bug, so I fixed it. |
||
} | ||
Ok(ColumnarValue::Array(a)) => { | ||
plan_err!( | ||
|
@@ -201,6 +199,7 @@ impl ExecutionPlan for ValuesExec { | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::expressions::lit; | ||
use crate::test::{self, make_partition}; | ||
|
||
use arrow_schema::{DataType, Field, Schema}; | ||
|
@@ -240,4 +239,15 @@ mod tests { | |
])); | ||
let _ = ValuesExec::try_new_from_batches(invalid_schema, batches).unwrap_err(); | ||
} | ||
|
||
// Test issue: https://github.com/apache/arrow-datafusion/issues/8763 | ||
#[test] | ||
fn new_exec_with_non_nullable_schema() { | ||
let schema = Arc::new(Schema::new(vec![Field::new( | ||
"col0", | ||
DataType::UInt32, | ||
false, | ||
)])); | ||
let _ = ValuesExec::try_new(schema, vec![vec![lit(1u32)]]).unwrap(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -114,6 +114,14 @@ VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13,NULL,'F',3.5) | |
---- | ||
1 2 3 4 5 6 7 8 9 10 11 12 13 NULL F 3.5 | ||
|
||
# Test non-literal expressions in VALUES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
query II | ||
VALUES (1, CASE WHEN RANDOM() > 0.5 THEN 1 ELSE 1 END), | ||
(2, CASE WHEN RANDOM() > 0.5 THEN 2 ELSE 2 END); | ||
---- | ||
1 1 | ||
2 2 | ||
|
||
query IT | ||
SELECT * FROM (VALUES (1,'a'),(2,NULL)) AS t(c1, c2) | ||
---- | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this code to use a null array probably pre-dates the ability to create zero column record batches