Skip to content
Permalink
Browse files
fix(spanner/spannertest): Fix the "LIKE" clause handling for prefix a…
…nd suffix matches (#4655)

Co-authored-by: Knut Olav Løite <koloite@gmail.com>
  • Loading branch information
sryoya and olavloite committed Aug 23, 2021
1 parent cde8697 commit a2118f02fb03bfc50952699318f35c23dc234c41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
@@ -873,6 +873,12 @@ func evalLike(str, pat string) bool {

// Lean on regexp for simplicity.
pat = regexp.QuoteMeta(pat)
if !strings.HasPrefix(pat, "%") {
pat = "^" + pat
}
if !strings.HasSuffix(pat, "%") {
pat = pat + "$"
}
pat = strings.Replace(pat, "%", ".*", -1)
pat = strings.Replace(pat, "_", ".", -1)
match, err := regexp.MatchString(pat, str)
@@ -816,6 +816,21 @@ func TestIntegration_ReadsAndQueries(t *testing.T) {
{"Jack", 1.85},
},
},
{
`SELECT str FROM SomeStrings WHERE str LIKE "a%"`,
nil,
[][]interface{}{
{"afoo"},
{"abar"},
},
},
{
`SELECT Name FROM Staff WHERE Name LIKE "%e"`,
nil,
[][]interface{}{
{"George"},
},
},
{
`SELECT Name FROM Staff WHERE Name LIKE "J%k" OR Name LIKE "_am"`,
nil,

0 comments on commit a2118f0

Please sign in to comment.