Clone (Delta Lake on Databricks)

Preview

This feature is in Public Preview.

Note

Available in Databricks Runtime 7.2 and above.

Clone a source Delta table to a target destination at a specific version. A clone can be either deep or shallow referring to whether it copies over the data from the source or not.

Important

There are important differences between shallow and deep clones with respect to dependencies between a clone and the source and other differences. See Clone a Delta table.

CREATE TABLE [IF NOT EXISTS] [db_name.]target_table
[SHALLOW | DEEP] CLONE [db_name.]source_table [<time_travel_version>]
[LOCATION 'path']
[CREATE OR] REPLACE TABLE [db_name.]target_table
[SHALLOW|DEEP] CLONE [db_name.]source_table [<time_travel_version>]
[LOCATION 'path']

where

<time_travel_version>  =
  TIMESTAMP AS OF timestamp_expression |
  VERSION AS OF version
  • Specify CREATE IF NOT EXISTS to avoid creating a table target_table if a table already exists. If a table already exists at the target, the clone operation is a no-op.
  • Specify CREATE OR REPLACE to replace the target of a clone operation if there is an existing table target_table. This updates the metastore with the new table if table name is used.
  • Specifying SHALLOW or DEEP creates a shallow or deep clone at the target. If neither SHALLOW nor DEEP is specified then a deep clone is created by default.
  • Specifying LOCATION creates an external table at the target with the provided location as the path where the data will be stored. If the target provided is a path instead of a table name, the operation will fail.

Examples

You can use CLONE for complex operations like data migration, data archiving, machine learning flow reproduction, short-term experiments, data sharing etc. See Clone use cases for a few examples.