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

Scalar Subqueries and List Subqueries #217

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

thobe
Copy link
Contributor

@thobe thobe commented Apr 13, 2017

@thobe thobe added the CIP label Apr 13, 2017
@thobe
Copy link
Contributor Author

thobe commented Apr 13, 2017

There is still some work to be done here, but comments are welcome.

Ideas for examples to include in the document:

  • Sorting lists
  • Filtering lists
  • Unpacking a singleton list

@thobe thobe changed the title CIP2017-03-29 Scalar Subqueries and List Subqueries Scalar Subqueries and List Subqueries Apr 13, 2017
----
ListSubquery = '[', SingleValueSubquery, ']' ;

ScalarSubquery = '<(((<', SingleValueSubquery, '>)))>' ;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These fish-brackets are a place holder, we really need something better to delineate a scalar subquery. Suggestions are most welcome. It could be a keyword, I considered 'SINGLE', '(', SingleValueSubquery, ')' ;, but single is already used as a predicate function (actually also a type of subquery) in Cypher.

Another suggestion was 'SCALAR', '(', SingleValueSubquery, ')' ;, but that didn't feel quite right.

Copy link
Contributor

@boggle boggle Apr 17, 2017

Choose a reason for hiding this comment

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

More random ideas:

  • VALUE ( subquery ) (but: too generic?)
  • QUERY ( subquery ) (but: too generic?
  • EVAL ( subquery ) (but: sounds too much like metaprogramming?)
  • $( subquery ) (but: feels like we should reserve this syntax, perhaps for metaprogramming/templating)
  • (> ()-[]->(c) RETURN c <) - Kinda like these "injection (or inception?) parens"
  • (| ()-[]->(c) RETURN c |) - Bananas ftw :)

Copy link
Contributor

@boggle boggle Apr 17, 2017

Choose a reason for hiding this comment

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

Maybe the whole approach is also wrong.. for crpq we're discussing path pattern predicates.. maybe here we're missing inline function or expression-level template definitions? Given those, the quest for scalar subqueries really just becomes a search for anonymous function syntax.

DECLARE  $subquery(args)=expr
...
WITH expr1 + $subquery(...)
...

Copy link
Contributor

Choose a reason for hiding this comment

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

One more... if we don't allow subquery short forms, i.e. starting with a pattern, round parenthesis might actually suffice from a parsing point of view... (MATCH (a)-[r]->(b) RETURN r). It's inconsistent with the other subquery forms under discussion but it would save us the hassle of coming up with weird fancy bracket syntax.

Copy link

Choose a reason for hiding this comment

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

  • 'SCALAR' as a keyword is simple and "does what it says on the tin"; i.e. it's very clear in its intention. What are the objections to its use?

  • $( subquery ) is rather elegant. Re boggle's comments about the drawback, would it not be reasonable to infer from context?

  • The inline function/expression-level template defs option looks very unwieldy from a readability point of view and does not marry up at all well with our other Subquery Family syntax. I don't see any advantage in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've had that thought as well...

if we don't allow subquery short forms /.../ round parenthesis might actually suffice from a parsing point of view

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 remember what the objections were to SCALAR - perhaps we never suggested it in prior conversation? I know that we suggested VALUE and decided that it was definitely too generic.

I'm leaning towards SCALAR now, since I agree with Stefan that since we've used $ for parameters, we should reserve variations with that character for variations of parametrization.

@boggle
Copy link
Contributor

boggle commented May 1, 2017

Just realized... using round parenthesis for scalar subqueries seems not well aligned with EXISTS {} which also returns a single value... in a way.. Not sure how to solve this given that we overloaded exists(n.prop)

@a-type
Copy link

a-type commented Jun 1, 2019

This seems like a very powerful feature and I'd love to see it added. In particular I think this would give a massive boost to the GraphQL->Cypher use case seen the in Neo4j-GraphQL tools. It's been two years without much conversation, but what would it take to get this moving again?

@thobe
Copy link
Contributor Author

thobe commented Jun 28, 2019

@a-type indeed this was first conceived of when we did a comparative analysis of Cypher and GraphQL in 2015. What is primarily needed for this to move forward is an openCypher implementor with a desire to get this into their product. In terms of actual work, the next step in terms of actual work on this proposal is to start designing TCK test cases to guide an implementation.

And stylistic fixes for the style god.
Clarify the semantics of Scalar Subqueries.
Specify the reason for having SingleValuePatternQuery,
 i.e. it being the future of Pattern Comprehension.
@thobe
Copy link
Contributor Author

thobe commented Jun 28, 2019

I believe that if we disallowed the SingleValuePatternQuery form from ScalarSubquery - which has the effect of a ScalarSubquery always starting with a keyword - we could do away with the SCALAR keyword as a prefix for ScalarSubquery with only a single parser lookahead.

I think that would be nicer.

@SpaghettiFactory
Copy link

Does this enable sorting, filtering and using aggregate functions in Map Projections, as mentioned in this blog post?

Would be awesome if neo4j could be queried like this!

@boggle
Copy link
Contributor

boggle commented May 30, 2020

Yes, that's the goal of this proposal which I expect to also become a part of GQL. It may happen eventually in Neo4j but note this repository is about language design primarily, not implementation by vendors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants