MCPcopy Create free account
hub / github.com/apache/paimon-rust / coerce_integer_datum

Function coerce_integer_datum

bindings/c/src/table.rs:603–655  ·  view source on GitHub ↗

Coerce an integer-family datum to match the target column's integer type. FFI callers (e.g. Go) often pass a narrower integer literal (Int) for a wider column (BigInt). This function widens or narrows the datum to match, checking range for narrowing conversions. Non-integer datums or non-integer columns are returned as-is.

(
    datum: Datum,
    fields: &[DataField],
    column: &str,
)

Source from the content-addressed store, hash-verified

601///
602/// Non-integer datums or non-integer columns are returned as-is.
603fn coerce_integer_datum(
604 datum: Datum,
605 fields: &[DataField],
606 column: &str,
607) -> Result<Datum, *mut paimon_error> {
608 let val = match &datum {
609 Datum::TinyInt(v) => *v as i64,
610 Datum::SmallInt(v) => *v as i64,
611 Datum::Int(v) => *v as i64,
612 Datum::Long(v) => *v,
613 _ => return Ok(datum),
614 };
615
616 let Some(field) = fields.iter().find(|f| f.name() == column) else {
617 // Column not found; let PredicateBuilder produce the proper error.
618 return Ok(datum);
619 };
620
621 match field.data_type() {
622 DataType::TinyInt(_) if !matches!(datum, Datum::TinyInt(_)) => {
623 if val < i8::MIN as i64 || val > i8::MAX as i64 {
624 Err(paimon_error::new(
625 PaimonErrorCode::InvalidInput,
626 format!("value {val} out of range for TinyInt column '{column}'"),
627 ))
628 } else {
629 Ok(Datum::TinyInt(val as i8))
630 }
631 }
632 DataType::SmallInt(_) if !matches!(datum, Datum::SmallInt(_)) => {
633 if val < i16::MIN as i64 || val > i16::MAX as i64 {
634 Err(paimon_error::new(
635 PaimonErrorCode::InvalidInput,
636 format!("value {val} out of range for SmallInt column '{column}'"),
637 ))
638 } else {
639 Ok(Datum::SmallInt(val as i16))
640 }
641 }
642 DataType::Int(_) if !matches!(datum, Datum::Int(_)) => {
643 if val < i32::MIN as i64 || val > i32::MAX as i64 {
644 Err(paimon_error::new(
645 PaimonErrorCode::InvalidInput,
646 format!("value {val} out of range for Int column '{column}'"),
647 ))
648 } else {
649 Ok(Datum::Int(val as i32))
650 }
651 }
652 DataType::BigInt(_) if !matches!(datum, Datum::Long(_)) => Ok(Datum::Long(val)),
653 _ => Ok(datum),
654 }
655}
656
657/// Helper to build a leaf predicate that takes a datum, via PredicateBuilder.
658unsafe fn build_leaf_predicate_datum(

Callers 2

Calls 3

data_typeMethod · 0.80
iterMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected