Jefffrey commented on code in PR #10114:
URL: https://github.com/apache/arrow-rs/pull/10114#discussion_r3871633360
##########
arrow-cast/src/parse.rs:
##########
@@ -646,7 +646,36 @@ fn parse_extended_ymd(string: &str) -> Option<(i32, u32,
u32)> {
Some((year, month, day))
}
-fn parse_date(string: &str) -> Option<NaiveDate> {
+/// Parse a given date string into a `NaiveDate`.
+///
+/// ```
+/// /// You can parse from ISO date strings
+/// use chrono::NaiveDate;
+/// use arrow_cast::parse::{parse_date, parse_decimal};
+/// let s1 = "2026-06-10";
+/// let d1 = parse_date(s1).unwrap();
+/// let expected_d1 = NaiveDate::from_ymd_opt(2026, 6, 10).unwrap();
+/// assert_eq!(expected_d1, d1);
+///
+/// // or from ISO extended(signed) year date strings
+/// let s2 = "+2026-06-10";
+/// let d2 = parse_date(s2).unwrap();
+/// let expected_d2 = NaiveDate::from_ymd_opt(2026, 6, 10).unwrap();
+/// assert_eq!(expected_d2, d2);
+///
+/// // or from date strings without hyphen
+/// let s3 = "20260610";
+/// let d3 = parse_date(s3).unwrap();
+/// let expected_d3 = NaiveDate::from_ymd_opt(2026, 6, 10).unwrap();
+/// assert_eq!(expected_d3, d3);
+///
+/// // or from datetime strings
+/// let s4 = "2026-06-10T14:23:45";
+/// let d4 = parse_date(s4).unwrap();
+/// let expected_d4 = NaiveDate::from_ymd_opt(2026, 6, 10).unwrap();
+/// assert_eq!(expected_d4, d4);
+/// ```
+pub fn parse_date(string: &str) -> Option<NaiveDate> {
Review Comment:
is this a leftover change? cant seem to find where this now being used in
the diff
##########
arrow-cast/src/display.rs:
##########
@@ -752,7 +756,8 @@ macro_rules! decimal_display {
decimal_display!(Decimal32Type, Decimal64Type, Decimal128Type, Decimal256Type);
-fn write_timestamp(
+/// Writes a timestamp value to the output using the given representation.
+pub fn write_timestamp(
Review Comment:
im not sure about adding this to our public api; we could probably get away
with leaving it public and just copying the code required into the variant
crate? especially as they seem to use default format + either no timezone or
the default utc timezone
##########
parquet-variant-compute/src/type_conversion.rs:
##########
@@ -766,3 +882,237 @@ macro_rules! primitive_conversion_single_value {
}};
}
pub(crate) use primitive_conversion_single_value;
+
+#[cfg(test)]
+mod tests {
+ use crate::type_conversion::variant_to_string;
+ use arrow::array::{
+ Array, BooleanArray, Date32Array, Int32Builder, ListBuilder,
StringArray,
+ Time64MicrosecondArray, TimestampMicrosecondArray,
TimestampNanosecondArray,
+ };
+ use arrow::compute::cast;
+ use arrow_schema::DataType;
+ use chrono::{DateTime, NaiveDate, NaiveTime};
+ use parquet_variant::{Variant, VariantBuilder, VariantBuilderExt};
+ use std::iter::zip;
+
+ #[test]
+ fn test_compatible_cast_logic_with_cast_kernel() {
+ // boolean -> string
+ let boolean_array = BooleanArray::from(vec![Some(true), Some(false)]);
+ let cast_array = cast(&boolean_array, &DataType::Utf8).unwrap();
+ let boolean_utf8_array =
cast_array.as_any().downcast_ref::<StringArray>().unwrap();
Review Comment:
```suggestion
let boolean_utf8_array = cast_array.as_string::<i32>();
```
can use the downcasters here to make it more succinct:
https://docs.rs/arrow/latest/arrow/array/trait.AsArray.html
--
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]