<?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 Accessing ADLS Gen2 related Hadoop configuration in notebook in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71366#M7390</link>
    <description>&lt;P&gt;I have a cluster in which I have the required configuration to access an ADLS Gen2, and it works without any problems.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ender_1-1717335940727.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8005i133E550A8847D010/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Ender_1-1717335940727.png" alt="Ender_1-1717335940727.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to access this storage using the Hadoop filesystem APIs. To achieve this, I am trying to get the Hadoop configuration from the active Spark session in a notebook. Please see the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql import SparkSession
from py4j.java_gateway import java_import

java_import(spark._jvm, 'org.apache.hadoop.fs.Path')
java_import(spark._jvm, 'org.apache.hadoop.fs.FileSystem')

hadoop_conf = spark._jsc.hadoopConfiguration()
adl_uri = "abfss://adl_container@adl_storage_account.dfs.core.windows.net/"
dir_path = spark._jvm.Path(adl_uri)
fs = dir_path.getFileSystem(hadoop_conf)
files = fs.listStatus(dir_path)
print(f"Paths in directory {adl_uri}:")
for file in files:
    print(file.getPath())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this code, I get the error below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o1131.getFileSystem. : Failure to initialize configuration for storage account adl_storage_account.dfs.core.windows.net: Invalid configuration value detected for fs.azure.account.key&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I checked the related configuration value, and it seems its value is None.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ender_3-1717336689720.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8007iAC6180B261826FDB/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Ender_3-1717336689720.png" alt="Ender_3-1717336689720.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Given that the Hadoop configuration works as expected when Spark tries to access the storage, it is certain that the configuration is set properly in the cluster configuration. But why can't I access this configuration through "spark._jsc.hadoopConfiguration()"? Is there another way to access the hadoop configuration including the ADLS Gen2 connector configuration?&lt;/P&gt;&lt;P&gt;PS: I know I can use dbutils.fs library to interact with the storage. I have my reasons for not using it.&lt;/P&gt;&lt;P&gt;PS2: If I create a new Hadoop configuration instance and set the required configuration for it, the above code works as expected. But I do not want to create a new Hadoop configuration instance when I have already one with the required authentication info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;java_import(spark._jvm, 'org.apache.hadoop.conf.Configuration')

hadoop_conf = spark._jvm.Configuration()
storage_account_name = "adl_storage_account"
hadoop_conf.set(
    "fs.azure.account.auth.type.{0}.dfs.core.windows.net".format(storage_account_name),
    "OAuth"
)
hadoop_conf.set(
    "fs.azure.account.oauth.provider.type.{0}.dfs.core.windows.net".format(storage_account_name),
    "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider"
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.id.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_id")
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.secret.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_secret")
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.endpoint.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_endpoint")
)
hadoop_conf.set(
    "fs.azure.account.key.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "key")
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 02 Jun 2024 14:16:08 GMT</pubDate>
    <dc:creator>Ender</dc:creator>
    <dc:date>2024-06-02T14:16:08Z</dc:date>
    <item>
      <title>Accessing ADLS Gen2 related Hadoop configuration in notebook</title>
      <link>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71366#M7390</link>
      <description>&lt;P&gt;I have a cluster in which I have the required configuration to access an ADLS Gen2, and it works without any problems.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ender_1-1717335940727.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8005i133E550A8847D010/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Ender_1-1717335940727.png" alt="Ender_1-1717335940727.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to access this storage using the Hadoop filesystem APIs. To achieve this, I am trying to get the Hadoop configuration from the active Spark session in a notebook. Please see the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql import SparkSession
from py4j.java_gateway import java_import

java_import(spark._jvm, 'org.apache.hadoop.fs.Path')
java_import(spark._jvm, 'org.apache.hadoop.fs.FileSystem')

hadoop_conf = spark._jsc.hadoopConfiguration()
adl_uri = "abfss://adl_container@adl_storage_account.dfs.core.windows.net/"
dir_path = spark._jvm.Path(adl_uri)
fs = dir_path.getFileSystem(hadoop_conf)
files = fs.listStatus(dir_path)
print(f"Paths in directory {adl_uri}:")
for file in files:
    print(file.getPath())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this code, I get the error below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o1131.getFileSystem. : Failure to initialize configuration for storage account adl_storage_account.dfs.core.windows.net: Invalid configuration value detected for fs.azure.account.key&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I checked the related configuration value, and it seems its value is None.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ender_3-1717336689720.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8007iAC6180B261826FDB/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Ender_3-1717336689720.png" alt="Ender_3-1717336689720.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Given that the Hadoop configuration works as expected when Spark tries to access the storage, it is certain that the configuration is set properly in the cluster configuration. But why can't I access this configuration through "spark._jsc.hadoopConfiguration()"? Is there another way to access the hadoop configuration including the ADLS Gen2 connector configuration?&lt;/P&gt;&lt;P&gt;PS: I know I can use dbutils.fs library to interact with the storage. I have my reasons for not using it.&lt;/P&gt;&lt;P&gt;PS2: If I create a new Hadoop configuration instance and set the required configuration for it, the above code works as expected. But I do not want to create a new Hadoop configuration instance when I have already one with the required authentication info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;java_import(spark._jvm, 'org.apache.hadoop.conf.Configuration')

hadoop_conf = spark._jvm.Configuration()
storage_account_name = "adl_storage_account"
hadoop_conf.set(
    "fs.azure.account.auth.type.{0}.dfs.core.windows.net".format(storage_account_name),
    "OAuth"
)
hadoop_conf.set(
    "fs.azure.account.oauth.provider.type.{0}.dfs.core.windows.net".format(storage_account_name),
    "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider"
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.id.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_id")
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.secret.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_secret")
)
hadoop_conf.set(
    "fs.azure.account.oauth2.client.endpoint.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "client_endpoint")
)
hadoop_conf.set(
    "fs.azure.account.key.{0}.dfs.core.windows.net".format(storage_account_name),
    dbutils.secrets.get("my_secret_scope", "key")
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jun 2024 14:16:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71366#M7390</guid>
      <dc:creator>Ender</dc:creator>
      <dc:date>2024-06-02T14:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing ADLS Gen2 related Hadoop configuration in notebook</title>
      <link>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71933#M7392</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you, `spark.sparkContext.getConf().getAll()` gets the configuration that I need. But it also includes configuration which are not related with Hadoop. In that case, I assume there is no better way to get the complete Hadoop configuration.&lt;/P&gt;&lt;P&gt;The&amp;nbsp;`Path.getFileSystem(hadoop_conf)` method requires a `spark._jvm.Configuration` instance, so in that case I will have to create a new instance of&amp;nbsp;`spark._jvm.Configuration()`, filter the desired configuration manually from entire Spark configuration dictionary, fill the `Configuration` instance with the filtered configuration and provide the method with it. But at least I have a working method now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 17:27:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71933#M7392</guid>
      <dc:creator>Ender</dc:creator>
      <dc:date>2024-06-06T17:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing ADLS Gen2 related Hadoop configuration in notebook</title>
      <link>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71935#M7393</link>
      <description>&lt;P&gt;By the way how do you achieve inline code highlighting in the editor &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I tried `` but it didn't work.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 17:28:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/accessing-adls-gen2-related-hadoop-configuration-in-notebook/m-p/71935#M7393</guid>
      <dc:creator>Ender</dc:creator>
      <dc:date>2024-06-06T17:28:45Z</dc:date>
    </item>
  </channel>
</rss>

