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


##########
spark/v4.1/spark/src/jmh/java/org/apache/iceberg/parquet/IcebergSourceVariantIOBenchmark.java:
##########
@@ -0,0 +1,538 @@
+/*
+ * 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 java.io.IOException;
+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.Variant;
+import org.apache.iceberg.variants.VariantMetadata;
+import org.apache.iceberg.variants.Variants;
+import org.apache.parquet.schema.Type;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Fork;
+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.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
+ *   <li>fully shredded variant
+ * </ol>
+ *
+ * <p>The table structure is:
+ *
+ * <pre>
+ *   id: int64 :- unique per row
+ *   category: int32 :- in range 0-19:  (fileNum % 2) * 10 + (id % 10);
+ *   nested: variant
+ *       .idstr: string :- unique string per row
+ *       .varid: int64  :- id
+ *       .varcategory: int32  :- category (0-19)
+ *       .col4: string :- non-unique string per row (picked from 20 values 
based on category)
+ * </pre>
+ *
+ * <p>The structure and repetition helps highlight the space-saving benefits 
of parquet and shedded
+ * 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 = 4)
+@Measurement(iterations = 8)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Timeout(time = 10, timeUnit = TimeUnit.MINUTES)
+public class IcebergSourceVariantIOBenchmark extends IcebergSourceBenchmark {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(IcebergSourceVariantIOBenchmark.class);
+
+  private static final int NUM_FILES = 4;
+  private static final int NUM_ROWS_PER_FILE = 250_000;
+
+  public static final String COL_ID = "id";
+
+  /** Name of the Spark temp view registered in {@link #setupBenchmark()}. */
+  private static final String TEMP_VIEW = "variant_table";
+
+  private static final Schema SCHEMA =
+      new Schema(
+          required(1, COL_ID, Types.LongType.get()),
+          required(2, "category", Types.IntegerType.get()),
+          required(3, "nested", Types.VariantType.get())); /* The variant. */
+
+  /** Filter to use when filtering on category column: {@value}. */
+  private static final String FILTER_ON_CATEGORY = "category = 5";
+
+  /** Get the category column from the variant: {@value}. */
+  private static final String VARIANT_GET_NESTED_CATEGORY =
+      "variant_get(nested, '$.varcategory', 'int')";
+
+  /** Get the ID field from inside the variant: {@value}. */
+  private static final String VARIANT_GET_NESTED_ID = "variant_get(nested, 
'$.varid', 'int')";

Review Comment:
   moved to `bigint`. Not doing enough with that type to measure any difference 
between that and int processing in the workflow.



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