Module com.darkcollective.relix.ast
Class LikePatterns
java.lang.Object
com.darkcollective.relix.ast.internal.LikePatterns
Translation of a SQL Known divergences from SQL
LIKE pattern into an anchored regular expression.
% becomes .* and _ becomes .; every regex
metacharacter is escaped so it matches literally; the result is anchored with
^…$ so it matches the whole value, as LIKE does.
This lives beside PatternPredicate because more than one consumer
needs it — the in-engine predicate evaluator and the MongoDB $regex
renderer — and they previously carried byte-identical private copies,
including the same hand-typed metacharacter set. They agreed only by luck.
Known divergences from SQL LIKE
A σ that is pushed down to a SQL backend is evaluated by that
backend's own LIKE, not by this translation, so the two are not
interchangeable in every case. The differences, all pre-existing:
- Case sensitivity. This translation is case-sensitive. MySQL's
LIKEis case-insensitive under its default collation. - Newlines.
_maps to regex., which does not match a line terminator; SQL's_matches any character. - Escape clause.
LIKE … ESCAPEis not modelled, so a backslash in a pattern is treated as a literal backslash rather than as an escape for a following%or_.
-
Method Summary
-
Method Details
-
toRegex
Converts a SQLLIKEpattern to an anchored regular expression.- Parameters:
pattern- the LIKE pattern, using%and_wildcards; must not be null- Returns:
- an anchored regex matching the same values, e.g.
a%becomes^a.*$
-