steveloughran commented on code in PR #15629:
URL: https://github.com/apache/iceberg/pull/15629#discussion_r3588099705


##########
spark/v4.1/spark/src/jmh/java/org/apache/iceberg/parquet/IcebergSourceVariantIOBenchmark.java:
##########
@@ -0,0 +1,915 @@
+/*
+ * 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.parquet;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.data.parquet.GenericParquetWriter;
+import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.spark.source.IcebergSourceBenchmark;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.variants.ShreddedObject;
+import org.apache.iceberg.variants.ValueArray;
+import org.apache.iceberg.variants.Variant;
+import org.apache.iceberg.variants.VariantMetadata;
+import org.apache.iceberg.variants.Variants;
+import org.apache.parquet.column.statistics.Statistics;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.BlockMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.parquet.schema.Type;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RuntimeConfig;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Timeout;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A benchmark that evaluates the performance of reading and filtering variant 
data through
+ * Iceberg's Spark data source.
+ *
+ * <p>Three tables are created with identical data:
+ *
+ * <ol>
+ *   <li>avro records containing the bytes
+ *   <li>unshredded variant object
+ *   <li>fully shredded variant object
+ * </ol>
+ *
+ * <p>The table structure is:
+ *
+ * <pre>
+ *   id: int64 :- unique per row
+ *   category: int32 :- in a very small range; written in clustered order so 
each Parquet row group should
+ *     contain very few entries from different ranges.
+ *   nested: variant (object)
+ *       .idstr: string :- unique string per row
+ *       .varid: int64  :- id
+ *       .varcategory: int32
+ *       .col4: string :- non-unique string per row (same number as category 
count)
+ *   arr: variant (array, always unshredded)
+ *       [0]: int32 :- category
+ *       [1]: int32 :- id % 20
+ *       [2]: int32 :- id % 100
+ *       [3]: int32 :- id % 50
+ *       [4]: int32 :- id % 1000
+ * </pre>
+ *
+ * <p>Arrays don't shred because they are anonymous.
+ *
+ * <p>All data is written into a single file to keep the Spark task count to 
1. Combined with a
+ * {@code local[1]} Spark master, all benchmark iterations execute on a single 
thread, which
+ * eliminates inter-task scheduling noise and makes measurements reproducible.
+ *
+ * <p>The structure and repetition helps highlight the space-saving benefits 
of parquet and shredded
+ * parquet, irrespective of performance — look in the output logs for "Size of 
Table" to see the
+ * values.
+ *
+ * <p>To run this benchmark for spark-4.1: <code>
+ *   ./gradlew -DsparkVersions=4.1 :iceberg-spark:iceberg-spark-4.1_2.13:jmh \
+ *       -PjmhIncludeRegex=IcebergSourceVariantIOBenchmark \
+ *       
-PjmhOutputPath=build/reports/benchmark/iceberg-source-variant-io-benchmark-result.txt
+ * </code>
+ */
+@Fork(1)
+@Warmup(iterations = 5)
+@Measurement(iterations = 5)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Timeout(time = 60, timeUnit = TimeUnit.MINUTES)
+public class IcebergSourceVariantIOBenchmark extends IcebergSourceBenchmark {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(IcebergSourceVariantIOBenchmark.class);
+
+  /** Table to use in benchmark. */
+  @Param({"Avro", "Unshredded", "Shredded"})
+  private TableType tableType;
+
+  private static final int NUM_FILES = 1;
+  private static final int NUM_ROWS_PER_FILE = 100_000;
+
+  /** Size of a compressed rowgroup. */
+  private static final int ROW_GROUP_SIZE = 1 * 1024 * 1024;
+
+  /** Number of distinct category values. */
+  private static final int NUM_CATEGORIES = 10;
+
+  public static final String COL_ID = "id";

Review Comment:
   I'll make them all private,inevitably just ide refactoring setup



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

Reply via email to