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

Add support for predicates / operators #518

Open
8 of 13 tasks
michael-simons opened this issue Jan 17, 2024 · 7 comments
Open
8 of 13 tasks

Add support for predicates / operators #518

michael-simons opened this issue Jan 17, 2024 · 7 comments

Comments

@michael-simons
Copy link
Collaborator

From sql2cypher created by jexp: neo4j-contrib/sql2cypher#14

Conditional Operators / Predicates

https://neo4j.com/docs/cypher-manual/current/clauses/where/#boolean-operations

  • AND, OR
  • Equals, Greater, Less Than
  • Less Than Equal, Greater Than Equal (missing in jooq @lukaseder)
  • BETWEEN
  • TRUE / FALSE (are they in SQL @lukaseder?)
  • NOT
  • Null handling (IS NULL etc)
  • NULL value
  • Regular expressions https://neo4j.com/docs/cypher-manual/current/clauses/where/#query-where-regex
  • String predicates STARTS WITH, ENDS WITH, CONTAINS -> LIKE ?
  • Predicate (list) functions and predicates? (not sure if there is an equivalent in SQL, perhaps with subqueries)
  • Label / Rel-Type checks ?
  • exists and count expressions

Predicate functions https://neo4j.com/docs/cypher-manual/current/functions/predicate/

@michael-simons
Copy link
Collaborator Author

  • Less Than Equal, Greater Than Equal (missing in jooq @lukaseder)

See QOM.Le, QOM.Ge

Yes, there are org.jooq.True, org.jooq.False, and org.jooq.Null. They should probably be reflected in the QOM API for better discoverablity: jOOQ/jOOQ#14537

@michael-simons
Copy link
Collaborator Author

Regarding these:

My suggestion here is:

  • jOOQ has QOM.StartsWith, etc. which are mere jOOQ convenience. They can't be parsed, currently, as there is not SQL equivalent
  • Like can be pattern matched as follows:
    • If the right hand side is a constant (org.jooq.Param), then process that Param in the translator
      • If it's x%: STARTS WITH
      • If it's %x: ENDS WITH
      • If it's %x%: CONTAINS
      • Otherwise, or if x contains % or _ then apply below regex rule
    • Otherwise turn LIKE into a regex: <lhs> ~= replace(replace(quoteForRegex(<rhs>), '%', '.*'), '_', '.'), optionally handling the LIKE .. ESCAPE clause

@michael-simons
Copy link
Collaborator Author

for LIKE:
might even make sense to do the replace in cypher, so that non-literal values (parameters) or expressions are also handled correctly.

the only tricky bit is escaping for regexp, perhaps something like:

reduce(s=str, rep IN [['?','\?'], ...['_','.'],['%','.*']] | s = replace(s, rep[0],rep[1])

or alternatively spell it out with a replace cascade

@michael-simons
Copy link
Collaborator Author

might even make sense to do the replace in cypher, so that non-literal values (parameters) or expressions are also handled correctly.

That's what I meant by "Otherwise turn LIKE into a regex: <lhs> ~="

@michael-simons
Copy link
Collaborator Author

Ah you didn't mean replacing the string in the transpiler but in the generated statement. Yep, sgtm.

@michael-simons
Copy link
Collaborator Author

Well, if there's a constant (org.jooq.Param), then that can be processed in the translator. Otherwise, it simply cannot.

@michael-simons
Copy link
Collaborator Author

I've added support for BETWEEN SYMMETRIC too. Dogfooding has shown that the QOM API needed a significant refactoring: jOOQ/jOOQ#14546, so I've moved the tag

@michael-simons michael-simons transferred this issue from another repository Feb 27, 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

No branches or pull requests

1 participant