Add synthetic length property as alias to Lists, so they can be used like arrays#18241
Merged
jdconrad merged 1 commit intoelastic:masterfrom May 10, 2016
Merged
Conversation
…n really be used like arrays
Contributor
|
+1 good idea and simple to do. It is nice since values in documents are also List and recommended with array syntax. the javascript plugin even has a rest test for this: https://github.com/elastic/elasticsearch/blob/master/plugins/lang-javascript/src/test/resources/rest-api-spec/test/lang_javascript/20_search.yaml#L410 |
Contributor
Author
I won't write integration tests :-) |
Contributor
|
yes your test is the way to go here. i only looked at the other engines the other day to better round out our integration tests. Just trying to get an idea of what is missing, what is cumbersome, etc. |
Contributor
|
@uschindler Thanks! This is a good change. |
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While writing tests for the array loads and stores I noticed some inconsistency in painless:
Syntax-wise you can exchange Lists and arrays, e.g. access a List like an array (this also works with maps, but that is out of scope for this issue). I failed to transform a simple
forloop usingarray.lengthto using a List. The loads/stores worked, but Lists don't have alengthproperty. To really allow lists to be used as arrays, we must add the "length" property manually.The PR is simple: We need no change in the indy bootstrap part, a Definition is enough. The trick is to add an alias "getLength" to
List,List<Object>, andList<String>. Then the property works automatically.