Skip to content

Commit 8f5ed6b

Browse files
committed
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
1 parent bc5a978 commit 8f5ed6b

File tree

6 files changed

+582
-4
lines changed

6 files changed

+582
-4
lines changed

datafusion/core/src/catalog_common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ pub fn resolve_table_references(
156156
| Statement::ShowColumns { .. }
157157
| Statement::ShowTables { .. }
158158
| Statement::ShowCollation { .. }
159+
| Statement::ShowSchemas { .. }
160+
| Statement::ShowDatabases { .. }
159161
);
160162
if requires_information_schema {
161163
for s in INFORMATION_SCHEMA_TABLES {

datafusion/core/src/execution/session_state.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ impl SessionState {
285285
.build()
286286
}
287287

288-
pub(crate) fn resolve_table_ref(
288+
/// Resolves a [`TableReference`] to a [`ResolvedTableReference`]
289+
/// using the default catalog and schema.
290+
pub fn resolve_table_ref(
289291
&self,
290292
table_ref: impl Into<TableReference>,
291293
) -> ResolvedTableReference {
@@ -845,9 +847,9 @@ impl SessionState {
845847
overwrite: bool,
846848
) -> Result<(), DataFusionError> {
847849
let ext = file_format.get_ext().to_lowercase();
848-
match (self.file_formats.entry(ext.clone()), overwrite){
849-
(Entry::Vacant(e), _) => {e.insert(file_format);},
850-
(Entry::Occupied(mut e), true) => {e.insert(file_format);},
850+
match (self.file_formats.entry(ext.clone()), overwrite) {
851+
(Entry::Vacant(e), _) => { e.insert(file_format); }
852+
(Entry::Occupied(mut e), true) => { e.insert(file_format); }
851853
(Entry::Occupied(_), false) => return config_err!("File type already registered for extension {ext}. Set overwrite to true to replace this extension."),
852854
};
853855
Ok(())

datafusion/functions/src/regex/mod.rs

Lines changed: 27 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];

datafusion/functions/src/regex/regexplike.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::sync::{Arc, OnceLock};
3535
#[derive(Debug)]
3636
pub struct RegexpLikeFunc {
3737
signature: Signature,
38+
aliases: Vec<String>,
3839
}
3940

4041
impl Default for RegexpLikeFunc {
@@ -84,6 +85,7 @@ impl RegexpLikeFunc {
8485
vec![TypeSignature::String(2), TypeSignature::String(3)],
8586
Volatility::Immutable,
8687
),
88+
aliases: vec![String::from("rlike")],
8789
}
8890
}
8991
}
@@ -112,6 +114,10 @@ impl ScalarUDFImpl for RegexpLikeFunc {
112114
})
113115
}
114116

117+
fn aliases(&self) -> &[String] {
118+
&self.aliases
119+
}
120+
115121
fn invoke_batch(
116122
&self,
117123
args: &[ColumnarValue],

0 commit comments

Comments
 (0)