-
Notifications
You must be signed in to change notification settings - Fork 168
feat(rust/core): add async traits for Driver, Database, Connection, Statement #3714
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
|
CC @felipecrv @mbrobbel too |
a52ee39 to
ad1f184
Compare
mbrobbel
left a comment
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.
For the Send bound stuff I would suggest using https://docs.rs/trait-variant/0.1.2/trait_variant/ (as suggested in https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits/#async-fn-in-public-traits).
For async vs sync I would suggest using the async trait as the default and provided sync helper traits and structs. But the truth is; there is no elegant solution available today for this.
|
|
2888512 to
61963f8
Compare
felipecrv
left a comment
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.
Once the code in blocking is moved back to the current location I can give another review.
@lidavidm do we really need everything to be a Future, even get/set options?
I made the |
|
Even get_option may involve I/O in some cases (e.g. if the driver has to run a query to fetch some information), unfortunately |
61963f8 to
c838f22
Compare
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.
Does arrow-rs not already have a trait for this?
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.
I see that arrow-rs does not implement ArrowAsyncDeviceStreamHandler etc yet. I think we need to figure this out in arrow-rs
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.
Related issue apache/arrow-rs#7228
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.
I think there needs to be explanation somewhere of what "local" means (traits that are not Send?)
Additionally, does it make sense to have non-Send variants? It's not clear to me that that's useful (when would a connection be limited to a single thread?)
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.
This is about flexibility. I think that, in practical terms, most drivers will implement the async trait with a Send bound. But someone might want to implement an async Rust driver that uses an FFI library to connect to a specialized database.
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 it actually worth optimizing for that flexibility, though? (Versus, say, expecting that such a very specialized database would instead manage this internally?)
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.
Because as it stands, this means duplicating every method/trait
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.
IMO it’s not worth supporting the non-Send variant (maybe someday in the future, when the crate stabilizes and reaches versions > 1.0.0).
Personally, I was planning to use adbc for the wasm target, and as far as I understand, all the necessary structures are Send.
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.
I agree that there may be a need for it, but as of now the driver implemented in Rust is so little known (I can find only sedona-db by @paleolimbot), I feel it might not be too late to remove it for now to reduce the maintenance burden, and then add it when there is demand.
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.
FYI: I found another driver (which seems to be fairly recent): https://github.com/marconae/exarrow-rs
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.
The sedona-db implementation is unused to my knowledge so don't worry about any compatibility issues there!
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.
@marconae sorry for the random ping, but would you like to weigh in on async ADBC interfaces? 🙂
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.
This is about flexibility.
We might end up offering too much flexibility in a standard that is supposed to make database access more uniform. If a database doesn't allow its handles to move between threads, it's the responsibility of the ADBC driver wrapping these database APIs to fix for that rather than bubbling up these restrictions to Rust users of ADBC via the type system which basically means a rewrite of the entire application depending on the ADBC driver that it uses.
…or DataFusion driver Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
…d sync wrappers Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
65929ed to
4996555
Compare
Hi, I’m back again. This is a continuation of this PR: #3712
I’ve returned with a draft of the asynchronous traits. They fully mirror the synchronous API (with a couple of differences in input arguments), adding
Future + Sendas the return type.As further development, I can propose:
Abstract away from async executors and introduce an
AsyncExecutortrait with a singleblock_onmethod. Inadbc_core, add helper structures likeSyncDriverWrapper<E: AsyncExecutor, D: AsyncDriver>and others, and implement the corresponding synchronous traits for them.Add some procedural macro magic to automatically implement the synchronous traits by generating the code described above.