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

FEATURE: Add PropertyValueCriteriaMatcher #4701

Merged
merged 7 commits into from
Mar 11, 2024

Conversation

mficzel
Copy link
Member

@mficzel mficzel commented Nov 3, 2023

The property value criteria matcher accepts a PropertyValueCriteriaInterface and provides static methods to check wether a Node or a PropertyCollection matches those criteria. This allows to use PHP for filtering nodes that were already fetched using the cr-property criteria.

Notes:

  • The PropertyValueCriteriaMatcher operates on the serialized values to be as close to the database operations as possible.
  • The PropertyValueCriteriaMatcher is merked @internal for now as is the the NodeType/ConstraintCheck that does very similar things.

Upgrade instructions

Review instructions

The review should check carefully that the implementation is in line with the checks in the db-drivers.

Also please note that i tried to write this as match statement but die not manage to get readable results for values that have to be read to a variable before checking.

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@mficzel mficzel requested a review from nezaniel November 3, 2023 17:06
@mficzel mficzel force-pushed the 90/addProppertyValueCriteriaMatcher branch 3 times, most recently from d0e65c5 to a8b2eec Compare November 4, 2023 16:56
@mficzel mficzel marked this pull request as ready for review November 4, 2023 17:39
@mficzel mficzel requested a review from mhsdesign November 6, 2023 16:40
@mhsdesign
Copy link
Member

I really like the idea but im not sure how we could check if its working as intended ... wait yes i do!!!

We could adjust the subgraph implementation of a few methods to not the db filtering but filter the nodes via php and see if the e2e test like it ^^

@mficzel
Copy link
Member Author

mficzel commented Nov 6, 2023

Maybe the proposed inMemoryGraph has a use for this aswell :-)

@mhsdesign
Copy link
Member

So i did it exactly as described above in #4710

and i noticed two kind of failing tests:

Not using strict === comparison in PropertyValueEquals

When I execute the findDescendantNodes query for entry node aggregate id "home" and filter '{"propertyValue": "stringProperty = true"}' I expect no nodes to be returned

descendantNodes.feature
      When I execute the findDescendantNodes query for entry node aggregate id "home" and filter '{"propertyValue": "stringProperty = true"}' I expect no nodes to be returned # Features/NodeTraversal/DescendantNodes.feature:112
        findDescendantNodes returned an unexpected result
        Failed asserting that two arrays are identical.
        --- Expected
        +++ Actual
        @@ @@
        -Array &0 ()
        +Array &0 (
        +    0 => 'b'
        +    1 => 'b1'
        +)

String comparison is lowercase in mariadb in PropertyValueContains

https://github.com/neos/neos-development-collection/blob/5917d8b357b1c867c66ac949f72a34266df692d6/Neos.ContentRepository.BehavioralTests/Tests/Behavior/Features/NodeTraversal/DescendantNodes.feature#L125C1-L126C1

001 Scenario:                                                                                                                                                                                                       # Features/NodeTraversal/DescendantNodes.feature:100
      When I execute the findDescendantNodes query for entry node aggregate id "home" and filter '{"propertyValue": "stringProperty *= \"späci\" OR text $= \"a1\""}' I expect the nodes "b,a1,a2a1" to be returned # Features/NodeTraversal/DescendantNodes.feature:126
        findDescendantNodes returned an unexpected result
        Failed asserting that two arrays are identical.
        --- Expected
        +++ Actual
        @@ @@
         Array &0 (
        -    0 => 'b'
        -    1 => 'a1'
        -    2 => 'a2a1'
        +    0 => 'a1'
        +    1 => 'a2a1'
         )

you can find my adjustments here
63a1e0a - if the tests also pass in ci, ill add them to your pr

@mficzel
Copy link
Member Author

mficzel commented Nov 6, 2023

I am not sure we would consider the MariaDB behavior correct by default. Imho we should discuss what we consider correct here.

@mhsdesign
Copy link
Member

Additionally i like to discuss the location of this matcher. With ExpandedNodeTypeCriteria we were also unsure where to place it but eventually considered it okay under Filters as its only supposed to be used by the subgraph impl.

But now it seems like we want to use it at other places as well - similar to PropertyValueCriteriaMatcher ^^

What do you say @bwaidelich?

@mhsdesign
Copy link
Member

And Postgres was exactly the opposite where its always case sensitive? isnt it?

@mficzel
Copy link
Member Author

mficzel commented Nov 7, 2023

@nezaniel can you help us to determine what the best default should be. Personally think the php implementation should be the best match and db-drivers should try to be as compatible as conveniently possible. Imho it is fine that using a specific database can have pros and cons.

@mficzel mficzel marked this pull request as draft November 10, 2023 11:02
@mficzel
Copy link
Member Author

mficzel commented Nov 10, 2023

Converted to draft as the case-sensitivity of the property value operations still has to be defined. Until that is done this is on hold.

@bwaidelich
Copy link
Member

Converted to draft as the case-sensitivity of the property value operations still has to be defined. Until that is done this is on hold.

See #4721

@mhsdesign
Copy link
Member

With the case insensitive matches merged: #4725 this is now unblocked.

@mficzel mficzel force-pushed the 90/addProppertyValueCriteriaMatcher branch from a8b2eec to 5f2db40 Compare February 16, 2024 10:33
@mficzel mficzel force-pushed the 90/addProppertyValueCriteriaMatcher branch 2 times, most recently from cd355df to 79ffd95 Compare February 16, 2024 10:52
@mficzel mficzel marked this pull request as ready for review February 16, 2024 11:02
@mficzel
Copy link
Member Author

mficzel commented Feb 16, 2024

With #4721 solved this is updated and now handles case sensitivity.

Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great one, thanks!
Just a comment re switch vs match

The property value criteria matcher accepts a ``PropertyValueCriteriaInterface`` and
provides static methods to check wether a ``Node`` or a ``PropertyCollection`` matches those criteria.
@mficzel mficzel force-pushed the 90/addProppertyValueCriteriaMatcher branch from 79ffd95 to b28aeb1 Compare February 16, 2024 14:39
mficzel and others added 2 commits February 16, 2024 15:39
…lter/PropertyValue/PropertyValueCriteriaMatcher.php

Co-authored-by: Bastian Waidelich <[email protected]>
@mhsdesign
Copy link
Member

As last time i again run the PropertyValueCriteriaMatcher against the behavioural tests by using it for filtering instead the db in the ContentSubgraphWithRuntimeCaches (which would be then rather a SlowContentSubgraph implementation)

The previous matter of case sensitivity was resolved, but the also mentioned issue Not using strict === comparison in PropertyValueEquals in propertyValueEquals still persists.

001 Scenario:                                                                                                                                                                  # Features/NodeTraversal/DescendantNodes.feature:100
      When I execute the findDescendantNodes query for entry node aggregate id "home" and filter '{"propertyValue": "stringProperty = true"}' I expect no nodes to be returned # Features/NodeTraversal/DescendantNodes.feature:112
        findDescendantNodes returned an unexpected result
        Failed asserting that two arrays are equal.
        --- Expected
        +++ Actual
        @@ @@
         Array (
        +    0 => 'b'
        +    1 => 'b1'
         )

The inline doc also specifically denotes that strict comparison should be used

The following should not return node "b1" because boolean true !== "true"

Testrunner: #4898

return static::matchesPropertyCollection($node->properties, $propertyValueCriteria);
}

public static function matchesPropertyCollection(PropertyCollection $propertyCollection, PropertyValueCriteriaInterface $propertyValueCriteria): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like to propose to use here as first parameter the serialised node properties directly. Using the higher level object is not necessary and might even introduce bugs as the matching should only happen on the serialised properties. Also it will be easier to test.

A last testrun is now triggered at #4898 but i assume everything will be green and youll get my approval :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is an actual benefit. In which usecase would one have serialized properties but not the propertyCollection.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduded matchesSerializedPropertyValues as separate method that is used by matchNode and matchPropertyCollection

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thänks. My reasoning here was just simply that when developing i came mostly across the SerializedPropertyValues and not the abstraction of the PropertyCollection which is not always available and harder to construct as it needs the serialiser. Also by passing in the serialised properties it becomes more obvious that the filtering happens on that level..

@mhsdesign
Copy link
Member

mhsdesign commented Feb 23, 2024

Tests at #4898 pass :D So its now basically a 1 to 1 implementation as far as the e2e testsuite says :)

mficzel and others added 2 commits February 24, 2024 19:52
`matchesNode` and `matchesPropertyCollection` internally use this method
…pertyConverter`

The `NodeSubjectProvider` will change in the future.
Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the adjustments and fixing everything.

@ahaeslich ahaeslich merged commit ffa0c00 into neos:9.0 Mar 11, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants