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

Function extract_datum_from_arrow

crates/paimon/src/spec/binary_row.rs:648–802  ·  view source on GitHub ↗

Extract a Datum from an Arrow RecordBatch column at the given row index.

(
    batch: &RecordBatch,
    row_idx: usize,
    col_idx: usize,
    data_type: &DataType,
)

Source from the content-addressed store, hash-verified

646
647/// Extract a Datum from an Arrow RecordBatch column at the given row index.
648pub fn extract_datum_from_arrow(
649 batch: &RecordBatch,
650 row_idx: usize,
651 col_idx: usize,
652 data_type: &DataType,
653) -> crate::Result<Option<Datum>> {
654 use arrow_array::Array;
655
656 let col = batch.column(col_idx);
657 if col.is_null(row_idx) {
658 return Ok(None);
659 }
660
661 let datum = match data_type {
662 DataType::Boolean(_) => {
663 let arr = col
664 .as_any()
665 .downcast_ref::<arrow_array::BooleanArray>()
666 .ok_or_else(|| type_mismatch_err("Boolean", col_idx))?;
667 Datum::Bool(arr.value(row_idx))
668 }
669 DataType::TinyInt(_) => {
670 let arr = col
671 .as_any()
672 .downcast_ref::<arrow_array::Int8Array>()
673 .ok_or_else(|| type_mismatch_err("TinyInt", col_idx))?;
674 Datum::TinyInt(arr.value(row_idx))
675 }
676 DataType::SmallInt(_) => {
677 let arr = col
678 .as_any()
679 .downcast_ref::<arrow_array::Int16Array>()
680 .ok_or_else(|| type_mismatch_err("SmallInt", col_idx))?;
681 Datum::SmallInt(arr.value(row_idx))
682 }
683 DataType::Int(_) => {
684 let arr = col
685 .as_any()
686 .downcast_ref::<arrow_array::Int32Array>()
687 .ok_or_else(|| type_mismatch_err("Int", col_idx))?;
688 Datum::Int(arr.value(row_idx))
689 }
690 DataType::BigInt(_) => {
691 let arr = col
692 .as_any()
693 .downcast_ref::<arrow_array::Int64Array>()
694 .ok_or_else(|| type_mismatch_err("BigInt", col_idx))?;
695 Datum::Long(arr.value(row_idx))
696 }
697 DataType::Float(_) => {
698 let arr = col
699 .as_any()
700 .downcast_ref::<arrow_array::Float32Array>()
701 .ok_or_else(|| type_mismatch_err("Float", col_idx))?;
702 Datum::Float(arr.value(row_idx))
703 }
704 DataType::Double(_) => {
705 let arr = col

Callers 4

from_arrowMethod · 0.85
compute_column_statsFunction · 0.85

Calls 9

type_mismatch_errFunction · 0.85
DateTypeAlias · 0.85
BytesTypeAlias · 0.85
columnMethod · 0.80
is_nullMethod · 0.80
precisionMethod · 0.80
scaleMethod · 0.80
to_vecMethod · 0.80
as_anyMethod · 0.45

Tested by

no test coverage detected