Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/extension.rs
7889 views
1
use super::*;
2
3
#[cfg_attr(feature = "ir_serde", derive(serde::Serialize, serde::Deserialize))]
4
#[derive(Clone, PartialEq, Debug, Eq, Hash)]
5
pub enum IRExtensionFunction {
6
To(DataType),
7
Storage,
8
}
9
10
impl IRExtensionFunction {
11
pub(super) fn get_field(&self, mapper: FieldsMapper) -> PolarsResult<Field> {
12
use IRExtensionFunction::*;
13
match self {
14
To(dtype) => mapper.with_dtype(dtype.clone()),
15
Storage => mapper.map_dtype(|dt| match dt {
16
DataType::Extension(_, storage) => (**storage).clone(),
17
dt => dt.clone(),
18
}),
19
}
20
}
21
22
pub fn function_options(&self) -> FunctionOptions {
23
use IRExtensionFunction::*;
24
match self {
25
To(_dtype) => FunctionOptions::elementwise(),
26
Storage => FunctionOptions::elementwise(),
27
}
28
}
29
}
30
31
impl Display for IRExtensionFunction {
32
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33
use IRExtensionFunction::*;
34
match self {
35
To(dtype) => write!(f, "ext.to({dtype:?})"),
36
Storage => write!(f, "ext.storage()"),
37
}
38
}
39
}
40
41
impl From<IRExtensionFunction> for IRFunctionExpr {
42
fn from(func: IRExtensionFunction) -> Self {
43
IRFunctionExpr::Extension(func)
44
}
45
}
46
47