cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to do python within sql query in Databricks ?

Yagao
New Contributor

Can anyone show me one use case how to do python within sql query ?

5 REPLIES 5

Anonymous
Not applicable

Did you get any solution? My Nordstrom Employee Portal

Anonymous
Not applicable

Hi @Ya Gaoโ€‹ and @Brooks fosterโ€‹ ! It seems like maybe you two are experiencing a similar need? I would love to know more about what you are trying to solve for - please comment below! And of course if you have made any progress since you posted, definitely let us know.

In the meantime I am going to try and find a Databricks expert who has used Python in a SQL query for you!

Dicer
Valued Contributor
spark.sql("select <Your Coumn> from <Your Table> ")
 

tomasz
Databricks Employee
Databricks Employee

To run Python within a SQL query you have to first define a Python function and then register it as a UDF. Once that is done you are able to call that UDF within a SQL query. Please take a look at this documentation here:

https://docs.databricks.com/spark/latest/spark-sql/udf-python.html#register-a-function-as-a-udf

jose_gonzalez
Databricks Employee
Databricks Employee

Hi @Ya Gaoโ€‹,

Just a friendly follow-up. Did any of the responses help you to resolve your question? if it did, please mark it as best. Otherwise, please let us know if you still need help.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group