Table Clone In Databricks

Using the clone command, we can create a copy of an existing Delta Lake table on Databricks at a specific version. Clones can be either deep or shallow.

Table Clone in Databricks

Clone is a Databricks-exclusive feature enabled in the Databricks Runtime by default.

Clone Types

A deep clone is a clone that copies the source table data to the clone target in addition to the metadata of the existing table. Stream metadata is also cloned such that a stream that writes to the Delta table can be stopped on a source table and continued on the target of a clone from where it left off.

A shallow clone is a clone that does not copy the data files to the clone target. These clones are cheaper to create. The table metadata is equivalent to the source.

Any changes made to either deep or shallow clones affect only the clones themselves and not the source table.

The syntax for Cloning Table,

Create a deep clone of ‘/data/source’ at ‘/data/target’

CREATE TABLE delta.`/data/target/` CLONE delta.`/data/source/`

Create a deep clone by Replacing the target table

CREATE OR REPLACE TABLE db.target_table CLONE db.source_table

Create a Shallow clone of ‘/data/source’ at ‘/data/target’

CREATE TABLE db.target_table SHALLOW CLONE delta.`/data/source`

Create a Shallow clone by utilizing the Table versioning

CREATE TABLE db.target_table SHALLOW CLONE delta.`/data/source` VERSION AS OF version


Similar Articles