Problem/Motivation
We have support LIKE
and NOT LIKE
operators. But we do not have the opposite operator to REGEXP
, namely, the NOT REGEXP
(negated regular expression).
It can blocks others feature requests, eg. #2853188: Add negated regular expressions for views filters (string and integer). Let's add this antagonist for the complete picture of the world.
Proposed resolution
- Add
NOT REGEXP
+ test coverage likeREGEXP
. - Fix testRegexCondition test, because it has an incorrect comparison (sort() returns true/false instead of sorted array) and an outdated style (see #6 and #8).
Remaining tasks
Commit.
User interface changes
None. (That'll be in #2853188: Add negated regular expressions for views filters (string and integer) when we expose this to views).
API changes
None. We're just getting pgsql up to parity with mysql for this particular query operation, and fixing the tests to cover it.
We *are* converting a Kernel test into using a dataprovider, but we rename the test method so there's no confusion. It's not a base class or trait shared by tests, so this doesn't count as an API change.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#21 | 2860644-21.patch | 5.3 KB | shashikant_chauhan |
#13 | interdiff.txt | 664 bytes | Anonymous (not verified) |
#13 | 2860644-13.patch | 5.3 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedvaplas created an issue. See original summary.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedThe test is based on
testRegexCondition()
, only the results are replaced by their opposites + used no-deprecated assert methods.Also nit improve pattern test method testRegexCondition().
Comment #3
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSince this patch adds a test for
NOT REGEXP
, we need to make sure that it works on SQLite too so I queued test runs for those environments.Comment #4
daffie CreditAttribution: daffie commentedThe patch looks good to me. But I have a bit of a problem with the current testRegexCondition test and the new copied and changed a bit version testNotRegexCondition test. The test testRegexCondition is written before we changed to PHPUnit testing. For PHPUnit testing it would be best if we split testRegexCondition into two separate tests and each with a provider method. @vaplas: What is your opinion?
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commented@daffie, your comment makes sense to me, definitely!
IMHO, we have 3 in 1 tests :) And only one of them is sensitive to the operator (
REGEXP
orNOT REGEXP
). Two other relate to the processing of the regular expression as a whole, and are independent of the operator.Such:
// Ensure that filter by "#" still works due to the quoting.
It has depend only from 'pattern' of regular expression (via SQLite reason).
// Ensure that REGEXP filter still works with no-string type field.
It has depend only from 'type of field' of regular expression (via PostgreSQL reason).
Also, during refactoring, I discovered one magical piece:
This found George. What is he doing here? Patronage by Foreach? After refactoring such a feint will not work :)
Interdiff not attached, because it does not seem helpful.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedNot. By
sort()
, because it return only true|false. Hence:always pass with equal sizes.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedBit cleanup.
Comment #8
daffie CreditAttribution: daffie commented@vaplas: Tank you for rewriting the test, but it was not in the way that I had intended. I hope you do not mind. In my way you can easily add new tests by adding them to the dataprovider. See https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writ.... Your changes to the PostgreSQL Connection class are for me RTBC. If you like my changes to SelectTest class, you set the issue status to RTBC.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedSuper nice, I can look at the #8 patch all day long!)
Also I was wrong when I thought that case with
'no-string'
does not depend on the operator. We really need to check both operators. Sorry for the noise about this.After #8 we lost few comments:
But maybe the git logs are the best way to analyze the reason for the appearance of these cases in
providerRegularExpressionCondition
.RTBC for me. But it will be great if someone will confirm this too.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentednit typo
return [
.Comment #12
daffie CreditAttribution: daffie commented@vaplas: Feel free to add the comments that you think that should be added.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedI will not cry much on these comments :) I just wanted to say, that I saw it during the review and do not mind, because the git-history is better tool for this (I read about it in book "Clean Code / Robert Martin"). But I also do not mind saving comments, of course.
So, we can not just duplicate the current REGEXP test to NOT REGEXP, because this leads to a number of problems:
sort()
error.Hence the changes in scope.
#8 patch good fix problems with database support regular expression (complete pair REGEXP - NOT REGEXP, and correction tests). Just fix nit typo.
Comment #14
Anonymous (not verified) CreditAttribution: Anonymous commentedUpdate IS and title, because we also fix the error in the testRegexCondition.
Comment #19
dwwNo longer applies to the 8.8.x branch.
I only care about this because it's blocking #2853188: Add negated regular expressions for views filters (string and integer), and I don't have a local pgsql environ to test with.
But maybe I'll have time for a blind reroll and see what the testbot thinks. If I get a chance to try that, I'll assign to myself.
Meanwhile, if anyone else wants to move this forward, please do. ;)
Thanks!
-Derek
Comment #21
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer commentedJust rerolled the previous patch.
Comment #22
dwwFantastic, thanks @shashikant_chauhan!
I just carefully reviewed the code. The test coverage looks great (thanks @daffie and @valpas -- whom I think was the original "Anonymous" we see in this issue). For a kernel test, a data provider is fine, and doesn't incur the same costs as a data provider for a functional test.
Everything looks great in the code change itself. It's simple and clean. No code style violations, etc.
I just requeued it for a bunch of different DB configurations (most importantly, pgsql!). ;) Assuming the bot comes back all green, this is ready. If it lands in time, hopefully we can get #2853188: Add negated regular expressions for views filters (string and integer) in, too, in time for 8.9.0.
Thanks folks!
-Derek
Comment #23
dwwThe SQLite test failure looks like a random fail from MediaLibrary JavaScript tests. :/
That's totally unrelated to this patch.
Meanwhile, fleshing out the summary more, and calling this a task. You could almost call it a bug that we support NOT REGEXP in mysql but not pgsql.
Still RTBC, unless the pgsql tests fail for some reason. ;)
Comment #24
alexpottCommitted and pushed 70e8937c9b to 9.0.x and 9400de336c to 8.9.x and 03bdf28929 to 8.8.x. Thanks!
Comment #28
dwwSweet, thanks! Unblocked #2853188: Add negated regular expressions for views filters (string and integer). That's pretty close to RTBC already.
Cheers,
-Derek