pvary commented on code in PR #14297: URL: https://github.com/apache/iceberg/pull/14297#discussion_r2924394352
########## spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkParquetWriterWithVariantShredding.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; +import org.apache.iceberg.FieldMetrics; +import org.apache.iceberg.Schema; +import org.apache.iceberg.parquet.ParquetValueWriter; +import org.apache.iceberg.parquet.TripleWriter; +import org.apache.iceberg.parquet.WriterLazyInitializable; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.spark.SparkSQLProperties; +import org.apache.iceberg.spark.data.ParquetWithSparkSchemaVisitor; +import org.apache.iceberg.spark.data.SparkParquetWriters; +import org.apache.iceberg.types.Types; +import org.apache.parquet.column.ColumnWriteStore; +import org.apache.parquet.column.ParquetProperties; +import org.apache.parquet.compression.CompressionCodecFactory; +import org.apache.parquet.hadoop.ColumnChunkPageWriteStore; +import org.apache.parquet.schema.MessageType; +import org.apache.spark.sql.catalyst.InternalRow; +import org.apache.spark.sql.types.StructType; + +/** + * A Parquet output writer that performs variant shredding with schema inference. + * + * <p>The writer works in two phases: 1. Schema inference phase: Buffers initial rows and analyzes + * variant data to infer schemas 2. Writing phase: Creates the actual Parquet writer with inferred + * schemas and writes all data + */ +public class SparkParquetWriterWithVariantShredding Review Comment: One of the main reason for introducing the `engineSchema` to the WriterFunction is that it could drive the decision how to write out the variants if they are already shredded in the engine data. I understand that in this case we don't have variant in the engine schema, but we would like to decide dynamically how to shred based on the first few input records. What if we create a ShreddedWriter which just collects the data, and don't create the underlying writer yet. Then based on the collected info and the properties based on the `ModelWriteBuilder.set` creates the underlying writer - writes out the records and then continues delegating the write. Could this work? -- 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]
