Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ expression: "#[sqlfunc(\n is_monotone = (true, true),\n output_type = i16,
)]
pub struct AddInt16;
impl crate::func::binary::EagerBinaryFunc for AddInt16 {
type Input1<'a> = Datum<'a>;
type Input2<'a> = Datum<'a>;
type Input<'a> = (Datum<'a>, Datum<'a>);
type Output<'a> = Result<Datum<'a>, EvalError>;
fn call<'a>(
&self,
a: Self::Input1<'a>,
b: Self::Input2<'a>,
(a, b): Self::Input<'a>,
temp_storage: &'a mz_repr::RowArena,
) -> Self::Output<'a> {
add_int16(a, b)
}
fn output_type(
&self,
input_type_a: mz_repr::SqlColumnType,
input_type_b: mz_repr::SqlColumnType,
input_types: &[mz_repr::SqlColumnType],
) -> mz_repr::SqlColumnType {
use mz_repr::AsColumnType;
let output = <i16>::as_column_type();
let propagates_nulls = crate::func::binary::EagerBinaryFunc::propagates_nulls(
self,
);
let nullable = output.nullable;
let is_null = nullable
|| (propagates_nulls && (input_type_a.nullable || input_type_b.nullable));
let inputs_nullable = input_types.iter().any(|it| it.nullable);
let is_null = nullable || (propagates_nulls && inputs_nullable);
output.nullable(is_null)
}
fn introduces_nulls(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ expression: "#[sqlfunc(test = true)]\nfn unary_fn<'a>(a: Datum<'a>, b: u16, temp
)]
pub struct UnaryFn;
impl crate::func::binary::EagerBinaryFunc for UnaryFn {
type Input1<'a> = Datum<'a>;
type Input2<'a> = u16;
type Input<'a> = (Datum<'a>, u16);
type Output<'a> = bool;
fn call<'a>(
&self,
a: Self::Input1<'a>,
b: Self::Input2<'a>,
(a, b): Self::Input<'a>,
temp_storage: &'a mz_repr::RowArena,
) -> Self::Output<'a> {
unary_fn(a, b, temp_storage)
}
fn output_type(
&self,
input_type_a: mz_repr::SqlColumnType,
input_type_b: mz_repr::SqlColumnType,
input_types: &[mz_repr::SqlColumnType],
) -> mz_repr::SqlColumnType {
use mz_repr::AsColumnType;
let output = Self::Output::as_column_type();
let propagates_nulls = crate::func::binary::EagerBinaryFunc::propagates_nulls(
self,
);
let nullable = output.nullable;
let is_null = nullable
|| (propagates_nulls && (input_type_a.nullable || input_type_b.nullable));
let inputs_nullable = input_types.iter().any(|it| it.nullable);
let is_null = nullable || (propagates_nulls && inputs_nullable);
output.nullable(is_null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ expression: "#[sqlfunc(\n is_monotone = (true, true),\n output_type = \"Op
)]
pub struct ComplexOutputTypeFn;
impl crate::func::binary::EagerBinaryFunc for ComplexOutputTypeFn {
type Input1<'a> = Datum<'a>;
type Input2<'a> = Datum<'a>;
type Input<'a> = (Datum<'a>, Datum<'a>);
type Output<'a> = Result<Datum<'a>, EvalError>;
fn call<'a>(
&self,
a: Self::Input1<'a>,
b: Self::Input2<'a>,
(a, b): Self::Input<'a>,
temp_storage: &'a mz_repr::RowArena,
) -> Self::Output<'a> {
complex_output_type_fn(a, b)
}
fn output_type(
&self,
input_type_a: mz_repr::SqlColumnType,
input_type_b: mz_repr::SqlColumnType,
input_types: &[mz_repr::SqlColumnType],
) -> mz_repr::SqlColumnType {
use mz_repr::AsColumnType;
let output = <Option<bool>>::as_column_type();
let propagates_nulls = crate::func::binary::EagerBinaryFunc::propagates_nulls(
self,
);
let nullable = output.nullable;
let is_null = nullable
|| (propagates_nulls && (input_type_a.nullable || input_type_b.nullable));
let inputs_nullable = input_types.iter().any(|it| it.nullable);
let is_null = nullable || (propagates_nulls && inputs_nullable);
output.nullable(is_null)
}
fn introduces_nulls(&self) -> bool {
Expand Down
14 changes: 5 additions & 9 deletions src/expr-derive-impl/src/sqlfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,20 @@ fn binary_func(
pub struct #struct_name;

impl crate::func::binary::EagerBinaryFunc for #struct_name {
type Input1<'a> = #input1_ty;
type Input2<'a> = #input2_ty;
type Input<'a> = (#input1_ty, #input2_ty);
type Output<'a> = #output_ty;

fn call<'a>(
&self,
a: Self::Input1<'a>,
b: Self::Input2<'a>,
(a, b): Self::Input<'a>,
temp_storage: &'a mz_repr::RowArena
) -> Self::Output<'a> {
#fn_name(a, b #arena)
}

fn output_type(
&self,
input_type_a: mz_repr::SqlColumnType,
input_type_b: mz_repr::SqlColumnType,
input_types: &[mz_repr::SqlColumnType],
) -> mz_repr::SqlColumnType {
use mz_repr::AsColumnType;
let output = #output_type;
Expand All @@ -516,9 +513,8 @@ fn binary_func(
// The output is nullable if it is nullable by itself
// or the input is nullable and this function
// propagates nulls
let is_null = nullable
|| (propagates_nulls
&& (input_type_a.nullable || input_type_b.nullable));
let inputs_nullable = input_types.iter().any(|it| it.nullable);
let is_null = nullable || (propagates_nulls && inputs_nullable);
output.nullable(is_null)
}

Expand Down
4 changes: 2 additions & 2 deletions src/expr/src/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ impl<'a> Interpreter for ColumnSpecs<'a> {
})
};

let col_type = func.output_type(left.col_type, right.col_type);
let col_type = func.output_type(&[left.col_type, right.col_type]);

let range = mapped_spec.intersect(ResultSpec::has_type(&col_type, fallible));
ColumnSpec { col_type, range }
Expand Down Expand Up @@ -1319,7 +1319,7 @@ mod tests {
if !binary_typecheck(&func, &type_left, &type_right) {
return None;
}
let type_out = func.output_type(type_left, type_right);
let type_out = func.output_type(&[type_left, type_right]);
let expr_out = MirScalarExpr::CallBinary {
func,
expr1: Box::new(expr_left),
Expand Down
8 changes: 4 additions & 4 deletions src/expr/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ impl MirScalarExpr {
MirScalarExpr::CallUnmaterializable(func) => func.output_type(),
MirScalarExpr::CallUnary { expr, func } => func.output_type(expr.typ(column_types)),
MirScalarExpr::CallBinary { expr1, expr2, func } => {
func.output_type(expr1.typ(column_types), expr2.typ(column_types))
func.output_type(&[expr1.typ(column_types), expr2.typ(column_types)])
}
MirScalarExpr::CallVariadic { exprs, func } => {
func.output_type(exprs.iter().map(|e| e.typ(column_types)).collect())
Expand All @@ -2001,10 +2001,10 @@ impl MirScalarExpr {
&func.output_type(SqlColumnType::from_repr(&expr.repr_typ(column_types))),
),
MirScalarExpr::CallBinary { expr1, expr2, func } => {
ReprColumnType::from(&func.output_type(
ReprColumnType::from(&func.output_type(&[
SqlColumnType::from_repr(&expr1.repr_typ(column_types)),
SqlColumnType::from_repr(&expr2.repr_typ(column_types)),
))
]))
}
MirScalarExpr::CallVariadic { exprs, func } => ReprColumnType::from(
&func.output_type(
Expand Down Expand Up @@ -2041,7 +2041,7 @@ impl MirScalarExpr {
)),
MirScalarExpr::CallUnary { func, expr } => func.eval(datums, temp_storage, expr),
MirScalarExpr::CallBinary { func, expr1, expr2 } => {
func.eval(datums, temp_storage, expr1, expr2)
func.eval(datums, temp_storage, &[expr1, expr2])
}
MirScalarExpr::CallVariadic { func, exprs } => func.eval(datums, temp_storage, exprs),
MirScalarExpr::If { cond, then, els } => match cond.eval(datums, temp_storage)? {
Expand Down
21 changes: 11 additions & 10 deletions src/expr/src/scalar/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ range_fn!(overright, overright, "&>");
range_fn!(adjacent, adjacent, "-|-");

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "+",
propagates_nulls = true,
Expand All @@ -1544,7 +1544,7 @@ fn range_union<'a>(
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "*",
propagates_nulls = true,
Expand All @@ -1559,7 +1559,7 @@ fn range_intersection<'a>(
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "-",
propagates_nulls = true,
Expand Down Expand Up @@ -1773,7 +1773,7 @@ fn map_contains_map<'a>(map_a: DatumMap<'a>, b: DatumMap<'a>) -> bool {
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.unwrap_map_value_type().clone().nullable(true)",
output_type_expr = "input_types[0].scalar_type.unwrap_map_value_type().clone().nullable(true)",
is_infix_op = true,
sqlname = "->",
propagates_nulls = true,
Expand Down Expand Up @@ -2734,7 +2734,7 @@ fn array_lower<'a>(a: Array<'a>, i: i64) -> Option<i32> {
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
sqlname = "array_remove",
propagates_nulls = false,
introduces_nulls = false
Expand Down Expand Up @@ -2819,7 +2819,7 @@ fn array_contains_array_rev<'a>(a: Array<'a>, b: Array<'a>) -> bool {
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "||",
propagates_nulls = false,
Expand Down Expand Up @@ -2930,7 +2930,7 @@ fn array_array_concat<'a>(
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "||",
propagates_nulls = false,
Expand All @@ -2950,7 +2950,7 @@ fn list_list_concat<'a>(a: Datum<'a>, b: Datum<'a>, temp_storage: &'a RowArena)
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "||",
propagates_nulls = false,
Expand All @@ -2969,8 +2969,9 @@ fn list_element_concat<'a>(a: Datum<'a>, b: Datum<'a>, temp_storage: &'a RowAren
})
}

// Note that the output type corresponds to the _second_ parameter's input type.
#[sqlfunc(
output_type_expr = "input_type_b.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[1].scalar_type.without_modifiers().nullable(true)",
is_infix_op = true,
sqlname = "||",
propagates_nulls = false,
Expand All @@ -2990,7 +2991,7 @@ fn element_list_concat<'a>(a: Datum<'a>, b: Datum<'a>, temp_storage: &'a RowAren
}

#[sqlfunc(
output_type_expr = "input_type_a.scalar_type.without_modifiers().nullable(true)",
output_type_expr = "input_types[0].scalar_type.without_modifiers().nullable(true)",
sqlname = "list_remove",
propagates_nulls = false,
introduces_nulls = false
Expand Down
Loading