Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions datafusion/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ rust-version = { workspace = true }
default = ["encoding_expressions"]
# enable the encode/decode functions
encoding_expressions = ["base64", "hex"]
# enable regexp_match/regexp_replace functions
regex_expressions = ["regex", "hashbrown"]



[lib]
Expand All @@ -49,3 +52,5 @@ datafusion-execution = { workspace = true }
datafusion-expr = { workspace = true }
hex = { version = "0.4", optional = true }
log = "0.4.20"
regex = { version = "1.8", optional = true }
hashbrown = { version = "0.14", features = ["raw"], optional = true }
7 changes: 7 additions & 0 deletions datafusion/functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ make_package!(
"Hex and binary `encode` and `decode` functions."
);

make_package!(
regex,
"regex_expressions",
"Regular Expressions `regexp_match` and `regexp_replace` functions."
);


/// Fluent-style API for creating `Expr`s
pub mod expr_fn {
#[cfg(feature = "encoding_expressions")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@

//! Regex expressions

use arrow::array::{
new_null_array, Array, ArrayDataBuilder, ArrayRef, BufferBuilder, GenericStringArray,
OffsetSizeTrait,
};
use arrow_array::builder::{GenericStringBuilder, ListBuilder};
use arrow_schema::ArrowError;
use arrow::array::{new_null_array, Array, ArrayDataBuilder, ArrayRef, BufferBuilder, GenericStringArray, OffsetSizeTrait, GenericStringBuilder, ListBuilder};
use datafusion_common::{arrow_datafusion_err, plan_err};
use datafusion_common::{
cast::as_generic_string_array, internal_err, DataFusionError, Result,
Expand All @@ -35,10 +30,8 @@ use datafusion_expr::{ColumnarValue, ScalarFunctionImplementation};
use hashbrown::HashMap;
use regex::Regex;
use std::sync::{Arc, OnceLock};
use arrow::error::ArrowError;

use crate::functions::{
make_scalar_function_inner, make_scalar_function_with_hints, Hint,
};

/// Get the first argument from the given string array.
///
Expand Down
30 changes: 30 additions & 0 deletions datafusion/functions/src/regex/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

mod inner;


// create UDFs
make_udf_function!(inner::RegexpMatch, REGEXP_MATCH, regexp_match);
make_udf_function!(inner::RegexpReplace, REGEXP_REPLACE, regexp_replace);

// Export the functions out of this package, both as expr_fn as well as a list of functions
export_functions!(
(regexp_match, input encoding, "encode the `input`, using the `encoding`. encoding can be base64 or hex"),
(regexp_replace, input encoding, "decode the `input`, using the `encoding`. encoding can be base64 or hex")
);