question

arkiboys avatar image
0 Votes"
arkiboys asked KranthiPakala-MSFT edited

sql against dataframe

Hi,
I have a dataframe which I am querying using pyspark. in azure databricks
Question:
How is it possible to query this dataframe using sql?
Thank you

azure-databricks
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KranthiPakala-MSFT avatar image
0 Votes"
KranthiPakala-MSFT answered KranthiPakala-MSFT edited

Hello @arkiboys,

Thanks for the question and using MS Q&A platform.

In order to run SQL queries on Data frame, first we need to convert them to temporary tables in our spark session as shown in below example. (Please note that these tables are defined for current session only and will be deleted once Spark session is expired. )

199750-image.png

Once you have your temporary table created for your data frame, you can use SQL queries as shown below:

199809-image.png


199810-image.png


Here is the referenced article where a detailed explanation is provided by a community volunteer: Running SQL queries on Spark DataFrames
Here is another helpful document: Run SQL queries on DataFrames

Hope this will help. Please let us know if any further queries.


  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how

  • Want a reminder to come back and check responses? Here is how to subscribe to a notification

  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators



image.png (9.6 KiB)
image.png (4.0 KiB)
image.png (11.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.