-
-
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.
- Loading branch information
Showing
13 changed files
with
284 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 @@ | ||
pub mod predicate; | ||
pub mod pyarrow; |
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,69 @@ | ||
use polars_core::error::polars_err; | ||
use polars_core::prelude::PolarsResult; | ||
|
||
use crate::prelude::*; | ||
|
||
fn accept_as_io_predicate(e: &Expr) -> bool { | ||
const LIMIT: usize = 1 << 16; | ||
match e { | ||
Expr::Literal(lv) => match lv { | ||
LiteralValue::Binary(v) => v.len() <= LIMIT, | ||
LiteralValue::String(v) => v.len() <= LIMIT, | ||
LiteralValue::Series(s) => s.estimated_size() < LIMIT, | ||
// Don't accept dynamic types | ||
LiteralValue::Int(_) => false, | ||
LiteralValue::Float(_) => false, | ||
_ => true, | ||
}, | ||
Expr::Wildcard | Expr::Column(_) => true, | ||
Expr::BinaryExpr { left, right, .. } => { | ||
accept_as_io_predicate(left) && accept_as_io_predicate(right) | ||
}, | ||
Expr::Ternary { | ||
truthy, | ||
falsy, | ||
predicate, | ||
} => { | ||
accept_as_io_predicate(truthy) | ||
&& accept_as_io_predicate(falsy) | ||
&& accept_as_io_predicate(predicate) | ||
}, | ||
Expr::Alias(_, _) => true, | ||
Expr::Function { | ||
function, input, .. | ||
} => { | ||
match function { | ||
// we already checked if streaming, so we can all functions | ||
FunctionExpr::Boolean(_) | FunctionExpr::BinaryExpr(_) | FunctionExpr::Coalesce => { | ||
}, | ||
#[cfg(feature = "log")] | ||
FunctionExpr::Entropy { .. } | ||
| FunctionExpr::Log { .. } | ||
| FunctionExpr::Log1p { .. } | ||
| FunctionExpr::Exp { .. } => {}, | ||
#[cfg(feature = "abs")] | ||
FunctionExpr::Abs => {}, | ||
#[cfg(feature = "trigonometry")] | ||
FunctionExpr::Atan2 => {}, | ||
#[cfg(feature = "round_series")] | ||
FunctionExpr::Clip { .. } => {}, | ||
#[cfg(feature = "fused")] | ||
FunctionExpr::Fused(_) => {}, | ||
_ => return false, | ||
} | ||
input.iter().all(accept_as_io_predicate) | ||
}, | ||
_ => false, | ||
} | ||
} | ||
|
||
pub fn serialize(expr: &Expr) -> PolarsResult<Option<Vec<u8>>> { | ||
if !accept_as_io_predicate(expr) { | ||
return Ok(None); | ||
} | ||
let mut buf = vec![]; | ||
ciborium::into_writer(expr, &mut buf) | ||
.map_err(|_| polars_err!(ComputeError: "could not serialize: {}", expr))?; | ||
|
||
Ok(Some(buf)) | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.