support nullable cast to no nullable
@@ -146,9 +146,11 @@ impl<'a> Evaluator<'a> {
return Ok(value);
}
+ if !src_type.is_nullable() {
if let Some(cast_fn) = check_simple_cast(false, dest_type) {
return self.run_simple_cast(span, src_type, dest_type, value, &cast_fn);
}
+ }
match (src_type, dest_type) {
(DataType::Null, DataType::Nullable(_)) => match value {
@@ -177,6 +179,23 @@ impl<'a> Evaluator<'a> {
}
_ => unreachable!(),
},
+ (DataType::Nullable(inner_src_ty), _) => match value {
+ Value::Scalar(Scalar::Null) => {
+ Err((span, (format!("unable to cast {src_type} to {dest_type}"))))
+ }
+ Value::Scalar(_) => self.run_cast(span, inner_src_ty, dest_type, value),
+ Value::Column(Column::Nullable(col)) => {
+ if col.validity.unset_bits() > 0 {
+ return Err((span, (format!("unable to cast {src_type} to {dest_type}"))));
+ }
+ let column = self
+ .run_cast(span, inner_src_ty, dest_type, Value::Column(col.column))?
+ .into_column()
+ .unwrap();
+ Ok(Value::Column(column))
+ }
+ _ => unreachable!(),
+ },
(_, DataType::Nullable(inner_dest_ty)) => match value {
Value::Scalar(scalar) => {
self.run_cast(span, src_type, inner_dest_ty, Value::Scalar(scalar))
