Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Oct 20, 2023
1 parent f9dabaa commit ed10b36
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/src/array/jsonb_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct JsonbArrayBuilder {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JsonbArray {
bitmap: Bitmap,
// A JSON array.
/// Elements are stored as a single JSONB array value.
data: jsonbb::Value,
}

Expand Down
23 changes: 20 additions & 3 deletions src/common/src/types/jsonb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,30 @@ impl From<i64> for JsonbVal {

impl From<F32> for JsonbVal {
fn from(v: F32) -> Self {
Self(v.0.into())
if v.0 == f32::INFINITY {
Self("Infinity".into())
} else if v.0 == f32::NEG_INFINITY {
Self("-Infinity".into())
} else if v.0.is_nan() {
Self("NaN".into())
} else {
Self(v.0.into())
}
}
}

// NOTE: Infinite or NaN values are not JSON numbers. They are stored as strings in Postgres.
impl From<F64> for JsonbVal {
fn from(v: F64) -> Self {
Self(v.0.into())
if v.0 == f64::INFINITY {
Self("Infinity".into())
} else if v.0 == f64::NEG_INFINITY {
Self("-Infinity".into())
} else if v.0.is_nan() {
Self("NaN".into())
} else {
Self(v.0.into())
}
}
}

Expand Down Expand Up @@ -269,7 +286,7 @@ impl<'a> JsonbRef<'a> {
}

/// Returns true if this is a jsonb `null`.
pub fn is_null(&self) -> bool {
pub fn is_jsonb_null(&self) -> bool {
self.0.as_null().is_some()
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl DataType {
DataType::Timestamptz => ScalarImpl::Timestamptz(Timestamptz::MIN),
DataType::Decimal => ScalarImpl::Decimal(Decimal::NegativeInf),
DataType::Interval => ScalarImpl::Interval(Interval::MIN),
DataType::Jsonb => ScalarImpl::Jsonb(JsonbVal::null()), // NOT `min` #7981
DataType::Jsonb => ScalarImpl::Jsonb(JsonbVal::null()),
DataType::Struct(data_types) => ScalarImpl::Struct(StructValue::new(
data_types
.types()
Expand Down
4 changes: 2 additions & 2 deletions src/expr/impl/src/scalar/jsonb_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn jsonb_array_element(v: JsonbRef<'_>, p: i32) -> Option<JsonbRef<'_>> {
#[function("jsonb_access_str(jsonb, varchar) -> varchar")]
pub fn jsonb_object_field_str(v: JsonbRef<'_>, p: &str, writer: &mut impl Write) -> Option<()> {
let jsonb = jsonb_object_field(v, p)?;
if jsonb.is_null() {
if jsonb.is_jsonb_null() {
return None;
}
jsonb.force_str(writer).unwrap();
Expand All @@ -52,7 +52,7 @@ pub fn jsonb_object_field_str(v: JsonbRef<'_>, p: &str, writer: &mut impl Write)
#[function("jsonb_access_str(jsonb, int4) -> varchar")]
pub fn jsonb_array_element_str(v: JsonbRef<'_>, p: i32, writer: &mut impl Write) -> Option<()> {
let jsonb = jsonb_array_element(v, p)?;
if jsonb.is_null() {
if jsonb.is_jsonb_null() {
return None;
}
jsonb.force_str(writer).unwrap();
Expand Down

0 comments on commit ed10b36

Please sign in to comment.