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.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!