Path: blob/main/crates/polars-plan/src/plans/aexpr/function_expr/binary.rs
7889 views
use super::*;12#[cfg_attr(feature = "ir_serde", derive(serde::Serialize, serde::Deserialize))]3#[derive(Clone, PartialEq, Debug, Eq, Hash)]4pub enum IRBinaryFunction {5Contains,6StartsWith,7EndsWith,8#[cfg(feature = "binary_encoding")]9HexDecode(bool),10#[cfg(feature = "binary_encoding")]11HexEncode,12#[cfg(feature = "binary_encoding")]13Base64Decode(bool),14#[cfg(feature = "binary_encoding")]15Base64Encode,16Size,17#[cfg(feature = "binary_encoding")]18Reinterpret(DataType, bool),19Slice,20Head,21Tail,22}2324impl IRBinaryFunction {25pub(super) fn get_field(&self, mapper: FieldsMapper) -> PolarsResult<Field> {26use IRBinaryFunction::*;27match self {28Contains => mapper.with_dtype(DataType::Boolean),29EndsWith | StartsWith => mapper.with_dtype(DataType::Boolean),30#[cfg(feature = "binary_encoding")]31HexDecode(_) | Base64Decode(_) => mapper.with_same_dtype(),32#[cfg(feature = "binary_encoding")]33HexEncode | Base64Encode => mapper.with_dtype(DataType::String),34Size => mapper.with_dtype(DataType::UInt32),35#[cfg(feature = "binary_encoding")]36Reinterpret(dtype, _) => mapper.with_dtype(dtype.clone()),37Slice | Head | Tail => mapper.with_same_dtype(),38}39}4041pub fn function_options(&self) -> FunctionOptions {42use IRBinaryFunction as B;43match self {44B::Contains | B::StartsWith | B::EndsWith => {45FunctionOptions::elementwise().with_supertyping(Default::default())46},47B::Size => FunctionOptions::elementwise(),48#[cfg(feature = "binary_encoding")]49B::HexDecode(_)50| B::HexEncode51| B::Base64Decode(_)52| B::Base64Encode53| B::Reinterpret(_, _) => FunctionOptions::elementwise(),54B::Slice | B::Head | B::Tail => FunctionOptions::elementwise(),55}56}57}5859impl Display for IRBinaryFunction {60fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {61use IRBinaryFunction::*;62let s = match self {63Contains => "contains",64StartsWith => "starts_with",65EndsWith => "ends_with",66#[cfg(feature = "binary_encoding")]67HexDecode(_) => "hex_decode",68#[cfg(feature = "binary_encoding")]69HexEncode => "hex_encode",70#[cfg(feature = "binary_encoding")]71Base64Decode(_) => "base64_decode",72#[cfg(feature = "binary_encoding")]73Base64Encode => "base64_encode",74Size => "size_bytes",75#[cfg(feature = "binary_encoding")]76Reinterpret(_, _) => "reinterpret",77Slice => "slice",78Head => "head",79Tail => "tail",80};81write!(f, "bin.{s}")82}83}8485impl From<IRBinaryFunction> for IRFunctionExpr {86fn from(b: IRBinaryFunction) -> Self {87IRFunctionExpr::BinaryExpr(b)88}89}909192