Skip to content

Commit e104c7c

Browse files
authored
fix: fold cast null to typed null (#116)
1 parent 5bbedc6 commit e104c7c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

datafusion/substrait/src/logical_plan/producer.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,21 @@ pub fn from_cast(
15731573
schema: &DFSchemaRef,
15741574
) -> Result<Expression> {
15751575
let Cast { expr, data_type } = cast;
1576+
// since substrait Null must be typed, so if we see a cast(null, dt), we make it a typed null
1577+
if let Expr::Literal(lit) = expr.as_ref() {
1578+
if lit.is_null() {
1579+
let lit = Literal {
1580+
nullable: true,
1581+
type_variation_reference: DEFAULT_TYPE_VARIATION_REF,
1582+
literal_type: Some(LiteralType::Null(to_substrait_type(
1583+
&data_type, true,
1584+
)?)),
1585+
};
1586+
return Ok(Expression {
1587+
rex_type: Some(RexType::Literal(lit)),
1588+
});
1589+
}
1590+
}
15761591
Ok(Expression {
15771592
rex_type: Some(RexType::Cast(Box::new(
15781593
substrait::proto::expression::Cast {

0 commit comments

Comments
 (0)