HashDistributionSortedTableOnePartitionSpec:
+ See https://iceberg.apache.org/docs/1.6.0/spark-writes/#writing-distribution-modes
Using write.distribution-mode
- should create the appropriate number of Iceberg files
+ Given a table that has a distribution mode of
hash
and is created with:
CREATE TABLE polaris.my_namespace.HashDistributionSortedTableOnePartitionSpec (
id int,
label String,
partitionKey long,
date Date,
timestamp Timestamp
) USING iceberg TBLPROPERTIES (
'format-version' = '2',
'write.spark.fanout.enabled' = 'true',
'write.distribution-mode' = 'hash',
'sort-order' = 'partitionKey ASC NULLS FIRST',
'spark.sql.adaptive.advisoryPartitionSizeInBytes' = '1073741824',
'write.spark.advisory-partition-size-bytes' = '1073741824',
'write.target-file-size-bytes' = '1073741824'
) PARTITIONED BY (partitionKey);
+ And a query plan that looks like:
== Optimized Logical Plan ==
Repartition 6, true, Statistics(sizeInBytes=6.3 MiB)
+- Project [id#3324, partitionKey#3326L, date#3327, timestamp#3328, concat(cast(otherId#3342L as string), xxx) AS label#3361], Statistics(sizeInBytes=6.3 MiB)
+- Join Inner, (partitionKey#3326L = otherId#3342L), Statistics(sizeInBytes=4.9 MiB)
:- LocalRelation [id#3324, partitionKey#3326L, date#3327, timestamp#3328], Statistics(sizeInBytes=640.0 B, rowCount=20)
+- Project [value#3339L AS otherId#3342L], Statistics(sizeInBytes=7.8 KiB)
+- SerializeFromObject [input[0, bigint, false] AS value#3339L], Statistics(sizeInBytes=7.8 KiB)
+- MapElements uk.co.odinconsultants.iceberg.distributions.AbstractWriteDistributionSpec$$Lambda$5586/0x0000000802566990@21154c66, class java.lang.Long, [StructField(value,LongType,true)], obj#3338: bigint, Statistics(sizeInBytes=7.8 KiB)
+- DeserializeToObject staticinvoke(class java.lang.Long, ObjectType(class java.lang.Long), valueOf, id#3334L, true, false, true), obj#3337: java.lang.Long, Statistics(sizeInBytes=7.8 KiB)
+- Range (0, 1000, step=1, splits=Some(4)), Statistics(sizeInBytes=7.8 KiB, rowCount=1.00E+3)
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- Exchange RoundRobinPartitioning(6), REPARTITION_BY_NUM, [plan_id=5668]
+- Project [id#3324, partitionKey#3326L, date#3327, timestamp#3328, concat(cast(otherId#3342L as string), xxx) AS label#3361]
+- BroadcastHashJoin [partitionKey#3326L], [otherId#3342L], Inner, BuildLeft, false
:- BroadcastExchange HashedRelationBroadcastMode(List(input[1, bigint, false]),false), [plan_id=5665]
: +- LocalTableScan [id#3324, partitionKey#3326L, date#3327, timestamp#3328]
+- Project [value#3339L AS otherId#3342L]
+- SerializeFromObject [input[0, bigint, false] AS value#3339L]
+- MapElements uk.co.odinconsultants.iceberg.distributions.AbstractWriteDistributionSpec$$Lambda$5586/0x0000000802566990@21154c66, obj#3338: bigint
+- DeserializeToObject staticinvoke(class java.lang.Long, ObjectType(class java.lang.Long), valueOf, id#3334L, true, false, true), obj#3337: java.lang.Long
+- Range (0, 1000, step=1, splits=4)
+ And it has 20 rows over 1 data file(s) when writing with 4 executor threads
+ When we add another 20 rows of the same data that is logically distributed over 1 partition(s)
+ Then there are now 1 more data files
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +