voonhous commented on code in PR #18961:
URL: https://github.com/apache/hudi/pull/18961#discussion_r3850249993


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/row/VariantShreddingInferenceInternalRowFileWriter.java:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.hudi.io.storage.row;
+
+import org.apache.hudi.SparkAdapterSupport$;
+import org.apache.hudi.common.avro.VariantShreddingSchemaInferrer;
+import 
org.apache.hudi.common.avro.VariantShreddingSchemaInferrer.VariantSample;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.util.CloseableUtils;
+import org.apache.hudi.common.util.DefaultSizeEstimator;
+import org.apache.hudi.core.io.storage.VariantShreddingInferenceFileWriter;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.expressions.UnsafeRow;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.unsafe.types.UTF8String;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A {@link HoodieInternalRowFileWriter} decorator that infers a per-file 
variant shredding
+ * schema from the first rows before opening the real parquet writer; the 
row-writer-path
+ * sibling of {@link VariantShreddingInferenceFileWriter}, sharing its 
buffering thresholds and
+ * failure semantics.
+ *
+ * <p>Meta columns including the commit seqno are composed into the row by the 
handle BEFORE
+ * {@code writeRow}, so ordered replay is value-exact here by construction. 
Rows and keys are
+ * copied because Spark iterators reuse their instances.</p>
+ */
+@Slf4j
+public class VariantShreddingInferenceInternalRowFileWriter implements 
HoodieInternalRowFileWriter {
+
+  private static final int SIZE_ESTIMATE_INTERVAL = 100;
+
+  /** Creates the real row file writer once the inferred typed_value schemas 
are known. */
+  @FunctionalInterface
+  public interface InferredRowWriterFactory {
+    HoodieInternalRowFileWriter create(Map<String, HoodieSchema> 
inferredTypedValues) throws IOException;
+  }
+
+  private final List<String> variantColumns;
+  private final int[] ordinals;
+  private final VariantShreddingSchemaInferrer inferrer;
+  private final InferredRowWriterFactory writerFactory;
+  private final long maxBufferedBytes;
+  private final DefaultSizeEstimator<InternalRow> sizeEstimator = new 
DefaultSizeEstimator<>();
+
+  private final List<BufferedRow> buffer = new ArrayList<>();
+  private final List<VariantSample[]> samples = new ArrayList<>();
+  private long bufferedBytes = 0;
+  private long estimatedRowSize = 0;
+  private long estimatedRowCount = 0;
+  private HoodieInternalRowFileWriter delegate;
+  private IOException fatalFailure;
+  private boolean closed = false;
+
+  public VariantShreddingInferenceInternalRowFileWriter(List<String> 
variantColumns,
+                                                        int[] ordinals,
+                                                        
VariantShreddingSchemaInferrer inferrer,
+                                                        
InferredRowWriterFactory writerFactory,
+                                                        long maxFileSize) {
+    this.variantColumns = variantColumns;
+    this.ordinals = ordinals;
+    this.inferrer = inferrer;
+    this.writerFactory = writerFactory;
+    this.maxBufferedBytes = 
Math.min(VariantShreddingInferenceFileWriter.MAX_BUFFERED_BYTES, Math.max(1, 
maxFileSize));

Review Comment:
   Pinned on both twins: one UnsafeRow (row writer) or one record with a 64MB 
payload (record writer) at `MAX_BUFFERED_BYTES` materializes with `maxFileSize` 
at `Long.MAX_VALUE`; dropping the min fails both. The row is allocated for real 
rather than pointed at a small buffer: the decorator copies it, and 
`UnsafeRow.copy()` reads `sizeInBytes` bytes from the backing array.



-- 
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]

Reply via email to