parquet 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
+ use crate::reader::ReaderError;
2
+
1
3
  use super::*;
2
4
 
3
- pub fn parse_zoned_timestamp(value: &ParquetValue) -> jiff::Timestamp {
5
+ pub fn parse_zoned_timestamp(value: &ParquetValue) -> Result<jiff::Timestamp, ReaderError> {
4
6
  let (ts, tz) = match value {
5
7
  ParquetValue::TimestampSecond(ts, tz) => (jiff::Timestamp::from_second(*ts).unwrap(), tz),
6
8
  ParquetValue::TimestampMillis(ts, tz) => {
@@ -12,7 +14,12 @@ pub fn parse_zoned_timestamp(value: &ParquetValue) -> jiff::Timestamp {
12
14
  ParquetValue::TimestampNanos(ts, tz) => {
13
15
  (jiff::Timestamp::from_nanosecond(*ts as i128).unwrap(), tz)
14
16
  }
15
- _ => panic!("Invalid timestamp value"),
17
+ _ => {
18
+ return Err(MagnusError::new(
19
+ magnus::exception::type_error(),
20
+ "Invalid timestamp value".to_string(),
21
+ ))?
22
+ }
16
23
  };
17
24
 
18
25
  // If timezone is provided, convert to zoned timestamp
@@ -42,17 +49,17 @@ pub fn parse_zoned_timestamp(value: &ParquetValue) -> jiff::Timestamp {
42
49
 
43
50
  // Create fixed timezone
44
51
  let tz = jiff::tz::TimeZone::fixed(jiff::tz::offset((total_minutes / 60) as i8));
45
- ts.to_zoned(tz).timestamp()
52
+ Ok(ts.to_zoned(tz).timestamp())
46
53
  } else {
47
54
  // Try IANA timezone
48
55
  match ts.in_tz(&tz) {
49
- Ok(zoned) => zoned.timestamp(),
50
- Err(_) => ts, // Fall back to UTC if timezone is invalid
56
+ Ok(zoned) => Ok(zoned.timestamp()),
57
+ Err(_) => Ok(ts), // Fall back to UTC if timezone is invalid
51
58
  }
52
59
  }
53
60
  } else {
54
61
  // No timezone provided - treat as UTC
55
- ts
62
+ Ok(ts)
56
63
  }
57
64
  }
58
65
 
@@ -62,13 +69,16 @@ macro_rules! impl_timestamp_conversion {
62
69
  ($value:expr, $unit:ident, $handle:expr) => {{
63
70
  match $value {
64
71
  ParquetValue::$unit(ts, tz) => {
65
- let ts = parse_zoned_timestamp(&ParquetValue::$unit(ts, tz));
72
+ let ts = parse_zoned_timestamp(&ParquetValue::$unit(ts, tz))?;
66
73
  let time_class = $handle.class_time();
67
74
  Ok(time_class
68
75
  .funcall::<_, _, Value>("parse", (ts.to_string(),))?
69
76
  .into_value_with($handle))
70
77
  }
71
- _ => panic!("Invalid timestamp type"),
78
+ _ => Err(ReaderError::Ruby(MagnusErrorWrapper(MagnusError::new(
79
+ magnus::exception::type_error(),
80
+ "Invalid timestamp type".to_string(),
81
+ )))),
72
82
  }
73
83
  }};
74
84
  }