Path: blob/main/crates/polars-plan/src/dsl/function_expr/strings.rs
6940 views
#[cfg(feature = "serde")]1use serde::{Deserialize, Serialize};23use super::*;45#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]6#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]7#[derive(Clone, PartialEq, Debug, Hash)]8pub enum StringFunction {9#[cfg(feature = "concat_str")]10ConcatHorizontal {11delimiter: PlSmallStr,12ignore_nulls: bool,13},14#[cfg(feature = "concat_str")]15ConcatVertical {16delimiter: PlSmallStr,17ignore_nulls: bool,18},19#[cfg(feature = "regex")]20Contains {21literal: bool,22strict: bool,23},24CountMatches(bool),25EndsWith,26Extract(usize),27ExtractAll,28#[cfg(feature = "extract_groups")]29ExtractGroups {30dtype: DataType,31pat: PlSmallStr,32},33#[cfg(feature = "regex")]34Find {35literal: bool,36strict: bool,37},38#[cfg(feature = "string_to_integer")]39ToInteger {40dtype: Option<DataType>,41strict: bool,42},43LenBytes,44LenChars,45Lowercase,46#[cfg(feature = "extract_jsonpath")]47JsonDecode(DataTypeExpr),48#[cfg(feature = "extract_jsonpath")]49JsonPathMatch,50#[cfg(feature = "regex")]51Replace {52// negative is replace all53// how many matches to replace54n: i64,55literal: bool,56},57#[cfg(feature = "string_normalize")]58Normalize {59form: UnicodeForm,60},61#[cfg(feature = "string_reverse")]62Reverse,63#[cfg(feature = "string_pad")]64PadStart {65fill_char: char,66},67#[cfg(feature = "string_pad")]68PadEnd {69fill_char: char,70},71Slice,72Head,73Tail,74#[cfg(feature = "string_encoding")]75HexEncode,76#[cfg(feature = "binary_encoding")]77HexDecode(bool),78#[cfg(feature = "string_encoding")]79Base64Encode,80#[cfg(feature = "binary_encoding")]81Base64Decode(bool),82StartsWith,83StripChars,84StripCharsStart,85StripCharsEnd,86StripPrefix,87StripSuffix,88#[cfg(feature = "dtype-struct")]89SplitExact {90n: usize,91inclusive: bool,92},93#[cfg(feature = "dtype-struct")]94SplitN(usize),95#[cfg(feature = "temporal")]96Strptime(DataTypeExpr, StrptimeOptions),97Split(bool),98#[cfg(feature = "dtype-decimal")]99ToDecimal {100scale: usize,101},102#[cfg(feature = "nightly")]103Titlecase,104Uppercase,105#[cfg(feature = "string_pad")]106ZFill,107#[cfg(feature = "find_many")]108ContainsAny {109ascii_case_insensitive: bool,110},111#[cfg(feature = "find_many")]112ReplaceMany {113ascii_case_insensitive: bool,114},115#[cfg(feature = "find_many")]116ExtractMany {117ascii_case_insensitive: bool,118overlapping: bool,119},120#[cfg(feature = "find_many")]121FindMany {122ascii_case_insensitive: bool,123overlapping: bool,124},125#[cfg(feature = "regex")]126EscapeRegex,127}128129impl Display for StringFunction {130fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {131use StringFunction::*;132let s = match self {133#[cfg(feature = "regex")]134Contains { .. } => "contains",135CountMatches(_) => "count_matches",136EndsWith => "ends_with",137Extract(_) => "extract",138#[cfg(feature = "concat_str")]139ConcatHorizontal { .. } => "concat_horizontal",140#[cfg(feature = "concat_str")]141ConcatVertical { .. } => "concat_vertical",142ExtractAll => "extract_all",143#[cfg(feature = "extract_groups")]144ExtractGroups { .. } => "extract_groups",145#[cfg(feature = "string_to_integer")]146ToInteger { .. } => "to_integer",147#[cfg(feature = "regex")]148Find { .. } => "find",149Head => "head",150Tail => "tail",151#[cfg(feature = "extract_jsonpath")]152JsonDecode { .. } => "json_decode",153#[cfg(feature = "extract_jsonpath")]154JsonPathMatch => "json_path_match",155LenBytes => "len_bytes",156Lowercase => "lowercase",157LenChars => "len_chars",158#[cfg(feature = "string_pad")]159PadEnd { .. } => "pad_end",160#[cfg(feature = "string_pad")]161PadStart { .. } => "pad_start",162#[cfg(feature = "regex")]163Replace { .. } => "replace",164#[cfg(feature = "string_normalize")]165Normalize { .. } => "normalize",166#[cfg(feature = "string_reverse")]167Reverse => "reverse",168#[cfg(feature = "string_encoding")]169HexEncode => "hex_encode",170#[cfg(feature = "binary_encoding")]171HexDecode(_) => "hex_decode",172#[cfg(feature = "string_encoding")]173Base64Encode => "base64_encode",174#[cfg(feature = "binary_encoding")]175Base64Decode(_) => "base64_decode",176Slice => "slice",177StartsWith => "starts_with",178StripChars => "strip_chars",179StripCharsStart => "strip_chars_start",180StripCharsEnd => "strip_chars_end",181StripPrefix => "strip_prefix",182StripSuffix => "strip_suffix",183#[cfg(feature = "dtype-struct")]184SplitExact { inclusive, .. } => {185if *inclusive {186"split_exact_inclusive"187} else {188"split_exact"189}190},191#[cfg(feature = "dtype-struct")]192SplitN(_) => "splitn",193#[cfg(feature = "temporal")]194Strptime(_, _) => "strptime",195Split(inclusive) => {196if *inclusive {197"split_inclusive"198} else {199"split"200}201},202#[cfg(feature = "nightly")]203Titlecase => "titlecase",204#[cfg(feature = "dtype-decimal")]205ToDecimal { .. } => "to_decimal",206Uppercase => "uppercase",207#[cfg(feature = "string_pad")]208ZFill => "zfill",209#[cfg(feature = "find_many")]210ContainsAny { .. } => "contains_any",211#[cfg(feature = "find_many")]212ReplaceMany { .. } => "replace_many",213#[cfg(feature = "find_many")]214ExtractMany { .. } => "extract_many",215#[cfg(feature = "find_many")]216FindMany { .. } => "extract_many",217#[cfg(feature = "regex")]218EscapeRegex => "escape_regex",219};220write!(f, "str.{s}")221}222}223224impl From<StringFunction> for FunctionExpr {225fn from(value: StringFunction) -> Self {226FunctionExpr::StringExpr(value)227}228}229230231