Skip to content

Commit

Permalink
feat: support current_catalog sys function (#18037)
Browse files Browse the repository at this point in the history
  • Loading branch information
yezizp2012 authored Aug 14, 2024
1 parent bd664bb commit 3043efd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions e2e_test/batch/basic/func.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ select count(current_database());
----
1

query I
select count(current_catalog);
----
1

query T
select regexp_match('abc', 'bc');
----
Expand Down
14 changes: 11 additions & 3 deletions src/frontend/src/binder/expr/function/builtin_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ impl Binder {
)
}

// `CURRENT_DATABASE` is the name of the database you are currently connected to.
// `CURRENT_CATALOG` is a synonym for `CURRENT_DATABASE`.
fn current_database() -> Handle {
guard_by_len(
0,
raw(|binder, _inputs| Ok(ExprImpl::literal_varchar(binder.db_name.clone()))),
)
}

// XXX: can we unify this with FUNC_SIG_MAP?
// For raw_call here, it seems unnecessary to declare it again here.
// For some functions, we have validation logic here. Is it still useful now?
Expand Down Expand Up @@ -410,9 +419,8 @@ impl Binder {
Ok(ExprImpl::literal_varchar(v))
})),
),
("current_database", guard_by_len(0, raw(|binder, _inputs| {
Ok(ExprImpl::literal_varchar(binder.db_name.clone()))
}))),
("current_catalog", current_database()),
("current_database", current_database()),
("current_schema", guard_by_len(0, raw(|binder, _inputs| {
return Ok(binder
.first_valid_schema()
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/binder/expr/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const SYS_FUNCTION_WITHOUT_ARGS: &[&str] = &[
"user",
"current_user",
"current_role",
"current_catalog",
"current_schema",
"current_timestamp",
];
Expand Down

0 comments on commit 3043efd

Please sign in to comment.