-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add a
TypeCheckRule
to the optimizer (#20425)
- Loading branch information
1 parent
93ceacc
commit 9ea5839
Showing
21 changed files
with
240 additions
and
99 deletions.
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
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
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,48 @@ | ||
use polars_core::error::{polars_ensure, PolarsResult}; | ||
use polars_core::prelude::DataType; | ||
use polars_utils::arena::{Arena, Node}; | ||
|
||
use super::{AExpr, OptimizationRule, IR}; | ||
use crate::plans::conversion::get_schema; | ||
use crate::plans::Context; | ||
|
||
pub struct TypeCheckRule; | ||
|
||
impl OptimizationRule for TypeCheckRule { | ||
fn optimize_plan( | ||
&mut self, | ||
ir_arena: &mut Arena<IR>, | ||
expr_arena: &mut Arena<AExpr>, | ||
node: Node, | ||
) -> PolarsResult<Option<IR>> { | ||
let ir = ir_arena.get(node); | ||
match ir { | ||
IR::Scan { | ||
predicate: Some(predicate), | ||
.. | ||
} => { | ||
let input_schema = get_schema(ir_arena, node); | ||
let dtype = predicate.dtype(input_schema.as_ref(), Context::Default, expr_arena)?; | ||
|
||
polars_ensure!( | ||
matches!(dtype, DataType::Boolean | DataType::Unknown(_)), | ||
InvalidOperation: "filter predicate must be of type `Boolean`, got `{dtype:?}`" | ||
); | ||
|
||
Ok(None) | ||
}, | ||
IR::Filter { predicate, .. } => { | ||
let input_schema = get_schema(ir_arena, node); | ||
let dtype = predicate.dtype(input_schema.as_ref(), Context::Default, expr_arena)?; | ||
|
||
polars_ensure!( | ||
matches!(dtype, DataType::Boolean | DataType::Unknown(_)), | ||
InvalidOperation: "filter predicate must be of type `Boolean`, got `{dtype:?}`" | ||
); | ||
|
||
Ok(None) | ||
}, | ||
_ => Ok(None), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.