Skip to content

Add synthetic length property as alias to Lists, so they can be used like arrays#18241

Merged
jdconrad merged 1 commit intoelastic:masterfrom
uschindler:painless_list_length
May 10, 2016
Merged

Add synthetic length property as alias to Lists, so they can be used like arrays#18241
jdconrad merged 1 commit intoelastic:masterfrom
uschindler:painless_list_length

Conversation

@uschindler
Copy link
Copy Markdown
Contributor

@uschindler uschindler commented May 10, 2016

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 for loop using array.length to using a List. The loads/stores worked, but Lists don't have a lengthproperty. 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>, and List<String>. Then the property works automatically.

@rmuir
Copy link
Copy Markdown
Contributor

rmuir commented May 10, 2016

+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

@uschindler
Copy link
Copy Markdown
Contributor Author

the javascript plugin even has a rest test for this

I won't write integration tests :-)

@rmuir
Copy link
Copy Markdown
Contributor

rmuir commented May 10, 2016

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.

@jdconrad
Copy link
Copy Markdown
Contributor

@uschindler Thanks! This is a good change.

@jdconrad jdconrad merged commit 06a4f64 into elastic:master May 10, 2016
@jdconrad jdconrad self-assigned this May 10, 2016
@uschindler uschindler deleted the painless_list_length branch May 10, 2016 16:40
@clintongormley clintongormley changed the title painless: Add synthetic length property as alias to Lists, so they can be used like arrays Add synthetic length property as alias to Lists, so they can be used like arrays May 17, 2016
@uschindler uschindler mentioned this pull request May 19, 2016
18 tasks
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Plugin Lang Painless labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement v5.0.0-alpha3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants