MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / rescale_numeric

Function rescale_numeric

src/pgrepr/src/value.rs:941–952  ·  view source on GitHub ↗

Rescales `n` to the scale required by `constraints`, if any.

(
    mut n: OrderedDecimal<mz_repr_numeric::Numeric>,
    constraints: Option<&NumericConstraints>,
)

Source from the content-addressed store, hash-verified

939
940/// Rescales `n` to the scale required by `constraints`, if any.
941fn rescale_numeric(
942 mut n: OrderedDecimal<mz_repr_numeric::Numeric>,
943 constraints: Option<&NumericConstraints>,
944) -> Result<OrderedDecimal<mz_repr_numeric::Numeric>, Box<dyn Error + Sync + Send>> {
945 if let Some(constraints) = constraints {
946 rescale(
947 &mut n.0,
948 NumericMaxScale::try_from(i64::from(constraints.max_scale()))?.into_u8(),
949 )?;
950 }
951 Ok(n)
952}
953
954fn encode_element(buf: &mut BytesMut, elem: Option<&Value>, ty: &Type) -> Result<(), io::Error> {
955 match elem {

Callers 3

decode_textMethod · 0.85
decode_text_into_rowMethod · 0.85
decode_binaryMethod · 0.85

Calls 3

rescaleFunction · 0.85
into_u8Method · 0.45
max_scaleMethod · 0.45

Tested by

no test coverage detected