-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Core, Data, Spark: Moving Spark to use the new FormatModel API #15328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
320ac20
4633b6f
6ae7eaa
576a7c9
4419dc3
b1c225b
025210f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,17 @@ | |
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import org.apache.iceberg.FileFormat; | ||
| import org.apache.iceberg.Files; | ||
| import org.apache.iceberg.PartitionSpec; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.encryption.EncryptedFiles; | ||
| import org.apache.iceberg.formats.FormatModelRegistry; | ||
| import org.apache.iceberg.io.DataWriter; | ||
| import org.apache.iceberg.io.FileAppender; | ||
| import org.apache.iceberg.parquet.Parquet; | ||
| import org.apache.iceberg.spark.SparkSchemaUtil; | ||
| import org.apache.iceberg.spark.data.RandomData; | ||
| import org.apache.iceberg.spark.data.SparkParquetWriters; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.apache.spark.sql.execution.datasources.parquet.ParquetWriteSupport; | ||
|
|
@@ -95,15 +99,16 @@ public void tearDownBenchmark() { | |
| @Benchmark | ||
| @Threads(1) | ||
| public void writeUsingIcebergWriter() throws IOException { | ||
| try (FileAppender<InternalRow> writer = | ||
| Parquet.write(Files.localOutput(dataFile)) | ||
| .createWriterFunc( | ||
| msgType -> | ||
| SparkParquetWriters.buildWriter(SparkSchemaUtil.convert(SCHEMA), msgType)) | ||
| try (DataWriter<InternalRow> writer = | ||
| FormatModelRegistry.dataWriteBuilder( | ||
| FileFormat.PARQUET, | ||
| InternalRow.class, | ||
| EncryptedFiles.plainAsEncryptedOutput(Files.localOutput(dataFile))) | ||
| .schema(SCHEMA) | ||
| .spec(PartitionSpec.unpartitioned()) | ||
| .build()) { | ||
|
|
||
| writer.addAll(rows); | ||
| writer.write(rows); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -121,6 +126,7 @@ public void writeUsingSparkWriter() throws IOException { | |
| .set("spark.sql.parquet.outputTimestampType", "TIMESTAMP_MICROS") | ||
| .set("spark.sql.caseSensitive", "false") | ||
| .set("spark.sql.parquet.fieldId.write.enabled", "false") | ||
| .set("spark.sql.parquet.variant.annotateLogicalType.enabled", "false") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests were failing with Spark 4.1, but probably doesn't worth to create a new PR for this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we file an issue to track the underlying Spark 4.1 test failure, so we can fix the root cause later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both "true" and "false" is ok as well. The issue was that the config was not set. |
||
| .schema(SCHEMA) | ||
| .build()) { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
| import org.apache.iceberg.FieldMetrics; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.parquet.ParquetValueReaders.ReusableEntry; | ||
| import org.apache.iceberg.parquet.ParquetValueWriter; | ||
| import org.apache.iceberg.parquet.ParquetValueWriters; | ||
|
|
@@ -41,6 +42,7 @@ | |
| import org.apache.iceberg.parquet.VariantWriterBuilder; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.spark.SparkSchemaUtil; | ||
| import org.apache.iceberg.types.TypeUtil; | ||
| import org.apache.iceberg.util.DecimalUtil; | ||
| import org.apache.iceberg.util.UUIDUtil; | ||
|
|
@@ -75,10 +77,27 @@ | |
| public class SparkParquetWriters { | ||
| private SparkParquetWriters() {} | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static <T> ParquetValueWriter<T> buildWriter(StructType dfSchema, MessageType type) { | ||
| return buildWriter(null, type, dfSchema); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static <T> ParquetValueWriter<T> buildWriter( | ||
| Schema icebergSchema, MessageType type, StructType dfSchema) { | ||
| return (ParquetValueWriter<T>) | ||
| ParquetWithSparkSchemaVisitor.visit( | ||
| dfSchema != null ? dfSchema : SparkSchemaUtil.convert(icebergSchema), | ||
| type, | ||
| new WriteBuilder(type)); | ||
| } | ||
|
|
||
| public static <T> ParquetValueWriter<T> buildWriter( | ||
| StructType dfSchema, MessageType type, Schema icebergSchema) { | ||
| return (ParquetValueWriter<T>) | ||
| ParquetWithSparkSchemaVisitor.visit(dfSchema, type, new WriteBuilder(type)); | ||
| ParquetWithSparkSchemaVisitor.visit( | ||
| dfSchema != null ? dfSchema : SparkSchemaUtil.convert(icebergSchema), | ||
| type, | ||
| new WriteBuilder(type)); | ||
| } | ||
|
Comment on lines
+84
to
101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it intentional here to have 2 functions with different signature ordering? might be confusing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve given this quite a bit of thought. On the caller side we use the order |
||
|
|
||
| private static class WriteBuilder extends ParquetWithSparkSchemaVisitor<ParquetValueWriter<?>> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were failing with Spark 4.1, but probably doesn't worth to create a new PR for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with this since it isn't production code. It's unlikely that this is going to cause problems cherry-picking.