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:ย 

Query API Result

lenonlmsv
New Contributor II

Hi, I'm new here.

Currently I have to read information from a query in databricks. I've used the query API to get the query definition but so far I'm not able to run the query and get the results.

Is it possible? Thanks

3 REPLIES 3

daniel_sahal
Esteemed Contributor

When using the JobsAPI you need to specify dbutils.notebook.exit("returnValue") to pass the results once the notebook finished it's job (https://docs.databricks.com/notebooks/notebook-workflows.html#notebook-workflows-exit).

Then you can get notebook_output.result through the API (https://docs.databricks.com/dev-tools/api/latest/jobs.html#operation/JobsRunsGetOutput)

I'm actually using the '/2.0/preview/sql' endpoint.

I tried to use this one in the past but seems that the return has a limitation. Should I switch to the jobs API?

daniel_sahal
Esteemed Contributor

It depends on what you're trying to do.

If you want to simply get a single value (or array of values) from the query - then jobsAPI is the way to go.

If you want to get the actualy query results as a table, then the best approach would be to save the results as a file on a storage.

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