-
Notifications
You must be signed in to change notification settings - Fork 5
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
User defined aggregate functions #10
Comments
Generally, I'd avoid introducing magic variables. If you need the original set, alias it, and index can be obtained with
With that, I think there are two orthogonal problems here: recurrence relations and aggregation.
|
And when we have lambda functions edgedb/edgedb#301 we might use them as a mechanism/syntax to write recursive queries. |
I want to query books of multiple libraries: |
Here's one way of doing it:
|
To select all books from a set of libraries given a set of library ids:
The idea here is that when you select a set of |
Thanks for the answer. I will describe my use case more clearly, i think it's not clear yet. I run a complex query to calculate a set of available Now i want to get the availability of multiple Using the
|
As far as i understand, this is not a recurrence relation since each element depends on the whole set and not only the previous element.
It's also possible to implement |
Interesting. We do have a plan to implement a more general partition-and-reduce statement: edgedb/edgedb#104 (comment). It should be possible to express what you're looking for using that syntax:
This syntax is admittedly a tad verbose for this particular purpose due to it being very generic (we will likely iterate on it before implementing and/or add some syntax sugar around it). Basically. because EdgeQL queries have to map 1:1 to SQL queries we are constrained by the type of semantics we can implement efficiently. Specifically, there's no real notion of iteration state in SQL, aside from the aforementioned recursive CTEs and aggregate functions. Another quirk is that those SQL mechanisms work on scalar expressions, not sets, which means your accumulator state must be scalar also. |
Interesting, i didn't know that. Why is this? How do you make sure it's performant?
Yes, it is. I spent a dozen of minutes trying to understand it ... but i couldn't. Also couldn't find it in the docs.
Please note that
Oh! So even if there were a way to define custom aggregate functions, it wouldn't work for my use case? 🤔 That leaves me with
|
Preserving a 1:1 query correspondence has a number of important advantages:
Postgres is actually really good at handling complex queries. It's not the size of the query text that matters, it's the inherent runtime complexity of the operations in it. |
That's because it isn't implemented yet (aside from being able to parse the syntax).
The hypothetical query I posted accounts for that. Remember that in EdgeQL everything is a function over a Cartesian product of the arguments, including the tuple constructor, so
is a set of |
Thank you for your answers @elprans This partition and reduce statement is really powerful.
I think it's the closest thing to my original idea. Very interesting |
Taken from Spectrum.
This is how i first imagined the syntax:
Note that this doesn't allow defining arbitrary aggregate functions, but rather executing them, just like
FOR
.Example 1
This would give a result of
hello world
.We can also access the current index by using
_index
and the original set using_source
Result:
2 hello world
The text was updated successfully, but these errors were encountered: