alamb commented on code in PR #8149:
URL: https://github.com/apache/arrow-rs/pull/8149#discussion_r2283028793
##########
parquet-variant/src/decoder.rs:
##########
@@ -64,6 +65,9 @@ pub enum VariantPrimitiveType {
Binary = 15,
String = 16,
Time = 17,
+ TimestampNanos = 18,
Review Comment:
I double checked and this is correct compared to
https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#encoding-types
##########
parquet-variant/src/variant.rs:
##########
@@ -1262,9 +1307,14 @@ impl From<NaiveDate> for Variant<'_, '_> {
impl From<DateTime<Utc>> for Variant<'_, '_> {
fn from(value: DateTime<Utc>) -> Self {
Review Comment:
i think this is ok
##########
parquet-variant/src/decoder.rs:
##########
@@ -316,6 +323,33 @@ pub(crate) fn decode_time_ntz(data: &[u8]) ->
Result<NaiveTime, ArrowError> {
.ok_or(case_error)
}
+/// Decodes a TimestampNanos from the value section of a variant.
+pub(crate) fn decode_timestamp_nanos(data: &[u8]) -> Result<DateTime<Utc>,
ArrowError> {
+ let nanos_since_epoch = i64::from_le_bytes(array_from_slice(data, 0)?);
+
+ // Copied from DateTime::from_timestamp_nanos as there is no infallible
version
Review Comment:
I don't understand this comment
##########
parquet-variant/src/variant.rs:
##########
@@ -632,6 +642,31 @@ impl<'m, 'v> Variant<'m, 'v> {
}
}
+ /// Converts this variant to a `uuid hyphenated string` if possible.
+ ///
+ /// Returns `Some(String)` for UUID variants, `None` for non-UUID variants.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use parquet_variant::Variant;
+ ///
+ /// // you can extract a UUID string from a UUID variant
+ /// let s =
uuid::Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap();
+ /// let v1 = Variant::Uuid(s);
+ /// assert_eq!("67e55044-10b1-426f-9247-bb680e5fe0c8",
v1.as_uuid_string().unwrap());
+ ///
+ /// //but not from other variants
+ /// let v2 = Variant::from(1234);
+ /// assert_eq!(None, v2.as_uuid_string())
+ /// ```
+ pub fn as_uuid_string(&self) -> Option<String> {
Review Comment:
I think having this be `as_uuid(&self) -> Option<Uuid>` would be both more
consistent with the other methods that access variant data, as well as being
more performant -- the caller could decide if they wanted to pay the cost to
convert to string as well
I think the example is great, and we could show it as a way to convert to
strings
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]