<?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: Issue while trying to read a text file in databricks using Local File API's instead of Spark API. in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34485#M25227</link>
    <description>&lt;P&gt;hey @Werner Stinckens​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;My apologies! Forgot to mention that I'm using the Databricks community edition. Thanks for the references, much appreciated!!&lt;/P&gt;</description>
    <pubDate>Wed, 24 Nov 2021 10:22:55 GMT</pubDate>
    <dc:creator>RiyazAliM</dc:creator>
    <dc:date>2021-11-24T10:22:55Z</dc:date>
    <item>
      <title>Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34479#M25221</link>
      <description>&lt;P&gt;I'm trying to read a small txt file which is added as a table to the default db on Databricks. While trying to read the file via Local File API, I get a `FileNotFoundError`, but I'm able to read the same file as&amp;nbsp;&lt;I&gt;Spark RDD&lt;/I&gt;&amp;nbsp;using&amp;nbsp;&lt;B&gt;SparkContext&lt;/B&gt;.&lt;/P&gt;&lt;P&gt;Please find the code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;with open("/FileStore/tables/boringwords.txt", "r") as f_read:
  for line in f_read:
    print(line)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error I get is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FileNotFoundError                         Traceback (most recent call last)
&amp;lt;command-2618449717515592&amp;gt; in &amp;lt;module&amp;gt;
----&amp;gt; 1 with open("dbfs:/FileStore/tables/boringwords.txt", "r") as f_read:
      2   for line in f_read:
      3     print(line)
&amp;nbsp;
FileNotFoundError: [Errno 2] No such file or directory: 'dbfs:/FileStore/tables/boringwords.txt'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where as, I have no problem reading the file using&amp;nbsp;&lt;B&gt;SparkContext&lt;/B&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;boring_words = sc.textFile("/FileStore/tables/boringwords.txt")
set(i.strip() for i in boring_words.collect())&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And as expected, I get the result for the above block of code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Out[4]: {'mad',
 'mobile',
 'filename',
 'circle',
 'cookies',
 'immigration',
 'anticipated',
 'editorials',
 'review'}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was also referring to the&amp;nbsp;&lt;A href="https://docs.databricks.com/data/databricks-file-system.html#fuse&amp;amp;language-python" alt="https://docs.databricks.com/data/databricks-file-system.html#fuse&amp;amp;language-python" target="_blank"&gt;&lt;B&gt;DBFS documentation&lt;/B&gt;&lt;/A&gt; to understand the Local File API's limitations but of no lead on the issue. Any help would be greatly appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 06:31:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34479#M25221</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2021-11-24T06:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34480#M25222</link>
      <description>&lt;P&gt;can you try with &lt;B&gt;/dbfs/Filestore/tables/boringwords.txt&lt;/B&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 07:49:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34480#M25222</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-24T07:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34481#M25223</link>
      <description>&lt;P&gt;Hey there @Werner Stinckens​&amp;nbsp;! Thanks for your response!&lt;/P&gt;&lt;P&gt;I've tried your suggestion and I still get the same error! &lt;/P&gt;&lt;P&gt;PFA the snip below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="error_snip"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2269iAE42843065C86184/image-size/large?v=v2&amp;amp;px=999" role="button" title="error_snip" alt="error_snip" /&gt;&lt;/span&gt;Moreover, I've realized that adding ```/dbfs``` to the path is optional, as I've stored the data in the default database. Refer to the OP that I'm creating a RDD by passing the path ```"/FileStore/Tables/filename.txt"``` in `sc.textFile`.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 08:58:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34481#M25223</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2021-11-24T08:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34482#M25224</link>
      <description>&lt;P&gt;you forgot a "/" as the first character in your file path.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 09:11:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34482#M25224</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-24T09:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34483#M25225</link>
      <description>&lt;P&gt;Hello @Werner Stinckens​&amp;nbsp;! &lt;/P&gt;&lt;P&gt;You're right! I missed the '/' earlier.&lt;/P&gt;&lt;P&gt;But, nothing changed after adding the '/' before dbfs. Below is the snip:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2279i5AB18CBC27DA0782/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;Moreover, when I tried the same path notation with SparkContext - It threw me an error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2274i9E4F6A64509C9C3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;I'm starting to wonder if this is the right way to provide the absolute path.&lt;/P&gt;&lt;P&gt;On the contrary, I've gave the path as "dbfs:/FileStore/tables/boringwords.txt" and it worked.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2277i34B4783ED5955079/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;But again this doesn't work for reading the file from Local API.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 09:52:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34483#M25225</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2021-11-24T09:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34484#M25226</link>
      <description>&lt;P&gt;No that should work.&lt;/P&gt;&lt;P&gt;I just tested it on my environment.&lt;/P&gt;&lt;P&gt;Also:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/azure/databricks/data/databricks-file-system#python" alt="https://docs.microsoft.com/en-us/azure/databricks/data/databricks-file-system#python" target="_blank"&gt;https://docs.microsoft.com/en-us/azure/databricks/data/databricks-file-system#python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/s/question/0D53f00001HKHS7CAP/python-open-function-is-unable-to-detect-the-file-in-dbfs" alt="https://community.databricks.com/s/question/0D53f00001HKHS7CAP/python-open-function-is-unable-to-detect-the-file-in-dbfs" target="_blank"&gt;https://community.databricks.com/s/question/0D53f00001HKHS7CAP/python-open-function-is-unable-to-detect-the-file-in-dbfs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But maybe you use the community edition of Databricks?  If I recall correctly, the dbfs mounting is limited.  So the local file interface might not work.&lt;/P&gt;&lt;P&gt;(See &lt;A href="https://community.databricks.com/s/question/0D53f00001HKIFjCAP/where-is-dbfs-mounted-with-community-edition" alt="https://community.databricks.com/s/question/0D53f00001HKIFjCAP/where-is-dbfs-mounted-with-community-edition" target="_blank"&gt;https://community.databricks.com/s/question/0D53f00001HKIFjCAP/where-is-dbfs-mounted-with-community-edition&lt;/A&gt;), not sure though.&lt;/P&gt;&lt;P&gt;If not: all I could think of is that the file is not there (so incorrect path), but SC can find it so that won't be it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proof it works:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2285i21FD1BDF008CEAA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 10:08:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34484#M25226</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-24T10:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34485#M25227</link>
      <description>&lt;P&gt;hey @Werner Stinckens​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;My apologies! Forgot to mention that I'm using the Databricks community edition. Thanks for the references, much appreciated!!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 10:22:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34485#M25227</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2021-11-24T10:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue while trying to read a text file in databricks using Local File API's instead of Spark API.</title>
      <link>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34487#M25229</link>
      <description>&lt;P&gt;Thank you for the help @Kaniz Fatma​&amp;nbsp;!! Appreciate it. &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:00:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/issue-while-trying-to-read-a-text-file-in-databricks-using-local/m-p/34487#M25229</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2021-12-12T16:00:55Z</dc:date>
    </item>
  </channel>
</rss>

