Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Add NULL literal support for decimal type
Browse files Browse the repository at this point in the history
Cargo fmt
  • Loading branch information
nseekhao committed Dec 12, 2022
1 parent 26222c8 commit c10f4fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ fn from_substrait_null(null_type: &Type) -> Result<ScalarValue> {
r#type::Kind::I16(_) => Ok(ScalarValue::Int16(None)),
r#type::Kind::I32(_) => Ok(ScalarValue::Int32(None)),
r#type::Kind::I64(_) => Ok(ScalarValue::Int64(None)),
r#type::Kind::Decimal(d) => Ok(ScalarValue::Decimal128(
None,
d.precision as u8,
d.scale as u8,
)),
_ => Err(DataFusionError::NotImplemented(format!(
"Unsupported null kind: {:?}",
kind
Expand Down
12 changes: 10 additions & 2 deletions src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ pub fn to_substrait_rex(
ScalarValue::Boolean(Some(b)) => Some(LiteralType::Boolean(*b)),
ScalarValue::Float32(Some(f)) => Some(LiteralType::Fp32(*f)),
ScalarValue::Float64(Some(f)) => Some(LiteralType::Fp64(*f)),
ScalarValue::Decimal128(v, p, s) => Some(LiteralType::Decimal(Decimal {
value: v.unwrap().to_le_bytes().to_vec(),
ScalarValue::Decimal128(Some(v), p, s) => Some(LiteralType::Decimal(Decimal {
value: v.to_le_bytes().to_vec(),
precision: *p as i32,
scale: *s as i32,
})),
Expand Down Expand Up @@ -628,6 +628,14 @@ fn try_to_substrait_null(v: &ScalarValue) -> Result<LiteralType> {
nullability: default_nullability,
})),
})),
ScalarValue::Decimal128(None, p, s) => Ok(LiteralType::Null(substrait::protobuf::Type {
kind: Some(r#type::Kind::Decimal(r#type::Decimal {
scale: *s as i32,
precision: *p as i32,
type_variation_reference: default_type_ref,
nullability: default_nullability,
})),
})),
// TODO: Extend support for remaining data types
_ => Err(DataFusionError::NotImplemented(format!(
"Unsupported literal: {:?}",
Expand Down
5 changes: 5 additions & 0 deletions tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ mod tests {
roundtrip("SELECT * FROM data WHERE b > 2.5").await
}

#[tokio::test]
async fn null_decimal_literal() -> Result<()> {
roundtrip("SELECT * FROM data WHERE b = NULL").await
}

#[tokio::test]
async fn simple_distinct() -> Result<()> {
test_alias(
Expand Down

0 comments on commit c10f4fc

Please sign in to comment.