- Notifications
You must be signed in to change notification settings - Fork 48
[poc] Async support #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
Signed-off-by: Andre Furlan <andre.furlan@databricks.com>
excId, ok := ctx.Value(driverctx.ExecutionContextKey).(*Execution) | ||
if !ok { | ||
return nil | ||
} | ||
return excId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since it's the Execution
pointer and not Id being returned, perhaps use exc
instead of excId
one idea to improve would be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick look over, mainly focused on the interface. Looking forward to this!
Authenticator string //TODO for oauth | ||
| ||
RunAsync bool // TODO | ||
RunAsync bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason why this is set at the config level, rather than on a per-query level? Or rather, is there any reason not to provide different methods for callers to use depending on whether they want the sync vs. async behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. It was the fastest way I got the PoC to work :-) . I have to think about the methods in the interface, maybe it does make sense to do as you say
// i := v | ||
// go func() { | ||
// _, exc, err := db.QueryContext(ogCtx, fmt.Sprintf("select %s", i)) | ||
rs, exc, err := db.QueryContext(ogCtx, `SELECT id FROM RANGE(100) ORDER BY RANDOM() + 2 asc`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure I'm understanding the semantics of this correctly:
- If the query has completed (direct results), then
rs
will be set and the caller can fetch the results - Otherwise, the caller can use
exc
to get the operation ID(?), and use that to poll for query status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @aldld , that's the idea... there is more to the execution than the ID, but it is just data that can be saved and used later.
I am not very happy with the way to check the results yet with different methods to query, check, get results. There must be a simpler way to merge check and get results in the same call. See the example I added so you have an idea of what I am talking about.
PoC on one approach of supporting true async apis.
Goal
The goal is to support server restart while a query is running.
It is not the goal to support parallelism and non-blocking calls. These can easily be supported with go routines with the standard sql API.
API
Function and type names are not final.
sql.OpenDB(connector)
works the same. No change. This is the synchronous API.dbsql.OpenDB(connector)
is new. This is where the asynchronous APis live.So the user has to explicitly want to interact with asynchronous APIs.
dbsql.OpenDB()
returns `DatabricksDB interface.The APIs support
DirectResults
, which means that calls are synchronous up to 5s, then become asynchronous. The sql.Rows and sql.Result APIs remain exactly the same.Usage
A typical workflow would be something like: