-
Notifications
You must be signed in to change notification settings - Fork 19
[query] Full support for manipulating multivalue properties #90
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
Conversation
Depends on https://github.com/phpcr/phpcr-utils/pull/121/files |
//cc @dbu |
nice one! how exactly do the first examples work? do they replace Trains, or all tags? (i would expect to replace all). and setting an index to NULL removes the value from the list, right? i think you can't store null as a value. and |
i was wondering if using an absolute index as you do is valid. from reading i think it is: however, i can't really think of a good use case for that. what is much more likely is that i want to replace the value i search for with something new. would there be a way to do either a complete string replacement or even a regex pattern replace that would apply to the specific value in the list? (i am thinking of things like: update all |
I think the use case for the index thing would be very specific but the use case for the If you specify |
And the node at "/cms/articles/article1" should have the property "tags" with value "Rockets" at index "0" | ||
And the node at "/cms/articles/article1" should have the property "tags" with value "Dragons" at index "1" | ||
|
||
Scenario: Update single multivalue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as Replace a multivalie index by value
Ah cool, sounds useful. What happens if i do "where a.tags = 'a' and a.tags = 'b'"? Should we not allow the replace syntax in that case? Or come up with something like regexp do for match groups? |
Hmm, actually now you say that I am unsure about this syntax for replacing values, we are mixing the two sides of the query. Maybe something like:
This is pushing the syntax a bit of course -- are there any precedents for this type of thing in other languages? |
i am -1 on the second option, because it looks like "Planes" would be the index in a hashmap, while it is actually a value. the [[ look a bit weird. i think the |
See discussion: #81 |
Updated to use functions. |
Note it would be good to also implement functions like The problem is that while we could implement them the SELECT statement Using functions in SELECT could also be a good strategy for retrieving the node path and score, e.g. |
2e0a0e2
to
c60428f
Compare
// 'name' => 'tags', | ||
// 'value' => new FunctionOperand(new ColumnOperand('a', 'tags'), array('asd', 'dsa')), | ||
// ), | ||
// )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically yes. but I can't find a way to make the assertion work without refactoring the code .. maybe that wouldn't be such a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this test in the end. This is one of the things I don't like about PHPSpec, its not that flexible.
do you have open questions or is this ready? functions for select statements are in conflict with staying compatible with jcr, and they would not work with jackalope-jackrabbit as we need to run the search on the server. |
I think it needs a cleanup :) Functions would never be used with the SELECT, only with UPDATE. |
c60428f
to
8e013c3
Compare
8e013c3
to
a42c2e2
Compare
Updated. Will merge it later. |
Hmm. Updated the description of this PR, I have now removed the |
783fa22
to
c77d386
Compare
array_shift($values); | ||
return $values; | ||
}, | ||
'array_set' => function ($operand, $current, $index, $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if array_set is a good name, i.e.
SET a.tags = array_set(a.tags, 'foo', 'bar');
Maybe:
array_replace_index(a.tags, 0, 'foo')
Would make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also use array_replace in both cases, and if its an int its the index, if its a string its the value to replace. hm, sounds really confusing though when you accidentally pass a number as string...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think we should keep setting indexes to values and replacing values with values should remain as separate functions.
c77d386
to
9d9e560
Compare
using |
ping @dbu - what do you think? arrays are now set with a function ( |
[query] Full support for manipulating multivalue properties
Merged. I think the function name and syntax are OK. |
# Delete a multivalue index | ||
UPDATE [nt:unstructured] SET a.tags = array_set(a.tags, 0, NULL) | ||
|
||
# Set a multivalue index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this be overwriting or insert at that position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overwriting
sorry, only found the time to review now. i would suggest these names:
|
I was probably a bit to hasty in merging as the tests are now failing, will have another look, |
indeed, so i would call it |
Adds support for updating multivalue properties with the UPDATE query:
UPDATE: This PR now includes support for evaluating functions as values over the previous syntax for updating multivalues properties. Currently only array functions are implemented.UPDATE: This PR now uses functions exclusively for setting and manipulating array valyes.
The functions are based on the Postgres array functions.
Other functions:
See also documentation: phpcr/phpcr-docs#17