<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Renaming a folder in adls is taking a lot of time in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157928#M54635</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/232191"&gt;@Nkrom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a very common issue! You are running into this because of how dbutils.fs.mv interacts with object storage. When you use it on a massive folder, it executes sequentially (one file at a time).&lt;/P&gt;&lt;P&gt;Even worse, &lt;STRONG&gt;dbutils commands execute entirely on the Driver Node&lt;/STRONG&gt;. Your worker nodes do absolutely nothing during this process. If your cluster has a small driver node, it will severely bottleneck the operation, hence the 7-hour wait!&lt;/P&gt;&lt;P&gt;If you don't have access to the raw Azure Storage Keys to use the Azure REST API directly, the best workaround is to use Python's ThreadPoolExecutor to run dbutils.fs.mv in parallel across multiple threads.&lt;/P&gt;&lt;P&gt;Here is a script you can use in your workflow to swap the folders much faster:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;from concurrent.futures import ThreadPoolExecutor

def fast_move_contents(source_dir, target_dir, workers=16):
    # Ensure target directory exists
    dbutils.fs.mkdirs(target_dir)
    
    # List all items (files/folders) in the top level of the source
    items = dbutils.fs.ls(source_dir)
    
    def move_item(item):
        dbutils.fs.mv(item.path, f"{target_dir}/{item.name}", recurse=True)
        
    # Process the moves in parallel using threads
    with ThreadPoolExecutor(max_workers=workers) as executor:
        executor.map(move_item, items)

# 1. Move 'customer' to a temp folder
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer", "abfss://container@storage.dfs.core.windows.net/customer_temp")

# 2. Move 'customer_01' to 'customer'
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer_01", "abfss://container@storage.dfs.core.windows.net/customer")

# 3. Move temp to 'customer_01'
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer_temp", "abfss://container@storage.dfs.core.windows.net/customer_01")

print("Parallel swap completed!")&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;Two Pro-Tips for your Workflow:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Cluster Sizing:&lt;/STRONG&gt; Since this runs on the driver, make sure the cluster attached to your workflow has a memory-optimized or compute-optimized &lt;STRONG&gt;Driver Node&lt;/STRONG&gt;. You can keep the worker nodes at zero (Single Node cluster) just for this specific task to save money!&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Max Workers:&lt;/STRONG&gt; You can safely increase workers=16 to 32 or 64 depending on how many cores your driver node has.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Hope this helps speed up your pipeline!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2026 16:24:28 GMT</pubDate>
    <dc:creator>ShamenParis</dc:creator>
    <dc:date>2026-05-29T16:24:28Z</dc:date>
    <item>
      <title>Renaming a folder in adls is taking a lot of time</title>
      <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157917#M54633</link>
      <description>&lt;P&gt;Hi i have a folder customer and customer_01 in adls location , now i need to rename customer_01 to customer and customer to customer_01 both if these folder have lots of files . If i use dbutls.fs.mv its taking a lot of time like 7 hours something is there any way to do via notebook so that we can attach it in workflow and doesnt need to go to adls location and rename in from there&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 16:02:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157917#M54633</guid>
      <dc:creator>Nkrom</dc:creator>
      <dc:date>2026-05-29T16:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a folder in adls is taking a lot of time</title>
      <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157928#M54635</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/232191"&gt;@Nkrom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a very common issue! You are running into this because of how dbutils.fs.mv interacts with object storage. When you use it on a massive folder, it executes sequentially (one file at a time).&lt;/P&gt;&lt;P&gt;Even worse, &lt;STRONG&gt;dbutils commands execute entirely on the Driver Node&lt;/STRONG&gt;. Your worker nodes do absolutely nothing during this process. If your cluster has a small driver node, it will severely bottleneck the operation, hence the 7-hour wait!&lt;/P&gt;&lt;P&gt;If you don't have access to the raw Azure Storage Keys to use the Azure REST API directly, the best workaround is to use Python's ThreadPoolExecutor to run dbutils.fs.mv in parallel across multiple threads.&lt;/P&gt;&lt;P&gt;Here is a script you can use in your workflow to swap the folders much faster:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;from concurrent.futures import ThreadPoolExecutor

def fast_move_contents(source_dir, target_dir, workers=16):
    # Ensure target directory exists
    dbutils.fs.mkdirs(target_dir)
    
    # List all items (files/folders) in the top level of the source
    items = dbutils.fs.ls(source_dir)
    
    def move_item(item):
        dbutils.fs.mv(item.path, f"{target_dir}/{item.name}", recurse=True)
        
    # Process the moves in parallel using threads
    with ThreadPoolExecutor(max_workers=workers) as executor:
        executor.map(move_item, items)

# 1. Move 'customer' to a temp folder
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer", "abfss://container@storage.dfs.core.windows.net/customer_temp")

# 2. Move 'customer_01' to 'customer'
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer_01", "abfss://container@storage.dfs.core.windows.net/customer")

# 3. Move temp to 'customer_01'
fast_move_contents("abfss://container@storage.dfs.core.windows.net/customer_temp", "abfss://container@storage.dfs.core.windows.net/customer_01")

print("Parallel swap completed!")&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;Two Pro-Tips for your Workflow:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Cluster Sizing:&lt;/STRONG&gt; Since this runs on the driver, make sure the cluster attached to your workflow has a memory-optimized or compute-optimized &lt;STRONG&gt;Driver Node&lt;/STRONG&gt;. You can keep the worker nodes at zero (Single Node cluster) just for this specific task to save money!&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Max Workers:&lt;/STRONG&gt; You can safely increase workers=16 to 32 or 64 depending on how many cores your driver node has.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Hope this helps speed up your pipeline!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 16:24:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157928#M54635</guid>
      <dc:creator>ShamenParis</dc:creator>
      <dc:date>2026-05-29T16:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a folder in adls is taking a lot of time</title>
      <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157929#M54636</link>
      <description>&lt;P&gt;Thanks for this how is that can azure rest api can you please mention that too&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 16:39:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157929#M54636</guid>
      <dc:creator>Nkrom</dc:creator>
      <dc:date>2026-05-29T16:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a folder in adls is taking a lot of time</title>
      <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157931#M54638</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/232191"&gt;@Nkrom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I am happy to share the Azure REST API method! Using the Azure Python SDK is the absolute fastest way to do this but you can choose any other programming language.&lt;BR /&gt;ADLS Gen2 uses a "Hierarchical Namespace" (HNS). When you use the Azure SDK to rename a folder, it doesn't touch the files inside. It literally just updates the folder name in the metadata layer. What takes dbutils 7 hours will take this API about 2 seconds.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Here is how you do it in a Databricks Notebook:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;First, you need to install the Azure Data Lake library. You can run this in the first cell of your notebook:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;%pip install azure-storage-file-datalake​&lt;/LI-CODE&gt;&lt;P&gt;Next, use this script. &lt;STRONG&gt;Important:&lt;/STRONG&gt; Never hardcode your storage key in the notebook. Always use dbutils.secrets.get() to pull it securely from your Databricks Key Vault! If not you can directly use the key.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from azure.storage.filedatalake import DataLakeServiceClient

# 1. Setup your credentials securely
storage_account = "&amp;lt;your_storage_account_name&amp;gt;"
container = "&amp;lt;your_container_name&amp;gt;"

# Pull the storage key from Databricks Secrets
storage_key = dbutils.secrets.get(scope="your_scope_name", key="your_secret_name")

# Create the client connection
service_client = DataLakeServiceClient(
    account_url=f"https://{storage_account}.dfs.core.windows.net", 
    credential=storage_key
)
file_system_client = service_client.get_file_system_client(file_system=container)

# 2. Get clients for your current directories
dir_customer = file_system_client.get_directory_client("customer")
dir_customer_01 = file_system_client.get_directory_client("customer_01")

# 3. Perform the atomic swap (This happens instantly!)
# Note: The new_name parameter requires the container name in the path
dir_customer.rename_directory(new_name=f"{container}/customer_temp")
dir_customer_01.rename_directory(new_name=f"{container}/customer")

# Get the temp folder and rename it to customer_01
dir_temp = file_system_client.get_directory_client("customer_temp")
dir_temp.rename_directory(new_name=f"{container}/customer_01")

print("Folders swapped instantly via Azure API!")&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;Quick note&lt;/STRONG&gt;: If your company uses Service Principals (Managed Identities / Entra ID) instead of Storage Account Keys, you can just install the azure-identity library and swap the credential=storage_key out for credential=DefaultAzureCredential().&lt;/P&gt;&lt;P&gt;Give this a try in your workflow, it will save you a massive amount of cluster compute time! Let us know how it goes&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 16:52:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157931#M54638</guid>
      <dc:creator>ShamenParis</dc:creator>
      <dc:date>2026-05-29T16:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a folder in adls is taking a lot of time</title>
      <link>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157932#M54639</link>
      <description>&lt;P&gt;Thanks in ton. I will take a look and get back&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2026 16:59:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/renaming-a-folder-in-adls-is-taking-a-lot-of-time/m-p/157932#M54639</guid>
      <dc:creator>Nkrom</dc:creator>
      <dc:date>2026-05-29T16:59:55Z</dc:date>
    </item>
  </channel>
</rss>

