MCPcopy Create free account
hub / github.com/apache/arrow-rs / build_decimal_array

Function build_decimal_array

arrow-csv/src/reader/mod.rs:948–979  ·  view source on GitHub ↗

parse the column string to an Arrow Array

(
    _line_number: usize,
    rows: &StringRecords<'_>,
    col_idx: usize,
    precision: u8,
    scale: i8,
    null_regex: &NullRegex,
)

Source from the content-addressed store, hash-verified

946
947// parse the column string to an Arrow Array
948fn build_decimal_array<T: DecimalType>(
949 _line_number: usize,
950 rows: &StringRecords<'_>,
951 col_idx: usize,
952 precision: u8,
953 scale: i8,
954 null_regex: &NullRegex,
955) -> Result<ArrayRef, ArrowError> {
956 let mut decimal_builder = PrimitiveBuilder::<T>::with_capacity(rows.len());
957 for row in rows.iter() {
958 let s = row.get(col_idx);
959 if null_regex.is_null(s) {
960 // append null
961 decimal_builder.append_null();
962 } else {
963 let decimal_value: Result<T::Native, _> = parse_decimal::<T>(s, precision, scale);
964 match decimal_value {
965 Ok(v) => {
966 decimal_builder.append_value(v);
967 }
968 Err(e) => {
969 return Err(e);
970 }
971 }
972 }
973 }
974 Ok(Arc::new(
975 decimal_builder
976 .finish()
977 .with_precision_and_scale(precision, scale)?,
978 ))
979}
980
981// parses a specific column (col_idx) into an Arrow Array.
982fn build_primitive_array<T: ArrowPrimitiveType + Parser>(

Callers

nothing calls this directly

Calls 8

lenMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
is_nullMethod · 0.45
append_nullMethod · 0.45
append_valueMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected