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

SCRIPTING: Move Aggregation Script Context to its own class #33820

Merged

Conversation

original-brownbear
Copy link
Member

WIP

@original-brownbear original-brownbear added >non-issue WIP :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v7.0.0 v6.5.0 labels Sep 18, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

I know this is a WIP, but I left a few comments for general direction I think we should take this.

}

/** Return the score of the current document. */
public double getScore() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should have score accessible as score and _score?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I was going to ask you, but yea I think score can go away here right?

* <p>
* @param value per-document value, typically a String, Long, or Double
*/
public void setNextAggregationValue(Object value) {
Copy link
Member

Choose a reason for hiding this comment

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

At minimum this should be typed (we should have separate script classes for each underlying doc values type), but I would much rather this be built into the script itself, so instead of setting the value, an iterate type call is made, similar to the doc values api.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rjernst as it turns out this isn't so trivial :(

Determining the exact type of the script upstream would require a lot of refactoring starting with org.elasticsearch.search.aggregations.support.ValuesSourceConfig (did some initial cleanups towards that in #34323).
Maybe we should do that in a next step?

/**
* Return the result as a long. This is used by aggregation scripts over long fields.
*/
public long runAsLong() {
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need these methods if we make typed versions of scripts, where execute would then return the correct type. Additionally, don't we always return double for all numeric fields (ie runAsLong isn't actually used)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used in: org.elasticsearch.search.aggregations.support.ValuesSource.Numeric.WithScript.LongValues.
but you're right typed versions of this context should be possible, will try tomorrow :)


public AggregationScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) {
this.params = new ParameterMap(new HashMap<>(params), DEPRECATIONS);
this.leafLookup = lookup.getLeafSearchLookup(leafContext);
Copy link
Member

Choose a reason for hiding this comment

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

I didn't think doc or _score works in value aggregation scripts? Looking at the user of this, I don't see where setDocument is called.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know about the score (though a scorer is set for this script in e.g org.elasticsearch.search.aggregations.support.values.ScriptBytesValues#setScorer) but the document is set in many places like org.elasticsearch.search.aggregations.support.values.ScriptLongValues#advanceExact

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I see the calls to setDocument now. It still looks like the scorer is not set anywhere, but it also looks quite deceptive so I fear there is something more complex going on.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

I agree this at least helps us get rid of SearchScript uses, so let's get this in with the generic Object return values and such, and then work on refactoring to have both typed and value/non-value specific versions (I still think _value scripts should not provide _score or doc). LGTM.

@original-brownbear
Copy link
Member Author

@rjernst thanks, I'll still have to fix the expression case here but that should be pretty quick+easy. Will try to hurry that up :)

@original-brownbear
Copy link
Member Author

@rjernst alright enabled expressions here too the same way I did it for the terms set script. See if you're still ok with it ? :)

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

this.params.putAll(leafLookup.asMap());
}

protected AggregationScript() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this empty ctor needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

@rjernst like in the terms set case (same code there) this is used by expressions because they don't use the leaf lookup (just to avoid the null checks and logic in the constructor).

@original-brownbear original-brownbear merged commit ebca273 into elastic:master Oct 15, 2018
@original-brownbear original-brownbear deleted the replace-aggs-context branch October 15, 2018 16:28
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Oct 15, 2018
* master:
  Do not update number of replicas on no indices (elastic#34481)
  Core: Remove two methods from AbstractComponent (elastic#34336)
  Use RoleRetrievalResult for better caching (elastic#34197)
  Revert "Search: Fix spelling mistake in Javadoc (elastic#34480)"
  Search: Fix spelling mistake in Javadoc (elastic#34480)
  Docs: improve formatting of Query String Query doc page (elastic#34432)
  Tests: Handle epoch date formatters edge cases (elastic#34437)
  Test: Fix running with external cluster
  Fix handling of empty keyword in terms aggregation (elastic#34457)
  [DOCS] Fix tag in SecurityDocumentationIT
  [Monitoring] Add additional necessary mappings for apm-server (elastic#34392)
  SCRIPTING: Move Aggregation Script Context to its own class (elastic#33820)
  MINOR: Remove Deadcode in  ExpressionTermSetQuery (elastic#34442)
  HLRC: Get SSL Certificates API (elastic#34135)
kcm pushed a commit that referenced this pull request Oct 30, 2018
* SCRIPTING: Move Aggregation Script Context to its own class
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 >non-issue v6.5.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants