<?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: Use Python notebook to read data from Databricks in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112533#M4874</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/127895"&gt;@Advika_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer. I modified to the below according to your recommendation. Howerver, I still received column names, instead of the data, as the result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df = (spark.read.format("jdbc")
    .option("url", jdbc_url)
    .option("dbtable", query)
    .option("user", "token")
    .option("password", access_token)
    .option("driver", "com.databricks.client.jdbc.Driver")
    .option("fetchsize", "10000")
    .load())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw a solution recommending to import and register the&amp;nbsp;dbsqlDialectClass&amp;nbsp;to the JAR file, but I can't figure out how to do it properly. I appreciate any guidance!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Mar 2025 04:24:28 GMT</pubDate>
    <dc:creator>cony2025</dc:creator>
    <dc:date>2025-03-14T04:24:28Z</dc:date>
    <item>
      <title>Use Python notebook to read data from Databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/111796#M4849</link>
      <description>&lt;P&gt;I'm very new to Databricks. I hope this is the right place to ask this question.&lt;/P&gt;&lt;P&gt;I want to use PySpark in a notebook to read data from a Databricks database with the below codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;databricks_host = "adb-xxxx.azuredatabricks.net"
http_path = "/sql/1.0/warehouses/xxxx"
access_token = "dapixxxx"
jdbc_url = f"jdbc:databricks://{databricks_host}:443/default;transportMode=http;ssl=1;httpPath={http_path};AuthMech=3"

query = "(SELECT DISTINCT building_code, city FROM wphub_poc.gold.v_d_building) as subquery"

df = (spark.read.format("jdbc")
    .option("url", jdbc_url)
    .option("query", query)
    .option("user", "token")
    .option("password", access_token)
    .option("driver", "com.databricks.client.jdbc.Driver")
    .option("fetchsize", "10000")
    .load())

print(df.printSchema())
print(df.show())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the df result only contains the litteral texts from the SELECT query, like this. Do I do anything wrong and how to fix it? Thank you!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2025-03-04 225915.png" style="width: 259px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15239iAF3E039E0983AFB5/image-dimensions/259x52?v=v2" width="259" height="52" role="button" title="Screenshot 2025-03-04 225915.png" alt="Screenshot 2025-03-04 225915.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2025-03-04 211512.png" style="width: 200px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15240i84CD10CB7B92BB43/image-size/small?v=v2&amp;amp;px=200" role="button" title="Screenshot 2025-03-04 211512.png" alt="Screenshot 2025-03-04 211512.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2025 07:11:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/111796#M4849</guid>
      <dc:creator>cony2025</dc:creator>
      <dc:date>2025-03-05T07:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use Python notebook to read data from Databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/111993#M4850</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/152009"&gt;@cony2025&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;It seems the issue is due to the &lt;STRONG&gt;query&lt;/STRONG&gt; parameter. When using &lt;STRONG&gt;.option("query")&lt;/STRONG&gt;, Spark automatically wraps your SQL inside an outer SELECT * FROM ( ), which leads to invalid nested subqueries if your original query already includes an alias.&lt;/P&gt;
&lt;P&gt;To avoid this, try using &lt;STRONG&gt;.option("dbtable")&lt;/STRONG&gt; instead. It prevents the automatic wrapping and should resolve the issue.&lt;/P&gt;
&lt;P&gt;Let me know if this doesn't help!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Mar 2025 11:29:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/111993#M4850</guid>
      <dc:creator>Advika_</dc:creator>
      <dc:date>2025-03-07T11:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Use Python notebook to read data from Databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112533#M4874</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/127895"&gt;@Advika_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer. I modified to the below according to your recommendation. Howerver, I still received column names, instead of the data, as the result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df = (spark.read.format("jdbc")
    .option("url", jdbc_url)
    .option("dbtable", query)
    .option("user", "token")
    .option("password", access_token)
    .option("driver", "com.databricks.client.jdbc.Driver")
    .option("fetchsize", "10000")
    .load())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw a solution recommending to import and register the&amp;nbsp;dbsqlDialectClass&amp;nbsp;to the JAR file, but I can't figure out how to do it properly. I appreciate any guidance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 04:24:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112533#M4874</guid>
      <dc:creator>cony2025</dc:creator>
      <dc:date>2025-03-14T04:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use Python notebook to read data from Databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112559#M4875</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/152009"&gt;@cony2025&lt;/a&gt;&amp;nbsp;Could you load the whole table as TempView and see if what happens&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df = (spark.read.format("jdbc")
    .option("url", jdbc_url)
    .option("dbtable", "wphub_poc.gold.v_d_building")
    .option("user", "token")
    .option("password", access_token)
    .option("driver", "com.databricks.client.jdbc.Driver")
    .option("fetchsize", "10000")
    .load())

df.createOrReplaceTempView("building_data")

spark.sql("SELECT DISTINCT building_code, city FROM building_data").show(truncate=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 09:20:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112559#M4875</guid>
      <dc:creator>Akash_Varuna</dc:creator>
      <dc:date>2025-03-14T09:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use Python notebook to read data from Databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112566#M4876</link>
      <description>&lt;P&gt;I would try changing the query to something like the following, it should return the column names in the table so you can see if the jdbc call is actually returning the data correctly&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT * FROM wphub_poc.gold.v_d_building limit 10&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 10:21:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/use-python-notebook-to-read-data-from-databricks/m-p/112566#M4876</guid>
      <dc:creator>dna1</dc:creator>
      <dc:date>2025-03-14T10:21:30Z</dc:date>
    </item>
  </channel>
</rss>

