sdf-jkl commented on code in PR #10114:
URL: https://github.com/apache/arrow-rs/pull/10114#discussion_r4064632045
##########
parquet-variant-compute/src/type_conversion.rs:
##########
@@ -705,6 +709,230 @@ pub(crate) fn variant_to_boolean(variant: &Variant<'_,
'_>, shred: bool) -> Opti
}
}
+#[inline]
+fn write_float_to_string<F: Float>(f: F, out: &mut String) {
+ let mut buffer = ryu::Buffer::new();
+ out.push_str(buffer.format(f));
+}
+
+// convert a variant to an owned string.
+pub(crate) fn variant_to_string(
+ variant: &Variant<'_, '_>,
+ formats: &TemporalFormats<'_>,
+) -> Option<String> {
+ if matches!(variant, Variant::Null) {
+ return None;
+ }
+
+ if matches!(variant, Variant::Object(_)) {
+ return None;
+ }
+ let mut s = String::new();
+ write_variant_to_string(variant, formats, &mut s).then_some(s)
+}
+
+fn write_lexical_to_string<N: lexical_core::ToLexical>(out: &mut String, n: N)
{
+ // i64::FORMATTED_SIZE is the upper bound for all integer types we support
+ // (i8/i16/i32/i64). With power-of-two feature it's 128, otherwise 20.
+ // We can't use N::FORMATTED_SIZE in a generic function
(generic_const_exprs).
+ let mut buf = [0u8; i64::FORMATTED_SIZE];
+ let written = lexical_core::write(n, &mut buf);
+ // Lexical core produces valid UTF-8
+ out.push_str(unsafe { std::str::from_utf8_unchecked(written) });
+}
+
+fn write_variant_to_string(
+ variant: &Variant<'_, '_>,
+ formats: &TemporalFormats<'_>,
+ out: &mut String,
+) -> bool {
+ match variant {
+ Variant::Null => {
+ out.push_str(formats.null());
+ true
+ }
+ Variant::String(s) => {
+ out.push_str(s);
+ true
+ }
+ Variant::ShortString(s) => {
+ out.push_str(s);
+ true
+ }
+ Variant::BooleanTrue => {
+ out.push_str("true");
+ true
+ }
+ Variant::BooleanFalse => {
+ out.push_str("false");
Review Comment:
here
##########
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:
Should we keep this private then?
##########
parquet-variant-compute/src/type_conversion.rs:
##########
@@ -705,6 +709,230 @@ pub(crate) fn variant_to_boolean(variant: &Variant<'_,
'_>, shred: bool) -> Opti
}
}
+#[inline]
+fn write_float_to_string<F: Float>(f: F, out: &mut String) {
+ let mut buffer = ryu::Buffer::new();
+ out.push_str(buffer.format(f));
+}
+
+// convert a variant to an owned string.
+pub(crate) fn variant_to_string(
+ variant: &Variant<'_, '_>,
+ formats: &TemporalFormats<'_>,
+) -> Option<String> {
+ if matches!(variant, Variant::Null) {
+ return None;
+ }
+
+ if matches!(variant, Variant::Object(_)) {
+ return None;
+ }
+ let mut s = String::new();
Review Comment:
here
##########
parquet-variant-compute/src/variant_to_arrow.rs:
##########
@@ -1274,7 +1436,15 @@ macro_rules! define_variant_to_primitive_builder {
}
define_variant_to_primitive_builder!(
- struct VariantToStringArrowBuilder<'a, B: StringLikeArrayBuilder>
+ struct VariantToStringGetArrowBuilder<'a, B: StringLikeArrayBuilder>
+ |capacity| -> B { B::with_capacity(capacity) },
+ |value; temporal_formats: formats| variant_to_string(value, formats),
+ type_name: B::type_name(),
+ append_value: |builder, v| builder.append_value(&v)
Review Comment:
here
--
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]