-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Remove Expr::GetIndexedField
, replace Expr::{field,index,range}
with FieldAccessor
, IndexAccessor
, and SliceAccessor
#10568
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6c8abb4
remove expr
jayzhan211 3aff84b
add expr extension
jayzhan211 5bf1d82
doc
jayzhan211 db6b48a
move test that has struct
jayzhan211 1a754b4
fmt
jayzhan211 dc3bfd7
add foc and fix displayed name
jayzhan211 136f3df
rm test
jayzhan211 860b11b
Merge remote-tracking branch 'upstream/main' into rm-GetIndexedField
jayzhan211 26cb3d0
rebase
jayzhan211 f70e1e6
move doc
jayzhan211 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,19 @@ use std::collections::HashMap; | |
use std::sync::Arc; | ||
|
||
use arrow::datatypes::{DataType, Field, Schema, SchemaRef, TimeUnit}; | ||
use arrow_schema::{Fields, SchemaBuilder}; | ||
use datafusion_common::config::ConfigOptions; | ||
use datafusion_common::{plan_err, Result}; | ||
use datafusion_expr::{AggregateUDF, LogicalPlan, ScalarUDF, TableSource, WindowUDF}; | ||
use datafusion_common::tree_node::{TransformedResult, TreeNode}; | ||
use datafusion_common::{plan_err, DFSchema, Result, ScalarValue}; | ||
use datafusion_expr::interval_arithmetic::{Interval, NullableInterval}; | ||
use datafusion_expr::{ | ||
col, lit, AggregateUDF, BinaryExpr, Expr, ExprSchemable, LogicalPlan, Operator, | ||
ScalarUDF, TableSource, WindowUDF, | ||
}; | ||
use datafusion_functions::core::expr_ext::FieldAccessor; | ||
use datafusion_optimizer::analyzer::Analyzer; | ||
use datafusion_optimizer::optimizer::Optimizer; | ||
use datafusion_optimizer::simplify_expressions::GuaranteeRewriter; | ||
use datafusion_optimizer::{OptimizerConfig, OptimizerContext}; | ||
use datafusion_sql::planner::{ContextProvider, SqlToRel}; | ||
use datafusion_sql::sqlparser::ast::Statement; | ||
|
@@ -233,3 +241,120 @@ impl TableSource for MyTableSource { | |
self.schema.clone() | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_nested_schema_nullability() { | ||
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. Move tests that use functions to core/tests |
||
let mut builder = SchemaBuilder::new(); | ||
builder.push(Field::new("foo", DataType::Int32, true)); | ||
builder.push(Field::new( | ||
"parent", | ||
DataType::Struct(Fields::from(vec![Field::new( | ||
"child", | ||
DataType::Int64, | ||
false, | ||
)])), | ||
true, | ||
)); | ||
let schema = builder.finish(); | ||
|
||
let dfschema = DFSchema::from_field_specific_qualified_schema( | ||
vec![Some("table_name".into()), None], | ||
&Arc::new(schema), | ||
) | ||
.unwrap(); | ||
|
||
let expr = col("parent").field("child"); | ||
assert!(expr.nullable(&dfschema).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_inequalities_non_null_bounded() { | ||
let guarantees = vec![ | ||
// x ∈ [1, 3] (not null) | ||
( | ||
col("x"), | ||
NullableInterval::NotNull { | ||
values: Interval::make(Some(1_i32), Some(3_i32)).unwrap(), | ||
}, | ||
), | ||
// s.y ∈ [1, 3] (not null) | ||
( | ||
col("s").field("y"), | ||
NullableInterval::NotNull { | ||
values: Interval::make(Some(1_i32), Some(3_i32)).unwrap(), | ||
}, | ||
), | ||
]; | ||
|
||
let mut rewriter = GuaranteeRewriter::new(guarantees.iter()); | ||
|
||
// (original_expr, expected_simplification) | ||
let simplified_cases = &[ | ||
(col("x").lt(lit(0)), false), | ||
(col("s").field("y").lt(lit(0)), false), | ||
(col("x").lt_eq(lit(3)), true), | ||
(col("x").gt(lit(3)), false), | ||
(col("x").gt(lit(0)), true), | ||
(col("x").eq(lit(0)), false), | ||
(col("x").not_eq(lit(0)), true), | ||
(col("x").between(lit(0), lit(5)), true), | ||
(col("x").between(lit(5), lit(10)), false), | ||
(col("x").not_between(lit(0), lit(5)), false), | ||
(col("x").not_between(lit(5), lit(10)), true), | ||
( | ||
Expr::BinaryExpr(BinaryExpr { | ||
left: Box::new(col("x")), | ||
op: Operator::IsDistinctFrom, | ||
right: Box::new(lit(ScalarValue::Null)), | ||
}), | ||
true, | ||
), | ||
( | ||
Expr::BinaryExpr(BinaryExpr { | ||
left: Box::new(col("x")), | ||
op: Operator::IsDistinctFrom, | ||
right: Box::new(lit(5)), | ||
}), | ||
true, | ||
), | ||
]; | ||
|
||
validate_simplified_cases(&mut rewriter, simplified_cases); | ||
|
||
let unchanged_cases = &[ | ||
col("x").gt(lit(2)), | ||
col("x").lt_eq(lit(2)), | ||
col("x").eq(lit(2)), | ||
col("x").not_eq(lit(2)), | ||
col("x").between(lit(3), lit(5)), | ||
col("x").not_between(lit(3), lit(10)), | ||
]; | ||
|
||
validate_unchanged_cases(&mut rewriter, unchanged_cases); | ||
} | ||
|
||
fn validate_simplified_cases<T>(rewriter: &mut GuaranteeRewriter, cases: &[(Expr, T)]) | ||
where | ||
ScalarValue: From<T>, | ||
T: Clone, | ||
{ | ||
for (expr, expected_value) in cases { | ||
let output = expr.clone().rewrite(rewriter).data().unwrap(); | ||
let expected = lit(ScalarValue::from(expected_value.clone())); | ||
assert_eq!( | ||
output, expected, | ||
"{} simplified to {}, but expected {}", | ||
expr, output, expected | ||
); | ||
} | ||
} | ||
fn validate_unchanged_cases(rewriter: &mut GuaranteeRewriter, cases: &[Expr]) { | ||
for expr in cases { | ||
let output = expr.clone().rewrite(rewriter).data().unwrap(); | ||
assert_eq!( | ||
&output, expr, | ||
"{} was simplified to {}, but expected it to be unchanged", | ||
expr, output | ||
); | ||
} | ||
} |
Oops, something went wrong.
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.
nice!