Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support current_catalog sys function #18037

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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 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
Loading