Reputation: 141
I want to know how can we change location of existing (Managed/External) Tables in Unity Catalog from Storage Account/Blob to Another. We want to have a functionality to make it flexible to store data either at root storage/external location/change in between
Upvotes: 3
Views: 1713
Reputation: 2943
You can directly edit the storage location in Databricks SQL:
ALTER TABLE catalog_name.schema_name.table_name
SET LOCATION 'new_storage_location';
-- Example:
-- SET LOCATION 's3://new-bucket/path/to/data_dir'; (or similar ADLS URI)
or you can use the databricks-sql-connector
package to run the same query from a Python script.
Upvotes: 0
Reputation: 3250
The below steps will help you move your metastore to a different Storage Account within Unity Catalog.
Step 1 : Create a new storage account for yourUnity Catalog. The Stoarge Account must be ADLS Gen2 account in the same region as your Databricks workspaces.
Step 2 : Create a container in the newly created storage account and note the ADLSv2 URI.
Step 3 : Create a service principal(SPN) and generate a client secret for the service principal.
Step 4 : The new service principal needs the Storage blob data contributor role in the storage account. Grant the Storage blob data contributor.
Step 5 : Log in to the Azure databricks account console and click on Data.
Step 6 : Click metastore name and then click Edit.
Step 7 : Now Update the ADLS Gen 2 path with the new storage container URI.
Step 8 : Click Save to update the metastore with the new storage account.
Reference:
The below are the Upgrade steps
Create a Catalog and Database for the target table.
%sql
CREATE CATALOG uc_batch
CREATE SCHEMA uc_batch.upgraded _sqldf
Grant access to the user performing the upgrade as well as to the user/principal running the streaming job.
%sql
CREATE CATALOG uc_batch
CREATE SCHEMA uc_batch.upgraded _sqldf
%sql
GRANT USAGE ON CATALOG uc_batch; TO 'data_eng'
Grant USAGE.CREATE ON SCHEMA uc_batch.upgraded TO 'data_eng'
The following steps can be performed by a developer. The developer has to be granted CREATE TABLES, READ FILES, and WRITE FILES rights on the external location. The users must be given access to a UC schema or permission to create one.
To move the existing managed table to the external table, perform the following steps:
To move the existing managed table to the Unity Catalog managed table, perform the following steps:
Deep clone the old target table to a newly created table in the Unity Catalog.
%sql
CREATE TABLE IF NOT EXISTS uc_batch.upgraded.salary_adjusted DEEP CLONE hive_metastore.default.salary_adjusted_sqldf
• Docs: uc-metastore-admin-quickstart • Docs: hive-metastore • Docs: index
Upvotes: 1