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(binder): support current_timestamp #7695

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 src/frontend/planner_test/tests/testdata/sysinfo_funcs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
binder_error: |-
Feature is not yet implemented: Only boolean literals are supported in `current_schemas`.
No tracking issue yet. Feel free to submit a feature request at https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Ffeature&template=feature_request.yml
- sql: |
select current_timestamp;
batch_plan: |-
BatchProject { exprs: [Now] }
└─BatchValues { rows: [[]] }
24 changes: 14 additions & 10 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ impl Binder {
fn raw_literal(literal: ExprImpl) -> Handle {
Box::new(move |_binder, _inputs| Ok(literal.clone()))
}
fn now() -> Handle {
Box::new(move |binder, mut inputs| {
binder.ensure_now_function_allowed()?;
if !binder.in_create_mv {
inputs.push(ExprImpl::from(Literal::new(
Some(ScalarImpl::Int64((binder.bind_timestamp_ms * 1000) as i64)),
DataType::Timestamptz,
)));
}
raw_call(ExprType::Now)(binder, inputs)
})
}

static HANDLES: LazyLock<HashMap<&'static str, Handle>> = LazyLock::new(|| {
[
Expand Down Expand Up @@ -497,16 +509,8 @@ impl Binder {
RW_VERSION
)))),
// non-deterministic
("now", raw(|binder, mut inputs|{
binder.ensure_now_function_allowed()?;
if !binder.in_create_mv {
inputs.push(ExprImpl::from(Literal::new(
Some(ScalarImpl::Int64((binder.bind_timestamp_ms * 1000) as i64)),
DataType::Timestamptz,
)));
}
raw_call(ExprType::Now)(binder, inputs)
}))
("now", now()),
("current_timestamp", now())
]
.into_iter()
.collect()
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Binder {
Expr::Row(exprs) => self.bind_row(exprs),
// input ref
Expr::Identifier(ident) => {
if ["session_user", "current_schema"]
if ["session_user", "current_schema", "current_timestamp"]
.iter()
.any(|e| ident.real_value().as_str() == *e)
{
Expand Down