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

Function build_primitive_array

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

parses a specific column (col_idx) into an Arrow Array.

(
    line_number: usize,
    rows: &StringRecords<'_>,
    col_idx: usize,
    null_regex: &NullRegex,
)

Source from the content-addressed store, hash-verified

980
981// parses a specific column (col_idx) into an Arrow Array.
982fn build_primitive_array<T: ArrowPrimitiveType + Parser>(
983 line_number: usize,
984 rows: &StringRecords<'_>,
985 col_idx: usize,
986 null_regex: &NullRegex,
987) -> Result<ArrayRef, ArrowError> {
988 rows.iter()
989 .enumerate()
990 .map(|(row_index, row)| {
991 let s = row.get(col_idx);
992 if null_regex.is_null(s) {
993 return Ok(None);
994 }
995
996 match T::parse(s) {
997 Some(e) => Ok(Some(e)),
998 None => Err(ArrowError::ParseError(format!(
999 // TODO: we should surface the underlying error here.
1000 "Error while parsing value '{}' as type '{}' for column {} at line {}. Row data: '{}'",
1001 s,
1002 T::DATA_TYPE,
1003 col_idx,
1004 line_number + row_index,
1005 row
1006 ))),
1007 }
1008 })
1009 .collect::<Result<PrimitiveArray<T>, ArrowError>>()
1010 .map(|e| Arc::new(e) as ArrayRef)
1011}
1012
1013fn build_timestamp_array<T: ArrowTimestampType>(
1014 line_number: usize,

Callers

nothing calls this directly

Calls 4

parseFunction · 0.70
iterMethod · 0.45
getMethod · 0.45
is_nullMethod · 0.45

Tested by

no test coverage detected