scovich commented on code in PR #8299:
URL: https://github.com/apache/arrow-rs/pull/8299#discussion_r2334676236
##########
parquet-variant-compute/src/type_conversion.rs:
##########
@@ -17,46 +17,18 @@
//! Module for transforming a typed arrow `Array` to `VariantArray`.
-/// Convert the input array to a `VariantArray` row by row, using `method`
-/// not requiring a generic type to downcast the generic array to a specific
-/// array type and `cast_fn` to transform each element to a type compatible
with Variant
-/// If `strict` is true(default), return error on conversion failure. If
false, insert null.
-macro_rules! non_generic_conversion_array {
- ($array:expr, $cast_fn:expr, $builder:expr) => {{
- let array = $array;
- for i in 0..array.len() {
- if array.is_null(i) {
- $builder.append_null();
- continue;
- }
- let cast_value = $cast_fn(array.value(i));
- $builder.append_variant(Variant::from(cast_value));
- }
- }};
- ($array:expr, $cast_fn:expr, $builder:expr, $strict:expr) => {{
- let array = $array;
- for i in 0..array.len() {
- if array.is_null(i) {
- $builder.append_null();
- continue;
- }
- match $cast_fn(array.value(i)) {
- Some(cast_value) => {
- $builder.append_variant(Variant::from(cast_value));
- }
- None if $strict => {
- return Err(ArrowError::ComputeError(format!(
- "Failed to convert value at index {}: conversion
failed",
- i
- )));
- }
- None => $builder.append_null(),
- }
- }
- Ok::<(), ArrowError>(())
- }};
+/// Options for controlling the behavior of `cast_to_variant_with_options`.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct CastOptions {
Review Comment:
Moved from cast_to_variant.rs
##########
parquet-variant-compute/src/cast_to_variant.rs:
##########
@@ -15,131 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-use std::collections::HashMap;
-use std::sync::Arc;
-
-use crate::type_conversion::{
- decimal_to_variant_decimal, generic_conversion_array,
non_generic_conversion_array,
- primitive_conversion_array, timestamp_to_variant_timestamp,
-};
-use crate::{VariantArray, VariantArrayBuilder};
-use arrow::array::{
- Array, AsArray, OffsetSizeTrait, TimestampMicrosecondArray,
TimestampMillisecondArray,
- TimestampNanosecondArray, TimestampSecondArray,
-};
-use arrow::buffer::{OffsetBuffer, ScalarBuffer};
-use arrow::compute::kernels::cast;
-use arrow::datatypes::{
- i256, ArrowNativeType, BinaryType, BinaryViewType, Date32Type, Date64Type,
Decimal128Type,
- Decimal256Type, Decimal32Type, Decimal64Type, Float16Type, Float32Type,
Float64Type, Int16Type,
- Int32Type, Int64Type, Int8Type, LargeBinaryType, RunEndIndexType,
Time32MillisecondType,
- Time32SecondType, Time64MicrosecondType, Time64NanosecondType, UInt16Type,
UInt32Type,
- UInt64Type, UInt8Type,
-};
-use arrow::temporal_conversions::{
- timestamp_ms_to_datetime, timestamp_ns_to_datetime,
timestamp_s_to_datetime,
- timestamp_us_to_datetime,
-};
-use arrow_schema::{ArrowError, DataType, FieldRef, TimeUnit, UnionFields};
-use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
-use parquet_variant::{
- Variant, VariantBuilder, VariantDecimal16, VariantDecimal4,
VariantDecimal8,
-};
-
-/// Options for controlling the behavior of `cast_to_variant_with_options`.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct CastOptions {
- /// If true, return error on conversion failure. If false, insert null for
failed conversions.
- pub strict: bool,
-}
-
-impl Default for CastOptions {
- fn default() -> Self {
- Self { strict: true }
- }
-}
Review Comment:
Moved to type_conversions.rs
##########
parquet-variant/src/builder.rs:
##########
@@ -1758,6 +1771,34 @@ impl VariantBuilderExt for VariantBuilder {
}
}
+/// A [`VariantBuilderExt`] that inserts a new field into a variant object.
+pub struct ObjectFieldBuilder<'o, 'v, 's> {
Review Comment:
Moved from from_json.rs
--
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]