Table Clone in Databricks
We can create a copy of an existing Delta Lake table on Databricks at a specific version using the clone command. Clones can be either deep or shallow.
Clone is an 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. Additionally, 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. The table metadata is equivalent to the source. These clones are cheaper to create.
Any changes made to either deep or shallow clones affect only the clones themselves and not the source table.
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