| 1028 | } |
| 1029 | |
| 1030 | fn build_timestamp_array_impl<T: ArrowTimestampType, Tz: TimeZone>( |
| 1031 | line_number: usize, |
| 1032 | rows: &StringRecords<'_>, |
| 1033 | col_idx: usize, |
| 1034 | timezone: &Tz, |
| 1035 | null_regex: &NullRegex, |
| 1036 | ) -> Result<PrimitiveArray<T>, ArrowError> { |
| 1037 | rows.iter() |
| 1038 | .enumerate() |
| 1039 | .map(|(row_index, row)| { |
| 1040 | let s = row.get(col_idx); |
| 1041 | if null_regex.is_null(s) { |
| 1042 | return Ok(None); |
| 1043 | } |
| 1044 | |
| 1045 | let date = string_to_datetime(timezone, s) |
| 1046 | .and_then(|date| match T::UNIT { |
| 1047 | TimeUnit::Second => Ok(date.timestamp()), |
| 1048 | TimeUnit::Millisecond => Ok(date.timestamp_millis()), |
| 1049 | TimeUnit::Microsecond => Ok(date.timestamp_micros()), |
| 1050 | TimeUnit::Nanosecond => date.timestamp_nanos_opt().ok_or_else(|| { |
| 1051 | ArrowError::ParseError(format!( |
| 1052 | "{} would overflow 64-bit signed nanoseconds", |
| 1053 | date.to_rfc3339(), |
| 1054 | )) |
| 1055 | }), |
| 1056 | }) |
| 1057 | .map_err(|e| { |
| 1058 | ArrowError::ParseError(format!( |
| 1059 | "Error parsing column {col_idx} at line {}: {}", |
| 1060 | line_number + row_index, |
| 1061 | e |
| 1062 | )) |
| 1063 | })?; |
| 1064 | Ok(Some(date)) |
| 1065 | }) |
| 1066 | .collect() |
| 1067 | } |
| 1068 | |
| 1069 | // parses a specific column (col_idx) into an Arrow Array. |
| 1070 | fn build_boolean_array( |