MCPcopy Create free account
hub / github.com/apache/datafusion / bigint_to_i256

Function bigint_to_i256

datafusion/sql/src/expr/value.rs:344–359  ·  view source on GitHub ↗

Returns None if the value can't be converted to i256. Modified from

(v: &BigInt)

Source from the content-addressed store, hash-verified

342/// Returns None if the value can't be converted to i256.
343/// Modified from <https://github.com/apache/arrow-rs/blob/c4dbf0d8af6ca5a19b8b2ea777da3c276807fc5e/arrow-buffer/src/bigint/mod.rs#L303>
344fn bigint_to_i256(v: &BigInt) -> Option<i256> {
345 let v_bytes = v.to_signed_bytes_le();
346 match v_bytes.len().cmp(&32) {
347 Ordering::Less => {
348 let mut bytes = if v.is_negative() {
349 [255_u8; 32]
350 } else {
351 [0; 32]
352 };
353 bytes[0..v_bytes.len()].copy_from_slice(&v_bytes[..v_bytes.len()]);
354 Some(i256::from_le_bytes(bytes))
355 }
356 Ordering::Equal => Some(i256::from_le_bytes(v_bytes.try_into().unwrap())),
357 Ordering::Greater => None,
358 }
359}
360
361fn parse_decimal(unsigned_number: &str, negative: bool) -> Result<Expr> {
362 let mut dec = BigDecimal::from_str(unsigned_number).map_err(|e| {

Callers 2

parse_decimalFunction · 0.85
test_bigint_to_i256Function · 0.85

Calls 2

cmpMethod · 0.45
lenMethod · 0.45

Tested by 1

test_bigint_to_i256Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…