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

fix(function): fix incorrect return datatype of function if #5980

Merged
merged 10 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 common/datablocks/src/data_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub struct DataBlock {
impl DataBlock {
#[inline]
pub fn create(schema: DataSchemaRef, columns: Vec<ColumnRef>) -> Self {
debug_assert!(schema
.fields()
.iter()
.zip(columns.iter())
.all(|(f, c)| f.data_type().data_type_id().to_physical_type() == c.data_type().data_type_id().to_physical_type()));
DataBlock { schema, columns }
}

Expand Down
2 changes: 1 addition & 1 deletion common/datablocks/tests/it/data_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use pretty_assertions::assert_eq;
fn test_data_block() -> Result<()> {
let schema = DataSchemaRefExt::create(vec![DataField::new("a", i64::to_data_type())]);

let block = DataBlock::create(schema.clone(), vec![Series::from_data(vec![1, 2, 3])]);
let block = DataBlock::create(schema.clone(), vec![Series::from_data(vec![1i64, 2, 3])]);
assert_eq!(&schema, block.schema());

assert_eq!(3, block.num_rows());
Expand Down
8 changes: 4 additions & 4 deletions common/datablocks/tests/it/kernels/data_block_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_data_block_sort() -> Result<()> {
]);

let raw = DataBlock::create(schema, vec![
Series::from_data(vec![6, 4, 3, 2, 1, 7]),
Series::from_data(vec![6i64, 4, 3, 2, 1, 7]),
Series::from_data(vec!["b1", "b2", "b3", "b4", "b5", "b6"]),
]);

Expand Down Expand Up @@ -185,7 +185,7 @@ fn test_data_block_sort() -> Result<()> {
asc: true,
nulls_first: false,
}];
println!("raw={:?}", raw);
// println!("raw={:?}", raw);
sundy-li marked this conversation as resolved.
Show resolved Hide resolved
let results = DataBlock::sort_block(&raw, &options, Some(3))?;
assert_eq!(raw.schema(), results.schema());

Expand Down Expand Up @@ -233,12 +233,12 @@ fn test_data_block_merge_sort() -> Result<()> {
]);

let raw1 = DataBlock::create(schema.clone(), vec![
Series::from_data(vec![3, 5, 7]),
Series::from_data(vec![3i64, 5, 7]),
Series::from_data(vec!["b1", "b2", "b3"]),
]);

let raw2 = DataBlock::create(schema, vec![
Series::from_data(vec![2, 4, 6]),
Series::from_data(vec![2i64, 4, 6]),
Series::from_data(vec!["b4", "b5", "b6"]),
]);

Expand Down
12 changes: 7 additions & 5 deletions common/functions/src/scalars/conditionals/if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ impl IfFunction {
&self,
cond_col: &ColumnRef,
columns: &ColumnsWithField,
_func_ctx: &FunctionContext,
func_ctx: &FunctionContext,
) -> Result<ColumnRef> {
debug_assert!(cond_col.is_const());
// whether nullable or not, we can use viewer to make it
let cond_viewer = bool::try_create_viewer(cond_col)?;
if cond_viewer.value_at(0) {
return Ok(columns[0].column().clone());
let c = if cond_viewer.value_at(0) {
columns[0].clone()
} else {
return Ok(columns[1].column().clone());
}
columns[1].clone()
};

cast_column_field(&c, c.data_type(), &self.least_supertype, func_ctx)
}

// lhs is const column and:
Expand Down
4 changes: 2 additions & 2 deletions common/streams/tests/it/stream_datablock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use futures::stream::StreamExt;
#[tokio::test]
async fn test_datablock_stream() {
let schema = DataSchemaRefExt::create(vec![
DataField::new("name", i32::to_data_type()),
DataField::new("age", Vu8::to_data_type()),
DataField::new("name", Vu8::to_data_type()),
DataField::new("age", i32::to_data_type()),
]);

let data_blocks = vec![
Expand Down
2 changes: 1 addition & 1 deletion query/tests/it/formats/output_format_tcsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn test_data_block(is_nullable: bool) -> Result<()> {
Series::from_data(vec![1, 2, 3]),
Series::from_data(vec!["a", "b", "c"]),
Series::from_data(vec![true, true, false]),
Series::from_data(vec![1.1, 2.2, 3.3]),
Series::from_data(vec![1.1f64, 2.2, 3.3]),
Series::from_data(vec![1_i32, 2_i32, 3_i32]),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ NULL
NULL
5
6
NULL 0
0 NULL
6 changes: 5 additions & 1 deletion tests/suites/0_stateless/02_function/02_0010_function_if.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ select if(number>0, 'Z+', 'zero') from numbers(3) order by number;
select if(number<1, true, null) from numbers(3) order by number;
select typeof(if(number % 3 = 0, to_uint32(1), to_int64(3))) from numbers(10) limit 1;
select typeof(if(number % 3 = 0, to_uint32(1), to_float32(3))) from numbers(10) limit 1;
SELECT if (number % 3 = 1, null, number) as a FROM numbers(7) order by number;
SELECT if (number % 3 = 1, null, number) as a FROM numbers(7) order by number;

-- constant
select if(true, null, number), if(false, null, number) from numbers(1);
select if(true, number, null), if(false, number, null) from numbers(1);