Moving data from ADLS Gen1 to ADLS Gen2 using Azure Databricks
Mount your Azure Data Lake Storage Gen2 (ADLS Gen2) filesystem to DBFS and use a Talend Job to move your data from ADLS Gen1 to ADLS Gen2.
The tAzureFSConfiguration component enables you to easily and flexibly connect to ADLS Gen1 or ADLS Gen2 in Spark Jobs. However, as only one tAzureFSConfiguration is allowed per Job, you cannot connect to your ADLS Gen1 system and ADLS Gen2 system at the same time in a single Spark Job.
For this reason, when you need to use a Talend Job to move data between those two systems, mount either ADLS Gen1 or ADLS Gen2 to DBFS before designing your Job.
This article demonstrates how to mount ADLS Gen2 and then design a Job to accomplish this move. If you need details about how to mount ADLS Gen1, see Mounting ADLS Gen1 from the Azure databricks documentation.
Grant your application the access to your ADLS Gen2
Before you begin
An Azure subscription is required.
Create your Azure Data Lake Storage Gen2 account if you do not have it
- For more details, see Create an Azure Data Lake Storage Gen2 account from the Azure documentation.
- Create an Azure Active Directory application on your Azure portal. For more details about how to do this, see the "Create an Azure Active Directory application" section in Azure documentation: Use portal to create an Azure Active Directory application.
Obtain the application ID, object ID and the client secret of the application
to be used from the portal.
- On the list of the registered applications, click the application you created and registered in the previous step to display its information blade.
- Click Overview to open its blade, and from the top section of the blade, copy the Object ID and the application ID displayed as Application (client) ID. Keep them somewhere safe for later use.
- Click Certificates & secrets to open its blade and then create the authentication key (client secret) to be used on this blade in the Client secrets section.
- Back to the Overview blade of the application to be used, click Endpoints on the top of this blade, copy the value of OAuth 2.0 token endpoint (v1) from the endpoint list that appears and keep it somewhere safe for later use.
Set the read and write permissions to the ADLS Gen2 filesystem to be used for
the service principal of your application.
It is very likely that the administrator of your Azure system has included your account and your applications in the group that has access to a given ADLS Gen2 storage account and a given ADLS Gen2 filesystem. In this case, ask your administrator to ensure that you have the proper access and then ignore this step.
Start your Microsoft Azure Storage Explorer and find your ADLS Gen2
storage account on the Storage Accounts
If you have not installed Microsoft Azure Storage Explorer, you can download it from the Microsoft Azure official site.
Expand this account and the Blob Containers node
under it; then click the ADLS Gen2 hierarchical filesystem to be used
under this node.
The filesystem in this image is for demonstration purposes only. Create the filesystem to be used under the Blob Containers node in your Microsoft Azure Storage Explorer, if you do not have one yet.
- On the blade that is opened, click Manage Access to open its wizard.
- At the bottom of this wizard, add the object ID of your application to the Add user or group field and click Add.
- Select the object ID just added from the Users and groups list and select all the permission for Access and Default.
- Click Save to validate these changes and close this wizard.
- Start your Microsoft Azure Storage Explorer and find your ADLS Gen2 storage account on the Storage Accounts list.
Mount the Azure Data Lake Storage Gen2 filesystem to be used to DBFS
Before you begin
- Ensure that you have grant your application the read-and-write permissions to your ADLS Gen2 filesystem.
- Download the Databricks CLI and install it as described in this documentation: Databricks Command-Line Interface.
Use this Databricks CLI to create a Databricks-backed secret scope. For
example, name this scope to talendsadlsgen2. The command
to be used is:
databricks secrets create-scope --scope talendadlsgen2 --initial-manage-principal users
This command grant the access permissions to this secret scope to all users.
Add a secret to this scope using the following command:
databricks secrets put --scope talendadlsgen2 --key adlscredentials
In this command, talendadlsgen2 is the name of the secret scope created in the previous step; adlscredentials is the secret to be created.
Once the command in the previous step is run, an text editor displays
automatically. Paste the value of the adlscredentials
secret in this editor and save and exit the editor. In this step, this value is
the client secret of your ADLS Gen2 storage account.
# ---------------------------------------------------------------------- # Do not edit the above line. Everything below it will be ignored. # Please input your secret value above the line. Text will be stored in # UTF-8 (MB4) form and any trailing new line will be stripped. # Exit without saving will abort writing secret.
This value must be added above this line.
Repeat this process to add, to this
talendadlsgen2 secret scope, the following secrets, separately:
- adlsclientid: the value of this secret is the application ID of your ADLS Gen2 storage account.
- adlsendpoint: the value of this secret is the oauth 2.0 token endpoint of your ADLS Gen2 storage account.
- On your Azure Databricks portal, create a Databricks cluster from the Azure Databricks Workspace. The version of this cluster must be among those supported by Talend.
Once the cluster is created and running, switch back to the Azure Databricks Workspace and click Create a Blank Notebook.
Add the following Scala code to this Notebook and replace
mount-namewith their actual values:
val configs = Map( "fs.azure.account.auth.type" -> "OAuth", "fs.azure.account.oauth.provider.type" -> "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider", "fs.azure.account.oauth2.client.id" -> dbutils.secrets.get(scope = "talendadlsgen2", key = "adlsclientid"), "fs.azure.account.oauth2.client.secret" -> dbutils.secrets.get(scope = "talendadlsgen2", key = "adlscredentials"), "fs.azure.account.oauth2.client.endpoint" -> dbutils.secrets.get(scope = "talendadlsgen2", key = "adlsendpoint") ) // Optionally, you can add <directory-name> to the source URI of your mount point. dbutils.fs.mount( source = "abfss://<file-system-name>@<storage-account-name>.dfs.core.windows.net/", mountPoint = "/mnt/<mount-name>", extraConfigs = configs)
Optionally, append the following lines to the code added in the previous
val df = spark.read.text("/mnt/<mount-name>/<file-location>") df.show();
These lines allow you to access files in your ADLS Gen2 filesystem as if they were in DBFS.
If the ADLS Gen2 filesystem to be mounted contains some files, run this Notebook.
Then you should see the data stored in the file specified by
<file-location> in the lines appended in the last step.
Granting the application to be used the access to your ADLS Gen1 folder
- Create an Azure Active Directory application on your Azure portal to access your ADLS Gen1 folder. For more details about how to do this, see the "Create an Azure Active Directory application" section in Azure documentation: Use portal to create an Azure Active Directory application
Obtain the application ID and the client secret (authentication key) from the portal.
- On the list of the registered applications, click the application you created and registered in the previous step to display its information blade.
- In the Essentials area, copy its application ID.
- Click All settings to display the Settings blade and click Required permissions on that blade.
- On the Required permissions blade, click Windows Azure Active Directory to display the Enable Access blade.
- Select the permissions to be granted to your application and click Save to close the Enable Access blade. You may need the consent of the administrator of your Azure portal to eventually validate the grant.
- Still on the Required permissions blade of your application, click Add and on the Add API access blade, click Select an API.
- Click Azure Data Lake and then click Select to validate your selection and automatically open the Enable Access blade of this API.
- Select the permission to be granted and click Select to close the Enable Access blade.
- On the Add API access blade, click Done to return to the Setting blade of your application.
- Click Keys to open the Keys blade.
- In the Password area, enter the description of you key, define its duration of validity and then click Save to display the value of your key.
- Copy the key value and keep it somewhere you think safe because you are not able to retrieve the key anymore once you leave this blade.
- Back to the list of the Azure Data Lake Storage services, select the Data Lake Storage you created at the beginning of the procedure and then click Data Explorer.
- On the blade that is opened, click Access to open the Access blade.
- Click Add and on the Select User or Group blade, search for your application, select it and click the Select button to open the Select Permission blade.
Select the permission to be assigned to your application and click OK.
In this example, select all the permissions.
Obtain the Azure OAUTH 2.0 token endpoint by proceeding as follows:
- Click Azure Active Directory and on the blade that is displayed, click App registrations.
- On the App registrations blade, click Endpoints and on the Endpoints blade, copy the value of the OAUTH 2.0 TOKEN ENDPOINT field.
Creating a Job to move data from ADLS Gen1 to Gen2
Before you begin
- A Talend Studio with Big Data is started and the Integration perspective is active.
- You Databricks cluster is running.
- Right-click the Big Data Batch node under Job Designs and select Create Big Data Batch Job from the contextual menu.
- In the New Job wizard, give a name to the Job you are going to create and provide other useful information if needed.
Click Finish to create your Job.
An empty Job is opened in the Studio.
- In the workspace, enter the name of the component to be used and select this component from the list that appears. In this scenario, the components are tAzureFSConfiguration, tFileInputDelimited and tFileOutputDelimited.
Connect tFileInputDelimited to tFileOutputDelimited using the Row >
In this example, the data to be migrated is assumed to be delimited data. For this reason, the components specific to delimited data are used.
- Leave tAzureFSConfiguration alone without any connection.
Double-click tAzureFSConfiguration to open its
Spark uses this component to connect to your ADLS Gen1 storage account from which you migrate data to the mounted ADLS Gen2 filesystem.
- From the Azure FileSystem drop-down list, select Azure Datalake Storage.
- In the Datalake storage account field, enter the name of the Data Lake Storage account you need to access.
In the Client ID and the Client
key fields, enter, respectively, the authentication ID and the
authentication key generated upon the registration of the application used to
access ADLS Gen1.
Ensure that the application to be used has appropriate permissions to access Azure Data Lake. You can check this on the Required permissions view of this application on Azure. For further information, see Azure documentation Assign the Azure AD application to the Azure Data Lake Storage account file or folder.
- In the Token endpoint field, copy-paste the OAuth 2.0 token endpoint that you can obtain from the Endpoints list accessible on the App registrations page on your Azure portal.
Double-click tFileInputDelimited to open its
- Select the Define a storage configuration component check box to use the ADLS Gen1 connection configuration from tAzureFSConfiguration.
- In the Folder/File field, enter the directory in which the data to be migrated is stored in your ADLS Gen1 folder.
Click the [...] button next to Edit
schema to define the schema of the data to be migrated and
accept the propagation of the schema to the component that follows, that is to
This image is for demonstration purposes only. In this example schema, the data has only two columns: FirstName and LastName.
- In Row separator and Field separator, enter the separators used in your data, respectively.
Double-click tFileOutputDelimited to open its
- Clear the Define a storage configuration component check box to use the DBFS system of your Databricks cluster.
- In the Folder field, enter the directory to be used to store the migrated data in the mounted ADLS Gen2 filesystem. For example, in this /mnt/adlsgen2/fromgen1 directory, adlsgen2 is the mount name specified when the filesystem was mounted and fromgen1 is the folder to be used to store the migrated data.
- From the Action drop-down list, select Create if the folder to be used does not exist yet on Azure Data Lake Storage; if this folder already exists, select Overwrite.
Configuring the Spark cluster on Azure Databricks
- On the Configuration tab of your Databricks cluster page, scroll down to the Spark tab at the bottom of the page.
- Click Edit to make the fields on this page editable.
As your Spark cluster uses tAzureFSConfiguration to connect
your ADLS Gen1 folder from which you move data to Gen2, in this
Spark tab, enter the Spark properties regarding the
credentials to be used to access that ADLS Gen1 folder.
spark.hadoop.dfs.adls.oauth2.access.token.provider.type ClientCredential spark.hadoop.dfs.adls.oauth2.client.id <your_app_id> spark.hadoop.dfs.adls.oauth2.credential <your_client_secret> spark.hadoop.dfs.adls.oauth2.refresh.url https://login.microsoftonline.com/<your_app_TENANT-ID>/oauth2/token
Add these ADLS Gen1 related properties each per line.
- Restart your Spark cluster.
- In the Spark UI tab of your Databricks cluster page, click Environment to display the list of properties and verify that each of the properties you added in the previous steps is present on that list.
In the Spark
Configuration tab of the Run view of your Job, enter the basic connection information to
Use pool: you can select this check box to leverage a Databricks pool. If you do, you must indicate the pool ID instead of the cluster ID in the Spark Configuration. You must also select the Use transient cluster check box.
In the Endpoint field, enter the URL address of your Azure Databricks workspace. This URL can be found in the Overview blade of your Databricks workspace page on your Azure portal. For example, this URL could look like https://adb-$workspaceId.$random.azuredatabricks.net.
In the Cluster ID field, enter the ID of the Databricks cluster to be used. This ID is the value of the spark.databricks.clusterUsageTags.clusterId property of your Spark cluster. You can find this property on the properties list in the Environment tab in the Spark UI view of your cluster.
You can also easily find this ID from the URL of your Databricks cluster. It is present immediately after cluster/ in this URL.
If you selected the Use pool option, in the Pool ID field, enter the ID of the Databricks pool to be used. This ID is the value of the DatabricksInstancePoolId key of your pool. You can find this key under Tags in the Configuration tab of your pool. It is also available in the tags of the clusters that are using the pool.
You can also easily find this ID from the URL of your Databricks pool. It is present immediately after cluster/instance-pools/view/ in this URL.
Click the [...] button next to the Token field to enter the authentication token generated for your Databricks user account. You can generate or find this token on the User settings page of your Databricks workspace. For further information, see Token management from the Azure documentation.
In the DBFS dependencies folder field, enter the directory that is used to store your Job related dependencies on Databricks Filesystem at runtime, putting a slash (/) at the end of this directory. For example, enter /jars/ to store the dependencies in a folder named jars. This folder is created on the fly if it does not exist then.
Poll interval when retrieving Job status (in ms): enter, without the quotation marks, the time interval (in milliseconds) at the end of which you want the Studio to ask Spark for the status of your Job. For example, this status could be Pending or Running.
The default value is 300000, meaning 30 seconds. This interval is recommended by Databricks to correctly retrieve the Job status.
Use transient cluster: you can select this check box to leverage the transient Databricks clusters.
The custom properties you defined in the Advanced properties table are automatically taken into account by the transient clusters at runtime.
- Autoscale: select or clear this check box to define
the number of workers to be used by your transient cluster.
- If you select this check box,
autoscaling is enabled. Then define the minimum number
of workers in Min
workers and the maximum number of
worders in Max
workers. Your transient cluster is
scaled up and down within this scope based on its
According to the Databricks documentation, autoscaling works best with Databricks runtime versions 3.0 or onwards.
- If you clear this check box, autoscaling is deactivated. Then define the number of workers a transient cluster is expected to have. This number does not include the Spark driver node.
- If you select this check box, autoscaling is enabled. Then define the minimum number of workers in Min workers and the maximum number of worders in Max workers. Your transient cluster is scaled up and down within this scope based on its workload.
- Node type
and Driver node type:
select the node types for the workers and the Spark driver node.
These types determine the capacity of your nodes and their
pricing by Databricks.
For details about these node types and the Databricks Units they use, see Supported Instance Types from the Databricks documentation.
disk: select this check box to enable your
transient cluster to automatically scale up its disk space when
its Spark workers are running low on disk space.
For more details about this elastic disk feature, search for the section about autoscaling local storage from your Databricks documentation.
- SSH public
key: if an SSH access has been set up for your
cluster, enter the public key of the generated SSH key pair.
This public key is automatically added to each node of your
transient cluster. If no SSH access has been set up, ignore this
For further information about SSH access to your cluster, see SSH access to clusters from the Databricks documentation.
- Configure cluster log: select this check box to define where to store your Spark logs for a long term. This storage system could be S3 or DBFS.
- Autoscale: select or clear this check box to define the number of workers to be used by your transient cluster.
- Do not restart the cluster when submitting: select this check box to prevent the Studio restarting the cluster when the Studio is submitting your Jobs. However, if you make changes in your Jobs, clear this check box so that the Studio resarts your cluster to take these changes into account.
- Press F6 to run this Job to start the migration.