Skip to content
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

Feature/subquery #794

Merged
merged 16 commits into from
Jul 17, 2024
Merged

Feature/subquery #794

merged 16 commits into from
Jul 17, 2024

Conversation

bplatz
Copy link
Contributor

@bplatz bplatz commented Jun 3, 2024

Adds new subquery capability. Supports multiple parallel subqueries, or nested subqueries.

A new solution-value interface is for select statements to pass formatted solutions for :select clauses instead of final projections as a normal select clause does.

e.g. in EDN - this has a subquery that calculates the average of all favNums, then in the parent query filters to only include users who have a favNum > than the average:

{:context  {:ex "http://example.org/ns/"}
 :select   '[?iri ?favNums]
 :where    ['{:id         ?iri
              :ex/favNums ?favNums}
            [:filter "(> ?favNums ?avgFavNum)"]
            [:query {:where  '{:ex/favNums ?favN}
                     :select '[(as (avg ?favN) ?avgFavNum)]}]]
 :order-by '[?iri ?favNums]}

Tests/examples in: fluree.db.query.subquery-test

@bplatz bplatz requested a review from a team June 5, 2024 11:43
@bplatz bplatz marked this pull request as ready for review June 5, 2024 11:43
src/clj/fluree/db/query/exec.cljc Show resolved Hide resolved
src/clj/fluree/db/query/exec.cljc Show resolved Hide resolved
src/clj/fluree/db/query/exec/select.cljc Outdated Show resolved Hide resolved
src/clj/fluree/db/query/exec/select.cljc Outdated Show resolved Hide resolved
(format-value [fmt db iri-cache context compact fuel-tracker error-ch solution]
"Formats a where search solution (map of pattern matches) by extracting and displaying relevant pattern matches."))
"Async format a search solution (map of pattern matches) by extracting relevant match.")
(solution-value [fmt error-ch solution]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be in a new subquery specific protocol because the solution-value method doesn't apply in all the cases where ValueSelector should be defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started this change, but both format-value and solution-value are tied to implicit-grouping?. So either solution-value needs to rely on the other protocol. At that point it seems they should be part of the same protocol.

Do you still want them separated out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have had reservations about the addition of implicit-grouping? as a protocol method, and especially as a method on this protocol since it was introduced because whether or not something is grouped implicitly is outside the scope of selecting values.

I think the best thing would be to go back to the way it was before and just add the other aggregate selector types to that function as necessary. That would eliminate problems like this and result in more flexibility.

I think that's probably beyond the scope of this particular pr so I might just make that change along with the changes I suggested here in a separate cleanup branch at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't plan to resolve this here - I don't think it is specific to the subquery functionality and can sit as a separate change. We are also still doing some query work, so opinions on ideal solution might change.

src/clj/fluree/db/query/exec/select.cljc Outdated Show resolved Hide resolved
src/clj/fluree/db/query/fql/parse.cljc Outdated Show resolved Hide resolved
@bplatz
Copy link
Contributor Author

bplatz commented Jul 17, 2024

I think all the issues are addressed here @zonotope. @dpetran would be great to move ahead with SPARQL subquery support to go with this.

@bplatz bplatz requested a review from zonotope July 17, 2024 14:28
Copy link
Contributor

@zonotope zonotope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌞

@bplatz bplatz merged commit 3cee302 into main Jul 17, 2024
1 check passed
@bplatz bplatz deleted the feature/subquery branch July 17, 2024 15:42
@bplatz bplatz mentioned this pull request Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants