Iceberg Configurations and Types
Mapping between Spark types and Iceberg types
Spark and Iceberg support different type sets. Iceberg automatically performs type conversions, but not all mapping types are supported. Therefore, you need to understand the type conversions in Iceberg before designing the column types of a table.
Iceberg types corresponding to Spark types
The following table describes how Spark types are converted to Iceberg types. The conversion applies to both the creation of Iceberg tables and the writing of data to Iceberg tables through Spark.
| Spark | Iceberg |
|---|---|
| boolean | boolean |
| short | integer |
| byte | integer |
| integer | integer |
| long | long |
| float | float |
| double | double |
| date | date |
| timestamp | timestamp with timezone |
| timestamp_ntz | timestamp without timezone |
| char | string |
| varchar | string |
| string | string |
| binary | binary |
| decimal | decimal |
| struct | struct |
| array | list |
| map | map |
This table mainly shows the type conversions at the time of table creation. In practice, a wider range of types are supported for conversions during write operations. Here are some key points during write operations:
- Iceberg numeric types (integer, long, float, double, decimal) support type promotion during write operations. For example, you can write Spark data of the short, byte, integer, and long types to Iceberg data of the long type.
- You can write Spark data of the binary type to Iceberg data of the fixed type. Note that length assertions will be performed during this process.
Spark types corresponding to Iceberg types
The following table describes how Iceberg types are converted to Spark types. The conversion applies to the reading of Iceberg tables through Spark.
| Iceberg | Spark |
|---|---|
| boolean | boolean |
| integer | integer |
| long | long |
| float | float |
| double | double |
| date | date |
| time | Not supported |
| timestamp with timezone | timestamp |
| timestamp without timezone | timestamp_ntz |
| string | string |
| uuid | string |
| fixed | binary |
| binary | binary |
| decimal | decimal |
| struct | struct |
| list | array |
| map | map |
| nanosecond timestamp | Not supported |
| nanosecond timestamp with timezone | Not supported |
| unknown | Not supported |
| variant | variant NOTE: Spark 4.0+ is supported. |
| geometry | Not supported |
| geography | Not supported |
Runtime Configuration
Configuration Setting Priority
Iceberg allows configuration to be specified at different levels. The effective configuration for a read or write operation is determined by the following priority order:
- DataSourceAPI read/write options: Use .option(...) in read/write operations to explicitly transfer the options.
- Spark session configurations: Use spark.conf.set(...), spark-defaults.conf, or --conf in spark-submit for global settings.
- Table properties: Set the properties in the Iceberg table by running ALTER TABLE SET TBLPROPERTIES.
- Default value:
Use the next-level configurations as a backup if no higher-level configurations are defined. This allows global default values to be enabled when needed, maintaining flexibility.
Spark SQL options
Iceberg allows you to set various global behaviors using Spark SQL configuration options. These can be set using Spark, SparkSession configurations, or spark-submit parameters. For example:
//Disable vectorization.
val spark = SparkSession.builder()
.appName("IcebergExample")
.master("local[*]")
.config("spark.sql.catalog.my_catalog","org.apache.iceberg.spark.SparkCatalog")
.config("spark.sql.extensions","org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
.config("spark.sql.iceberg.vectorization.enabled","false")
.getOrCreate() | Spark Option | Default Value | Description |
|---|---|---|
| spark.sql.iceberg.vectorization.enabled | Inherits from table properties. (Parquet: the default value of read.parquet.vectorization.enabled is true. ORC: The default value of read.orc.vectorization.enabled is false.) | Controls whether to enable vectorized read of data files.
|
| spark.sql.iceberg.parquet.reader-type | ICEBERG | Sets the Parquet reader implementation. The options are as follows:
|
| spark.sql.iceberg.check-nullability | true | Checks whether the nullability of the write schema matches the nullability of the table.
|
| spark.sql.iceberg.check-ordering | true | Checks whether the column order of the write schema matches the column order of the table schema.
|
| spark.sql.iceberg.planning.preserve-data-grouping | false |
|
| spark.sql.iceberg.aggregate-push-down.enabled | true | Controls whether to push down aggregate functions (MAX, MIN, and COUNT).
|
| spark.sql.iceberg.distribution-mode | Determined based on your environment:
| Controls the data distribution policy during write operations. The options are as follows:
For details, see Writing Data to an Iceberg Table. |
| spark.wap.id | null | Specifies the write-audit-release (WAP) snapshot staging ID. After this parameter is set, a new snapshot is created in the staged state and associated with this ID. You need to manually publish the snapshot. If this parameter is set to null, the snapshot is directly committed. Before setting this parameter, set the table property write.wap.enabled to true. |
| spark.wap.branch | null | Specifies the WAP branch name. After this parameter is set, the snapshot is committed to the specified branch instead of the main branch to isolate the development or test environment. If this parameter is set to null, the snapshot is committed to the current branch. Before setting this parameter, set the table property write.wap.enabled to true. |
| spark.sql.iceberg.compression-codec | Inherits from table properties. (Parquet: The default value of write.parquet.compression-codec is zstd. Avro: The default value of write.avro.compression-codec is gzip. ORC: The default value of write.orc.compression-codec is zlib.) | Specifies the compression codec used for writing data. Different file formats support different codecs:
|
| spark.sql.iceberg.compression-level | Inherits from table properties (Parquet: the default value of write.parquet.compression-level is null. Avro: the default value of write.avro.compression-level is null.) | Specifies the compression level of Parquet/Avro files. Generally, the value is an integer ranging from 1 to 9. A larger value indicates a higher compression ratio but a slower speed. The default value null indicates that the default level of the codec is used. This parameter is valid only for codecs that support level configurations, such as gzip, zstd, and deflate. |
| spark.sql.iceberg.compression-strategy | Inherits from the table property write.orc.compression-strategy (default value: speed). | Specifies the ORC compression policy. The options are as follows:
|
| spark.sql.iceberg.data-planning-mode | Inherits from the table property read.data-planning-mode (default value: AUTO). | Specifies the scan planning mode of data files. The options are as follows:
|
| spark.sql.iceberg.delete-planning-mode | Inherits from the table property read.delete-planning-mode (default value: AUTO). | Specifies the scan planning mode of the deletion files. The options are as follows:
|
| spark.sql.iceberg.advisory-partition-size | Inherits from the table property write.target-file-size-bytes (default value: 536870912, that is, 512 MB). | Specifies the recommended partition size (in bytes) for writing data to a table when Spark Adaptive Query Execution (AQE) is enabled. It is used to adjusts the size of the output files, which affects the amount of data written by each task. |
| spark.sql.iceberg.locality.enabled | false | Controls whether to report the localization information of Spark tasks on the executor.
|
| spark.sql.iceberg.executor-cache.enabled | true | Controls whether to enable the cache on the executor.
|
| spark.sql.iceberg.executor-cache.timeout | 10 (10 minutes) | Specifies the timeout interval for a cache entry, in minutes. Cache entries that are not accessed within this period will be cleared. |
| spark.sql.iceberg.executor-cache.max-entry-size | 67108864 (64 MB) | Specifies the maximum size of each cache entry, in bytes. Files larger than this size will not be cached. |
| spark.sql.iceberg.executor-cache.max-total-size | 134217728 (128 MB) | Specifies the maximum total size of the executor cache, in bytes. When the total cache size exceeds this value, old entries are evicted based on the least recently used (LRU) policy. |
| spark.sql.iceberg.executor-cache.locality.enabled | false |
|
| spark.sql.iceberg.merge-schema | false | Controls whether to modify the table schema to match the schema of the written data.
|
| spark.sql.iceberg.report-column-stats | true | Controls whether to report the Puffin table statistics to the cost-based optimizer (CBO) of Spark.
|
Read options
Spark read options are transferred when DataFrame Reader is configured, as shown below:
//Time travel
spark.read
.option("snapshot-id",10963874102873L)
.table("catalog.db.table") | Spark Option | Default Value | Description |
|---|---|---|
| snapshot-id | null | Specifies the ID (long type) of the table snapshot to be read. It is used for the TimeTravel function to read data from a specified historical version. This parameter is mutually exclusive with as-of-timestamp. If this parameter is set to null, the latest snapshot is read. |
| as-of-timestamp | null | Specifies a timestamp in milliseconds (long type). If this parameter is set, the latest snapshot generated before this timestamp is used. It is used for time-based historical data query. This parameter is mutually exclusive with snapshot-id. If both parameters are set, snapshot-id takes precedence. If this parameter is set to null, the latest snapshot is read. |
| split-size | Inherits from the table properties. (The default value of read.split.target-size is 134217728, that is, 128 MB. The default value of read.split.metadata-target-size is 33554432, that is, 32 MB.) | Overrides the table's read.split.target-size (target size of data file splitting) and read.split.metadata-target-size (target size of metadata file splitting). It is used to control the amount of data processed by each Spark task. A smaller value indicates more tasks to be generated. |
| lookback | Inherits from the table property read.split.planning-lookback (default value: 10). | Overrides the table's read.split.planning-lookback. It specifies the number of files that are backtracked when splits are planned, which is used to merge small files into the same split. A larger value indicates more files to be merged but a longer planning time. |
| file-open-cost | Inherits from the table property read.split.open-file-cost. The default value is 4194304, that is, 4 MB. | Overrides the table's read.split.open-file-cost. It indicates the estimated cost (in bytes) of opening a file, which is used for cost optimization during split planning. |
| vectorization-enabled | Inherits from table properties. (Parquet: the default value of read.parquet.vectorization.enabled is true. ORC: The default value of read.orc.vectorization.enabled is false.) | Overrides the vectorized read switch of this table. If this parameter is set to true, Parquet/ORC vectorized read is enabled, and columnar batch processing is used to improve query performance. If this parameter is set to false, a non-vectorized row-by-row reader is used, which offers lower performance but better compatibility. |
| batch-size | Inherits from table properties. (Parquet: The default value of read.parquet.vectorization.batch-size is 5000. ORC: The default value of read.orc.vectorization.batch-size is 5000.) | Overrides the vectorized batch size of this table, that is, the number of rows processed in each batch. Larger batches (for example, 10,000) increase throughput but also increase memory consumption. Smaller batches (for example, 1,000) reduce memory usage but decrease throughput. |
| stream-from-timestamp | null | Specifies a timestamp (long type) in milliseconds as the start point for streaming. If the timestamp is earlier than the oldest known ancestor snapshot, the oldest snapshot is used. If this parameter is set to null, streaming reads start from the latest snapshot. |
| streaming-max-files-per-micro-batch | Integer.MAX_VALUE (2147483647) | Specifies the maximum number of files per micro-batch. It is used to control the number of files processed in each batch of the structured streaming. Setting a smaller value can prevent delays caused by large batches. |
| streaming-max-rows-per-micro-batch | Integer.MAX_VALUE (2147483647) | Specifies the maximum number of rows per micro-batch (soft limit). |
When the streaming-max-rows-per-micro-batch option defines a soft maximum value, a batch will always contain all rows in the next unprocessed data file. However, if including additional files would exceed the soft maximum limit, those files will not be included.
Write options
Spark write options are transferred when DataFrameWriterV2 is configured, as shown below:
//Use Avro instead of Parquet for writing.
df.writeTo("catalog.db.table")
.option("write-format","avro")
.option("snapshot-property.key","value")
.append() | Spark Option | Default Value | Description |
|---|---|---|
| write-format | Inherits from the table property write.format.default (default value: parquet). | Specifies the file format used for the write operation. The options are as follows:
|
| target-file-size-bytes | Inherits from the table property write.target-file-size-bytes (default value: 536870912, that is, 512 MB). | Overrides the table's write.target-file-size-bytes. It is used to control the target size of each output data file. A smaller value results in more small files (which may increase the scanning overhead during queries), while a larger value reduces the number of files but increases the size of a single file (which may increase memory consumption). |
| check-nullability | true | Controls whether to perform the nullability check on a field. If this parameter is set to true, an exception is thrown if a field declared as NOT NULL in the written data contains a null value. If this parameter is set to false, this check is skipped and null values can be written to the NOT NULL field (which may cause subsequent query exceptions). |
| snapshot-property.custom-key | null | Adds an entry with a custom key and corresponding value to the snapshot summary. For example, snapshot-property.user=alice will add {"user":"alice"} to the snapshot metadata. This parameter is used for audit tracking or change marking. (The DSv2 API requires the prefix snapshot-property.) |
| fanout-enabled | false | Overrides the table's write.spark.fanout.enabled.
|
| check-ordering | true | Checks whether the input schema is the same as the table schema.
|
| isolation-level | null | Specifies the isolation level required for DataFrame overwrite operations. The options are as follows:
Default values for table properties:
|
| validate-from-snapshot-id | null | If the isolation level is set, this parameter specifies the baseline snapshot ID (of the long type) for checking concurrent write conflicts in the table. It should be the ID of any snapshot before the table is read. You can obtain the value from the Table API or Snapshots table. If this parameter is set to null, the oldest known snapshot of the table is used. |
| compression-codec | Inherits from table properties. (Parquet: The default value of write.parquet.compression-codec is zstd. Avro: The default value of write.avro.compression-codec is gzip. ORC: The default value of write.orc.compression-codec is zlib.) | Overrides the compression codec used for writing data to this table.
|
| compression-level | Inherits from table properties (Parquet: the default value of write.parquet.compression-level is null. Avro: the default value of write.avro.compression-level is null.) | Overrides the compression level used for writing data in Parquet and Avro formats to this table. The value is an integer ranging from 1 to 9. A larger value indicates a higher compression ratio but a slower compression speed. The default value null indicates that the default level of the codec is used. This parameter is valid only for codecs that support level configurations, such as gzip, zstd, and deflate. |
| compression-strategy | Inherits from the table property write.orc.compression-strategy (default value: speed). | Overrides the compression strategy used for writing data in ORC format to this table. The options are as follows:
|
| distribution-mode | Determined based on your environment. If the table has a sorting order, the value is range. If the table has partitions, the value is hash. In other cases, the value is none. | Overrides the distribution mode used for writing data to this table. The options are as follows:
Default values for table properties: The default values of write.delete.distribution-mode, write.update.distribution-mode, and write.merge.distribution-mode are hash. For details, see Writing Data to an Iceberg Table. |
| delete-granularity | file | Overrides the write and delete granularity used for this table. The options are as follows:
This parameter affects the efficiency of the DELETE operations. The file level is more accurate but generates more small files. The partition level is more efficient but deletes the entire partition. |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot