parses a specific column (col_idx) into an Arrow Array.
(
line_number: usize,
rows: &StringRecords<'_>,
col_idx: usize,
null_regex: &NullRegex,
)
| 1068 | |
| 1069 | // parses a specific column (col_idx) into an Arrow Array. |
| 1070 | fn build_boolean_array( |
| 1071 | line_number: usize, |
| 1072 | rows: &StringRecords<'_>, |
| 1073 | col_idx: usize, |
| 1074 | null_regex: &NullRegex, |
| 1075 | ) -> Result<ArrayRef, ArrowError> { |
| 1076 | rows.iter() |
| 1077 | .enumerate() |
| 1078 | .map(|(row_index, row)| { |
| 1079 | let s = row.get(col_idx); |
| 1080 | if null_regex.is_null(s) { |
| 1081 | return Ok(None); |
| 1082 | } |
| 1083 | let parsed = parse_bool(s); |
| 1084 | match parsed { |
| 1085 | Some(e) => Ok(Some(e)), |
| 1086 | None => Err(ArrowError::ParseError(format!( |
| 1087 | // TODO: we should surface the underlying error here. |
| 1088 | "Error while parsing value '{}' as type '{}' for column {} at line {}. Row data: '{}'", |
| 1089 | s, |
| 1090 | "Boolean", |
| 1091 | col_idx, |
| 1092 | line_number + row_index, |
| 1093 | row |
| 1094 | ))), |
| 1095 | } |
| 1096 | }) |
| 1097 | .collect::<Result<BooleanArray, _>>() |
| 1098 | .map(|e| Arc::new(e) as ArrayRef) |
| 1099 | } |
| 1100 | |
| 1101 | /// Builder for CSV [`Reader`]s |
| 1102 | #[derive(Debug)] |
no test coverage detected