Skip to content

Commit d176c58

Browse files
authored
Implement regexp_substr (#6)
* Extend references with new SHowSchemas type Make resolve_table_ref as pub Fix docs linter Add DDL AlterTable Add DDL AlterTable Add "rlike" as an alias for regexp_like (#2) * Add "rlike" as an alias for regexp_like * Update docs Extend references with new ShowSchemas type (#4) * Extend references with new SHowSchemas type * Make resolve_table_ref as pub * Fix docs linter Fix deps Import alter table Temp Temp Add regexp_substr udf Add regexp_substr udf Add regexp_substr udf Add regexp_substr udf * Add regexp_substr to docs * Update comments and fix returned datatype * Update docs
1 parent cc37c59 commit d176c58

File tree

3 files changed

+627
-0
lines changed

3 files changed

+627
-0
lines changed

datafusion/functions/src/regex/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ pub mod regexpcount;
2323
pub mod regexplike;
2424
pub mod regexpmatch;
2525
pub mod regexpreplace;
26+
pub mod regexpsubstr;
2627

2728
// create UDFs
2829
make_udf_function!(regexpcount::RegexpCountFunc, regexp_count);
2930
make_udf_function!(regexpmatch::RegexpMatchFunc, regexp_match);
3031
make_udf_function!(regexplike::RegexpLikeFunc, regexp_like);
3132
make_udf_function!(regexpreplace::RegexpReplaceFunc, regexp_replace);
33+
make_udf_function!(regexpsubstr::RegexpSubstrFunc, regexp_substr);
3234

3335
pub mod expr_fn {
3436
use datafusion_expr::Expr;
@@ -60,6 +62,31 @@ pub mod expr_fn {
6062
super::regexp_match().call(args)
6163
}
6264

65+
/// Returns the substring that matches a regular expression within a string.
66+
pub fn regexp_substr(
67+
values: Expr,
68+
regex: Expr,
69+
start: Option<Expr>,
70+
occurrence: Option<Expr>,
71+
flags: Option<Expr>,
72+
group_num: Option<Expr>,
73+
) -> Expr {
74+
let mut args = vec![values, regex];
75+
if let Some(start) = start {
76+
args.push(start);
77+
};
78+
if let Some(occurrence) = occurrence {
79+
args.push(occurrence);
80+
};
81+
if let Some(flags) = flags {
82+
args.push(flags);
83+
};
84+
if let Some(group_num) = group_num {
85+
args.push(group_num);
86+
};
87+
super::regexp_substr().call(args)
88+
}
89+
6390
/// Returns true if a has at least one match in a string, false otherwise.
6491
pub fn regexp_like(values: Expr, regex: Expr, flags: Option<Expr>) -> Expr {
6592
let mut args = vec![values, regex];
@@ -91,5 +118,6 @@ pub fn functions() -> Vec<Arc<datafusion_expr::ScalarUDF>> {
91118
regexp_match(),
92119
regexp_like(),
93120
regexp_replace(),
121+
regexp_substr(),
94122
]
95123
}

0 commit comments

Comments
 (0)