-
Notifications
You must be signed in to change notification settings - Fork 267
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
External functions #567
External functions #567
Conversation
ed0d996
to
90cd98f
Compare
Reviewing this, I noticed a funny bug we have ATM - nonexistent functions in result columns just get ignored completely (#573)
compare:
Bug is due to this line: https://github.com/tursodatabase/limbo/blob/main/core/translate/planner.rs#L365 Anyway, this got me thinking whether we should try to validate and/or bind functions already in Advantages:
Disadvantages: We would probably have to add another new custom AST node like |
I'd like to raise an issue of terminology wrt 'Generic Function'. I realize there aren't enough terms to go around, but the term has been used for functions that operate differently depending on what objects they're called on (polymorphism). This usage originated in the early 1980s with Lisp, in Howard Cannon's Flavors object system, predecessor to the Common Lisp Object System. More important than the history is that it is in wide usage today, in languages from C++ to Python, Typescript, and R. There's even a Wikipedia page on it. Also relevant is that, to me at least, "generic" doesn't convey anything meaningful here. "External function" might be more suggestive. (At least, on a quick scan, I didn't see anything suggesting any sort of polymorphic dispatch). I'm not going to insist that the term be used the same way in all contexts for all time! I just want to flag the potential for confusion so you can mitigate it, either with different terminology or taking care in how you describe it. Or: Make them actually generic functions, with externally-loadable implementations for different types, so a plugin that defines, say, a GIS coordinate and a plugin that defines a geometric coordinate can both define a distance(p1, p2) function, giving great circle or cartesian distances. As a bonus, this side-steps namespace collision issues. Implementation and semantics can be straightforward if you limit dispatch to the first argument, as was the case with the original Flavors version. Downside is you cannot validate the call signature until the type of the object is known, which may be later than your current validation of the AST. |
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 I agree with @BobKerns that it makes sense to rename to something like ExternalFunction. Nevertheless, looks great
There's a potential problem w/ waiting this late to resolve the function in case it's an aggregate: #576 (comment) Ofc we can for now just do double the work and resolve the function using the symbol table in the planner as well |
d34a166
to
e633003
Compare
The database object is a way to represent state that's shared across multiple connections. We don't want to release that object until all connections are closed.
We don't need them anywhere and they make it hard to introduce GenericFunction.
e633003
to
90e90ea
Compare
90e90ea
to
0aabcdd
Compare
This pull request adds support for external functions, which are functions provided by extensions. The main difference to how things are today is that extensions can register functions to a symbol table at runtime instead of specifying an enum variant.