Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Add support for LIKE.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-simons committed Jul 25, 2023
1 parent 0be77e5 commit c372963
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/neo4j/sql2cypher/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,16 @@ else if (c instanceof QOM.RowIsNull e) {
else if (c instanceof QOM.RowIsNotNull e) {
return e.$arg1().$fields().stream().map(f -> expression(f).isNotNull()).reduce(Condition::and).get();
}
else if (c instanceof QOM.Like like) {
Expression rhs;
if (like.$arg2() instanceof Param p && p.$inline() && p.getValue() instanceof String s) {
rhs = Cypher.literalOf(s.replace("%", ".*"));
}
else {
rhs = expression(like.$arg2());
}
return expression(like.$arg1()).matches(rhs);
}
else {
throw unsupported(c);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/predicates.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,20 @@ WHERE
OR (3 IS NOT NULL AND 4 IS NOT NULL)
RETURN 1
----

== `LIKE` can be used

The `LIKE` comparator can be used, too:

[source,sql,id=t5_0,name=predicates_like]
----
SELECT * FROM movies m WHERE m.title LIKE '%Matrix%'
----

will be transpiled to

[source,cypher,id=t5_0_expected]
----
MATCH (m:`movies`) WHERE m.title =~ '.*Matrix.*'
RETURN *
----

0 comments on commit c372963

Please sign in to comment.