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