gkpanda4 commented on code in PR #14297: URL: https://github.com/apache/iceberg/pull/14297#discussion_r2713971629
########## spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/VariantShreddingAnalyzer.java: ########## @@ -0,0 +1,323 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.spark.source; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.variants.PhysicalType; +import org.apache.iceberg.variants.VariantArray; +import org.apache.iceberg.variants.VariantMetadata; +import org.apache.iceberg.variants.VariantObject; +import org.apache.iceberg.variants.VariantPrimitive; +import org.apache.iceberg.variants.VariantValue; +import org.apache.parquet.schema.GroupType; +import org.apache.parquet.schema.LogicalTypeAnnotation; +import org.apache.parquet.schema.PrimitiveType; +import org.apache.parquet.schema.Type; +import org.apache.parquet.schema.Types; +import org.apache.spark.sql.catalyst.InternalRow; +import org.apache.spark.unsafe.types.VariantVal; + +/** + * Analyzes variant data across buffered rows to determine an optimal shredding schema. + * + * <ul> + * <li>shred to the most common type + * </ul> + */ +public class VariantShreddingAnalyzer { Review Comment: Can you add a test scenario for a field, for example, ZIP codes like 98101, 97201, and 10001, it get parsed as different integer types (INT32 + INT16). Should having a type family check makes more sense? Like grouping them as * Integer Family: INT8, INT16, INT32, INT64 → promote to most capable type * Decimal Family: DECIMAL4, DECIMAL8, DECIMAL16 → promote to most capable type * Boolean Family: TRUE, FALSE → treat as single boolean type Bit on lines with Spark side implementation https://github.com/apache/spark/pull/52406/files#diff-fb3268e5296f089d5f57c168f3e9cd74a401b184db3f30982588a134d8abfa53R322-R326 where all integer types are converted to Long -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
