Skip to content

Commit

Permalink
rename proctime
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao-su committed Apr 11, 2023
1 parent fd16158 commit 4459f34
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ message ExprNode {
VNODE = 1101;
// Non-deterministic functions
NOW = 2022;
PROC_TIME = 2023;
proctime = 2023;
// User defined functions
UDF = 3000;
}
Expand Down
4 changes: 2 additions & 2 deletions src/expr/src/expr/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use super::expr_regexp::RegexpMatchExpression;
use super::expr_some_all::SomeAllExpression;
use super::expr_udf::UdfExpression;
use super::expr_vnode::VnodeExpression;
use crate::expr::expr_proc_time::ProcTimeExpression;
use crate::expr::expr_proctime::ProcTimeExpression;
use crate::expr::{BoxedExpression, Expression, InputRefExpression, LiteralExpression};
use crate::sig::func::FUNC_SIG_MAP;
use crate::{bail, ExprError, Result};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn build_from_prost(prost: &ExprNode) -> Result<BoxedExpression> {
}
E::Vnode => VnodeExpression::try_from(prost).map(Expression::boxed),
E::Udf => UdfExpression::try_from(prost).map(Expression::boxed),
E::ProcTime => ProcTimeExpression::try_from(prost).map(Expression::boxed),
E::Proctime => ProcTimeExpression::try_from(prost).map(Expression::boxed),
_ => Err(ExprError::UnsupportedFunction(format!(
"{:?}",
prost.get_expr_type()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> TryFrom<&'a ExprNode> for ProcTimeExpression {
type Error = ExprError;

fn try_from(prost: &'a ExprNode) -> Result<Self> {
ensure!(prost.get_expr_type().unwrap() == Type::ProcTime);
ensure!(prost.get_expr_type().unwrap() == Type::Proctime);
ensure!(DataType::from(prost.get_return_type().unwrap()) == DataType::Timestamptz);
let RexNode::FuncCall(func_call_node) = prost.get_rex_node().unwrap() else {
bail!("Expected RexNode::FuncCall");
Expand All @@ -52,10 +52,10 @@ impl Expression for ProcTimeExpression {
}

async fn eval_v2(&self, input: &DataChunk) -> Result<ValueImpl> {
let proc_time = CONTEXT
let proctime = CONTEXT
.try_with(|context| context.get_physical_time())
.map_err(|_| ExprError::Context)?;
let datum = Some(ScalarImpl::Int64(proc_time as i64));
let datum = Some(ScalarImpl::Int64(proctime as i64));

Ok(ValueImpl::Scalar {
value: datum,
Expand All @@ -64,10 +64,10 @@ impl Expression for ProcTimeExpression {
}

async fn eval_row(&self, _input: &OwnedRow) -> Result<Datum> {
let proc_time = CONTEXT
let proctime = CONTEXT
.try_with(|context| context.get_physical_time())
.map_err(|_| ExprError::Context)?;
let datum = Some(ScalarImpl::Int64(proc_time as i64));
let datum = Some(ScalarImpl::Int64(proctime as i64));

Ok(datum)
}
Expand All @@ -83,16 +83,16 @@ mod tests {
use crate::expr::{ExprContext, CONTEXT};

#[tokio::test]
async fn test_expr_proc_time() {
let proc_time_expr = ProcTimeExpression::new();
async fn test_expr_proctime() {
let proctime_expr = ProcTimeExpression::new();
let epoch = Epoch::now();
let time = epoch.physical_time();
let time_datum = Some(ScalarRefImpl::Int64(time as i64));
let context = ExprContext::new(epoch);
let chunk = DataChunk::new_dummy(3);

let array = CONTEXT
.scope(context, proc_time_expr.eval(&chunk))
.scope(context, proctime_expr.eval(&chunk))
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/expr/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod expr_jsonb_access;
mod expr_literal;
mod expr_nested_construct;
mod expr_now;
mod expr_proc_time;
mod expr_proctime;
pub mod expr_regexp;
mod expr_some_all;
mod expr_to_char_const_tmpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BatchExchange { order: [], dist: Single }
└─BatchProject { exprs: [(v2 + 1:Int32) as $expr1] }
└─BatchSource { source: "s1", columns: ["v2", "_row_id"], filter: (None, None) }
- name: select proc_time()
- name: select proctime()
sql: |
select proc_time();
binder_error: 'Invalid input syntax: Function `PROC_TIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?'
select proctime();
binder_error: 'Invalid input syntax: Function `PROCTIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?'
4 changes: 1 addition & 3 deletions src/frontend/planner_test/tests/testdata/nexmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,7 @@
TUMBLE_END(B.p_time, INTERVAL '10' SECOND) as endtime
FROM (SELECT *, PROCTIME() as p_time FROM bid) B
GROUP BY B.bidder, TUMBLE(B.p_time, INTERVAL '10' SECOND);
binder_error: |-
Feature is not yet implemented: unsupported function "proctime", do you mean "proc_time"?
Tracking issue: https://github.com/risingwavelabs/risingwave/issues/112
binder_error: 'Invalid input syntax: Function `PROCTIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?'
- id: nexmark_q13
before:
- create_tables
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/planner_test/tests/testdata/nexmark_source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,7 @@
TUMBLE_END(B.p_time, INTERVAL '10' SECOND) as endtime
FROM (SELECT *, PROCTIME() as p_time FROM bid) B
GROUP BY B.bidder, TUMBLE(B.p_time, INTERVAL '10' SECOND);
binder_error: |-
Feature is not yet implemented: unsupported function "proctime", do you mean "proc_time"?
Tracking issue: https://github.com/risingwavelabs/risingwave/issues/112
binder_error: 'Invalid input syntax: Function `PROCTIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?'
- id: nexmark_q13
before:
- create_sources
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ impl Binder {
raw_literal(ExprImpl::literal_f64(std::f64::consts::PI))
}

fn proc_time() -> Handle {
fn proctime() -> Handle {
Box::new(move |binder, inputs| {
binder.ensure_proc_time_function_allowed()?;
raw_call(ExprType::ProcTime)(binder, inputs)
binder.ensure_proctime_function_allowed()?;
raw_call(ExprType::Proctime)(binder, inputs)
})
}

Expand Down Expand Up @@ -570,7 +570,7 @@ impl Binder {
// non-deterministic
("now", now()),
("current_timestamp", now()),
("proc_time", proc_time())
("proctime", proctime())
]
.into_iter()
.collect()
Expand Down Expand Up @@ -691,10 +691,10 @@ impl Binder {
Ok(())
}

fn ensure_proc_time_function_allowed(&self) -> Result<()> {
fn ensure_proctime_function_allowed(&self) -> Result<()> {
if !self.is_for_ddl() {
return Err(ErrorCode::InvalidInputSyntax(
"Function `PROC_TIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?".to_string(),
"Function `PROCTIME()` is only allowed in CREATE TABLE/SOURCE. Is `NOW()` what you want?".to_string(),
)
.into());
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/expr/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl std::fmt::Debug for FunctionCallDisplay<'_> {
ExprType::BitwiseXor => {
explain_verbose_binary_op(f, "#", &that.inputs, self.input_schema)
}
ExprType::Now | ExprType::ProcTime => {
ExprType::Now | ExprType::Proctime => {
write!(f, "{:?}", that.func_type)
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/expr/type_inference/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ fn infer_type_for_special(
ensure_arity!("now", | inputs | <= 1);
Ok(Some(DataType::Timestamptz))
}
ExprType::ProcTime => {
ensure_arity!("proc_time", | inputs | == 0);
ExprType::Proctime => {
ensure_arity!("proctime", | inputs | == 0);
Ok(Some(DataType::Timestamptz))
}
_ => Ok(None),
Expand Down

0 comments on commit 4459f34

Please sign in to comment.