parses a specific column (col_idx) into an Arrow Array.
(
line_number: usize,
rows: &StringRecords<'_>,
col_idx: usize,
null_regex: &NullRegex,
)
| 980 | |
| 981 | // parses a specific column (col_idx) into an Arrow Array. |
| 982 | fn 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 | |
| 1013 | fn build_timestamp_array<T: ArrowTimestampType>( |
| 1014 | line_number: usize, |