CertSafari
    Databricks Certified Data Engineer Professional - October 9 onwards· Lessons

    Domain 9 · Lesson 44/45

    Scalable Delta and Iceberg table layouts: partitioning, clustering and file sizing

    Design scalable Delta/Iceberg table layouts for large data assets by mapping partitioning to data grain, aligning clustering to relationship access patterns, and maintaining balanced file sizes through compaction.

    16 min read
    2.5% of exam
    6 sources
    Published 22 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Decide from table size and data grain whether a large table should be partitioned at all, and on which column
    • Choose liquid clustering keys from the filter and join columns that queries use between facts and dimensions
    • Convert a partitioned table to liquid clustering in place and know when OPTIMIZE must follow
    • Keep file sizes balanced with OPTIMIZE, auto compaction, optimized writes and target file sizes, on both Delta and Iceberg tables

    Key concept

    Partition only where the grain yields large partitions — A partition column is justified only when the table is very large and every value of the column still holds at least about 1 GB of data. Below that, use liquid clustering on the columns queries filter by, and let compaction keep the files balanced.

    1.Start from the grain, the predicates and the size

    A table layout covers three decisions that depend on each other: whether to partition, which columns to cluster on, and how large the data files should be. Make them in this order. First identify the grain, meaning what one row represents and how it arrives (one event per row, landing by ingest date). Next list the dominant predicates, the columns that dashboards and jobs filter and join on. Last, estimate the table's size at maturity. Get them wrong and the cost is high. An ineffective partitioning strategy might negatively affect query performance and require a full rewrite of data to fix, and on a large table that rewrite is slow and expensive.

    Size sets the default, and that default is not to partition. Most tables on Databricks with less than 100 TB of data don't need partitioning. Delta automatically clusters unpartitioned tables by ingestion time, which gives the same benefit a date partition would for event data that arrives in date order. If such a table later receives heavy UPDATE or MERGE traffic, keep that ordering with liquid clustering on a column that follows ingestion order, such as an event timestamp or a creation date.

    Partitioning guidance by table size
    Table sizeGuidance
    Under 1 TBDon't partition
    1 TB to 100 TBUse liquid clustering instead of partitioning. Partitioning hurts performance more often than it helps
    100 TB or morePartitioning might help, but try liquid clustering first and verify the improvement

    For a table large enough to partition, the partition column comes from the grain, never from a high-cardinality key. An ingest date or a physical location qualifies, because these columns have low or known cardinality. Timestamps and customer IDs do not, because they produce millions of tiny directories. Then check the arithmetic: divide the table size by the number of distinct partition values. If any partition falls below roughly 1 GB, the scheme costs more than it saves, because tables with fewer, larger partitions tend to perform better. Daily partitions on a table that adds 200 MB a day fail this test, even though the date column matches the grain exactly. The mechanics of Hive-style partitioning and ZORDER are covered in Hive-style partitioning and ZORDER. For layout design, the rule that matters is the 1 GB floor.

    Checkpoint 1 of 8· Match them up

    Match each table size to the Databricks partitioning guidance for it

    Tap a term, then the definition that fits it.

    Checkpoint 2 of 8· Check yourself

    A 400 TB clickstream table holds about three years of events, one row per event, landing by ingest date. Queries filter on customer_id and on date. The team has verified that partitioning beats liquid clustering for this table. Which partition column fits?

    Sources1

    2.Cluster on the columns that relate facts to dimensions

    Liquid clustering replaces partitioning and ZORDER as the main layout tool. It organises files around clustering keys and has no fixed directory boundaries (Liquid Clustering covers how it works). In a design, the main question is which keys to choose. Take them from the relationships queries traverse. On a fact table, that usually means the date column dashboards slice by plus the foreign key that joins to the most-filtered dimension, such as event_date and customer_id on fact_events. File skipping depends on per-file min/max statistics, so clustering rows with similar key values into the same files lets a filter on those keys skip most of the table.

    Creating a table clustered on two keyssql
    CREATE TABLE table1 (
      col0 STRING,
      col1 DATE,
      col2 BIGINT
    )
    CLUSTER BY (col0, col1);

    Several situations favour clustering over partitioning:

    • Queries that filter on high-cardinality columns, such as a customer key
    • Heavily skewed data, where some partitions would be huge and most would be tiny
    • Fast-growing tables whose maintenance would otherwise need constant tuning
    • Access patterns that vary or change as new reports are built
    • Cases where any plausible partition key would return results from too many or too few partitions

    Changing access patterns are what most clearly separate clustering from partitioning. When next quarter's dashboards filter on different columns, you can redefine the clustering keys without rewriting existing data. A partitioned table would need a full rewrite to change its partition column. Clustering also handles a case partitioning cannot: liquid clustering is the only way to data-skip on a struct field without first extracting it into a top-level column.

    When there are too many tables to tune by hand, let the platform pick the keys. In Databricks Runtime 15.4 LTS and above, CLUSTER BY AUTO on a Unity Catalog managed Delta table lets Databricks choose clustering keys to optimise query performance. This requires predictive optimization, which selects the keys and runs clustering asynchronously. Because predictive optimization bases these choices on how the data is actually used, keys can change as dashboards change. The table history records this as an AUTO_CLUSTERING_COLUMN_SELECTION operation.

    Checkpoint 3 of 8· Check yourself

    Your team is designing the layout for fact_events, a 30 TB table. Dashboards slice it by event_date and filter on customer_id, and next quarter's reports are expected to filter on different columns. Which layout fits these requirements?

    Checkpoint 4 of 8· Exam question

    A team is designing a fact_events table that will grow to several billion rows. Query patterns filter heavily on event_date and customer_id, but the exact date ranges and customer segments used in dashboards change frequently as new reports are built each month. The team wants a layout that avoids costly directory-listing overhead from thousands of narrow partitions while still letting the physical data layout adapt as query patterns shift. Which approach best meets these requirements?

    Checkpoint 5 of 8· Exam question

    A platform team manages hundreds of Unity Catalog managed Delta tables and does not have the capacity to manually choose and periodically revisit clustering keys as BI dashboards evolve. They want Databricks to observe query history and select clustering keys automatically, changing them only when the switch is expected to pay for itself in reduced maintenance cost. Which configuration satisfies this requirement?

    Sources2314

    3.Moving a partitioned table to clustering, on Delta and Iceberg

    A partitioned table that has outgrown its scheme can be converted in place. In Databricks Runtime 18.1 and above, ALTER TABLE ... REPLACE PARTITIONED BY WITH CLUSTER BY turns a partitioned Delta table into a liquid-clustered one without exporting and reloading the data, for both managed and external tables. A plain ALTER TABLE ... CLUSTER BY only works on a table that is not partitioned. A CTAS into a new table works too, but it rewrites everything and does not preserve all table metadata.

    The three forms of the conversion clause
    ClauseResulting clustering keys
    CLUSTER BY (cols)The listed columns. Keep them close to the old partition columns to avoid a large first recluster
    CLUSTER BY AUTOStarts from the current partition columns, then predictive optimization adapts them. Unity Catalog managed tables only
    CLUSTER BY (no options)The current partition columns

    No. The ALTER changes metadata, not data. The physical reorganisation happens when OPTIMIZE runs. If the new keys differ from the old partitions, the first OPTIMIZE is a large reclustering job, so schedule it accordingly. After conversion, DESCRIBE EXTENDED shows the new clustering columns, and DESCRIBE HISTORY shows the REORG and protocol-upgrade steps.

    Converting to different clustering columns, then applying themsql
    ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
    OPTIMIZE t1;

    Iceberg tables follow the same layout rules with a few differences in mechanics (Iceberg as a target format (managed Iceberg tables / UniForm) covers the format itself). For managed Iceberg tables, Unity Catalog supports only liquid clustering, and a PARTITION BY clause is read as clustering keys. Running the conversion command on these tables therefore raises an error, because there is nothing to convert. OPTIMIZE rewrites Iceberg files as it does Delta files, but Iceberg uses clustering and sorting strategies in place of ZORDER. Liquid clustering on Iceberg is in Public Preview from Databricks Runtime 16.4 LTS.

    Checkpoint 6 of 8· Fill the gap

    Table t1 is partitioned on (year, month, day) and is converted to cluster on different columns. Which command in the second line actually reorganises the existing files by the new keys?

    ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
     ?  t1;

    Checkpoint 7 of 8· Exam question

    An existing Delta table orders is partitioned by order_month and has accumulated hundreds of small partitions after a shift in order volume, degrading query performance. The team wants to move the table to liquid clustering on order_date and region without exporting and reloading the underlying data. Which statement should they run?

    Sources215

    4.Keeping file sizes balanced with compaction

    Even a good partition and clustering design degrades if the files are the wrong size. Streaming appends and small batches leave thousands of small files. Each one adds per-file overhead and its own statistics to check, which is why Databricks sizes files so that the number of files in a table doesn't grow too large. Files can also be too big. On very narrow tables, a single file can hold more rows than the Parquet format supports, and the write fails. maxRecordsPerFile is the remedy, but only when that error actually occurs.

    OPTIMIZE is the main tool for compaction. It rewrites data files into fewer, evenly sized ones using bin-packing, which balances files by bytes in storage rather than by row count. On a clustered table it also groups rows by the clustering keys. On a partitioned table it compacts within each partition, never across partitions. The operation is safe to run alongside other work. It changes no data, readers keep their snapshot, a second run on the same data does nothing, and streams that read from the table are unaffected. On a large table you can limit it to recent data with a predicate.

    Compacting only recent datasql
    OPTIMIZE table_name WHERE date >= '2022-11-18'

    Two write-time features reduce small files before OPTIMIZE ever runs, but neither replaces it. Optimized writes shuffle data before writing so each write produces fewer, larger files. This matters most on partitioned tables and adds some write latency. Auto compaction runs synchronously on the writing cluster after a successful write and combines small files that have not yet been compacted. It is a file-merging step and has nothing to do with clustering keys. Both are always on for MERGE, UPDATE and DELETE. Do not combine optimized writes with a manual repartition(n) or coalesce(n). For tables over 1 TB, run OPTIMIZE on a schedule as well. A sensible starting point is daily, at night, then adjust the frequency to balance cost against query speed.

    Autotuned target file size grows with table size
    Table sizeTarget file sizeApproximate files
    10 GB256 MB40
    1 TB256 MB4096
    5 TB512 MB17339
    10 TB1 GB24437
    100 TB1 GB114437

    Target size depends on table size, and autotuning sets it for you. A table under 2.56 TB targets 256 MB files. Between 2.56 TB and 10 TB the target grows linearly, and above 10 TB it is 1 GB. As a table grows, files written at the old, smaller target are not rewritten when the target rises. If those leftovers matter, set a fixed delta.targetFileSize (or iceberg.targetFileSize). A table you tune this way is no longer autotuned, and on managed tables only OPTIMIZE honours the setting. For Unity Catalog managed tables, the simplest path is predictive optimization. It runs OPTIMIZE, VACUUM and ANALYZE when they are cost-effective, on serverless compute, and records them in system.storage.predictive_optimization_operations_history. It does not run on external tables, and it never performs ZORDER.

    Checkpoint 8 of 8· Match them up

    A 3 TB external Delta table gets streaming appends. Pair each file-sizing feature with what it actually does for this table

    Tap a term, then the definition that fits it.

    Sources654

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “An ineffective partitioning strategy might negatively affect query performance and require a full rewrite of data to fix.”
      ↩︎ Start from the grain, the predicates and the size
      “Most tables on Databricks with less than 100 TB of data don't need partitioning.”
      ↩︎ Start from the grain, the predicates and the size
      “automatically clusters data in unpartitioned tables by ingestion time, so you get partitioning-like performance without manual tuning”
      ↩︎ Start from the grain, the predicates and the size
      “For partitions, verify that each partition contains at least 1 GB of data.”
      ↩︎ Start from the grain, the predicates and the size
      “Liquid clustering is the only way to data-skip on a struct field without first extracting it into a top-level column.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “For managed tables using Apache Iceberg, Unity Catalog supports only liquid clustering and interprets PARTITION BY columns as clustering keys.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “For partitions, verify that each partition contains at least 1 GB of data.”
      ↩︎ Key concept
      “Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations)”
      ↩︎ Exam trap 1
      “With less than 1 TB of data, don't partition.”
      ↩︎ Prediction
      “With less than 1 TB of data, don't partition. With more than 1 TB to 100 TB of data, use liquid clustering instead of partitioning.”
      ↩︎ Checkpoint
      “Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations), but not for fields with high cardinality”
      ↩︎ Checkpoint
    2. 2.
      “Unlike traditional partitioning, you can redefine clustering keys without rewriting existing data.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “Tables where a typical partition key might return results from too many or too few partitions.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “Clustering is not compatible with partitioning or ZORDER.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “In Databricks Runtime 15.4 LTS and above, you can enable automatic liquid clustering for Unity Catalog managed Delta Lake tables.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “Automatic liquid clustering requires predictive optimization for automatic key selection and clustering operations, and runs asynchronously.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “to convert an existing partitioned Delta Lake table to liquid clustering, use REPLACE PARTITIONED BY WITH CLUSTER BY in an ALTER TABLE statement.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “To benefit from altering clustering columns, you must run OPTIMIZE.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “Using very different columns triggers a large reclustering operation on the first OPTIMIZE run.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “For managed Iceberg tables, conversion is not necessary because these tables use partition definitions as liquid clustering keys.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “to convert an existing partitioned Delta Lake table to liquid clustering, use REPLACE PARTITIONED BY WITH CLUSTER BY in an ALTER TABLE statement.”
      ↩︎ Exam trap 2
    3. 3.
      “at query time to skip irrelevant files and speed up queries”
      ↩︎ Cluster on the columns that relate facts to dimensions
    4. 4.
      “If automatic liquid clustering is enabled, predictive optimization might select new clustering keys before clustering data.”
      ↩︎ Cluster on the columns that relate facts to dimensions
      “OPTIMIZE does not run ZORDER when executed by predictive optimization.”
      ↩︎ Keeping file sizes balanced with compaction
      “OPTIMIZE does not run ZORDER when executed by predictive optimization.”
      ↩︎ Exam trap 4
    5. 5.
      “Apache Iceberg tables use clustering and sorting strategies instead of ZORDER.”
      ↩︎ Moving a partitioned table to clustering, on Delta and Iceberg
      “Bin-packing aims to produce evenly-balanced data files with respect to their size in storage”
      ↩︎ Keeping file sizes balanced with compaction
      “For tables with partitions defined, file compaction and data layout are performed within partitions.”
      ↩︎ Keeping file sizes balanced with compaction
      “Because OPTIMIZE makes no data changes to the table, a read before and after an OPTIMIZE has the same results.”
      ↩︎ Keeping file sizes balanced with compaction
      “Databricks recommends that you start by running OPTIMIZE on a daily basis, preferably at night when spot prices are low”
      ↩︎ Keeping file sizes balanced with compaction
    6. 6.
      “so that the number of files in the table doesn't grow too large”
      ↩︎ Keeping file sizes balanced with compaction
      “the number of rows in a given data file exceeds the support limits of the Parquet format”
      ↩︎ Keeping file sizes balanced with compaction
      “For tables larger than 1 TB, Databricks recommends running OPTIMIZE on a schedule to further consolidate files.”
      ↩︎ Keeping file sizes balanced with compaction
      “Optimized writes are most effective for partitioned tables, as they reduce the number of small files written to each partition.”
      ↩︎ Keeping file sizes balanced with compaction
      “It runs synchronously on the cluster that performs the write, after the write succeeds”
      ↩︎ Keeping file sizes balanced with compaction
      “When the target file size for a table grows, existing files are not re-optimized into larger files by the OPTIMIZE command.”
      ↩︎ Keeping file sizes balanced with compaction
      “When using Unity Catalog managed tables and SQL warehouses or Databricks Runtime 11.3 LTS and above, only OPTIMIZE commands respect the targetFileSize setting.”
      ↩︎ Keeping file sizes balanced with compaction
      “Auto compaction and optimized writes each reduce small file problems, but are not a full replacement for OPTIMIZE.”
      ↩︎ Exam trap 3
      “Auto compaction and optimized writes each reduce small file problems, but are not a full replacement for OPTIMIZE.”
      ↩︎ Checkpoint

    Spotted a mistake, or was something unclear? Tell us.