Skip to content

Commit

Permalink
use i32 instead
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Oct 9, 2024
1 parent 671668e commit 5f948a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
20 changes: 16 additions & 4 deletions e2e_test/batch/functions/vnode.slt.part
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query error Function `rw_vnode` takes at least 2 arguments (0 given)
query error takes at least 2 arguments \(0 given\)
select rw_vnode();

query error Function `rw_vnode` takes at least 2 arguments (1 given)
query error takes at least 2 arguments \(1 given\)
select rw_vnode(256);

query I
Expand All @@ -14,9 +14,21 @@ select rw_vnode(4096, 114, 514);
----
1377

query error the first argument (vnode count) must not be NULL
# VirtualNode::MAX_COUNT
query I
select rw_vnode(32768, 114, 514);
----
21857

query error the first argument \(vnode count\) must not be NULL
select rw_vnode(NULL, 114, 514);

query error the first argument \(vnode count\) must be in range 1..=32768
select rw_vnode(0, 114, 514);

query error the first argument \(vnode count\) must be in range 1..=32768
select rw_vnode(32769, 114, 514);

statement ok
create table vnodes (vnode int);

Expand All @@ -26,7 +38,7 @@ insert into vnodes values (256), (4096);
statement ok
flush;

query error the first argument (vnode count) must be a constant
query error the first argument \(vnode count\) must be a constant
select rw_vnode(vnode, 114, 514) from vnodes;

statement ok
Expand Down
13 changes: 9 additions & 4 deletions src/expr/impl/src/scalar/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ fn build_user(_: DataType, children: Vec<BoxedExpression>) -> Result<BoxedExpres
.eval_const() // required to be constant
.context("the first argument (vnode count) must be a constant")?
.context("the first argument (vnode count) must not be NULL")?
.into_int16() as usize; // always int16, casted during type inference
if vnode_count == 0 {
return Err(anyhow::anyhow!("the first argument (vnode count) must not be zero").into());
.into_int32(); // always int32, casted during type inference

if !(1i32..=VirtualNode::MAX_COUNT as i32).contains(&vnode_count) {
return Err(anyhow::anyhow!(
"the first argument (vnode count) must be in range 1..={}",
VirtualNode::MAX_COUNT
)
.into());
}

let children = children.collect_vec();

Ok(Box::new(VnodeExpression {
vnode_count: Some(vnode_count),
vnode_count: Some(vnode_count.try_into().unwrap()),
all_indices: (0..children.len()).collect(),
children,
}))
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/expr/type_inference/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ fn infer_type_for_special(
}
ExprType::VnodeUser => {
ensure_arity!("rw_vnode", 2 <= | inputs |);
inputs[0].cast_explicit_mut(DataType::Int16)?;
inputs[0].cast_explicit_mut(DataType::Int32)?; // vnode count
Ok(Some(VirtualNode::RW_TYPE))
}
ExprType::Greatest | ExprType::Least => {
Expand Down

0 comments on commit 5f948a0

Please sign in to comment.