cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Honored Contributor III

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
Honored Contributor III

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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.