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

Extract Empty/Script/Missing ValuesSource behavior to an interface #48320

Merged

Conversation

not-napoleon
Copy link
Member

As part of the extensible values source work, this PR extracts some of the hard-coded ValuesSource types from ValuesSourceConfig.

Related to #42949

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

@polyfractal polyfractal self-requested a review October 30, 2019 15:10
@talevy talevy self-requested a review October 30, 2019 15:10
@not-napoleon not-napoleon changed the base branch from feature/extensible-values-source to master October 31, 2019 20:15
Copy link
Contributor

@polyfractal polyfractal left a comment

Choose a reason for hiding this comment

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

Left some comments/small changes. I like this, feels good to extract some of the config resolution to a different class. That thing is too hard to read today!

@Override
public ValuesSource getEmpty() {
// TODO: Implement this or get rid of ANY
throw new UnsupportedOperationException("ValuesSourceType.ANY is still a special case");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be BuiltinValuesSourceType.ANY right?

Not sure about the error message, but don't have a better suggestion at the moment :/

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this was my main hesitation on merging this to master. ANY is still handled in the "old style" with special cases scattered through ValuesSourceConfig. I'm pretty sure we'll never hit this error message, but given the complexity it's hard to be absolutely sure.

public ValuesSource getField(FieldContext fieldContext, AggregationScript.LeafFactory script) {
final IndexFieldData<?> indexFieldData = fieldContext.indexFieldData();
ValuesSource dataSource;
if (indexFieldData instanceof IndexOrdinalsFieldData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not important right now, but I wonder if we should try to encode some of these attributes with properties instead, in a future iteration? hasOrdinals(), isNumeric(), isRange() (or hasHistogram() in reference to Ignacio's PR) etc, that way we can avoid doing instanceof checks?

Might not be worth it, just a thought since instanceof's always sorta make me uneasy :) And it might make things more pluggable in the future since we won't have hardcoded classes in Core, just attributes

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'm +1 on this, but it seems out of scope for this PR. I can open an issue for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

#48864 opened to track this


@Override
public ValuesSource getScript(AggregationScript.LeafFactory script, ValueType scriptValueType) {
throw new AggregationExecutionException("value source of type [" + this.value() + "] is not supported by scripts");
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should make this exception the same as the other getFoo() methods, whatever we decide to keep it consistent?

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above. Changing exception types in this PR is too many moving parts IMHO.

@@ -307,7 +367,7 @@ public boolean needsScores() {

@Override
public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOException {
return new ValuesSource.WithScript.BytesValues(delegate.bytesValues(context), script.newInstance(context));
return new Bytes.WithScript.BytesValues(delegate.bytesValues(context), script.newInstance(context));
Copy link
Member Author

Choose a reason for hiding this comment

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

@polyfractal As per above comment, this is one of the rough edges. We're in a Numeric subclass, but we have this bytesValues method which calls into a different subclass now. I'm just guessing, but I suspect this is why WithScript wasn't a Bytes subclass originally.

@not-napoleon
Copy link
Member Author

@elasticmachine run elasticsearch-ci/2

Copy link
Contributor

@polyfractal polyfractal left a comment

Choose a reason for hiding this comment

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

I think I do like Tal's suggestion for "Core" instead of "Builtin". Otherwise LGTM!

@not-napoleon
Copy link
Member Author

@elasticmachine run elasticsearch-ci/packaging-sample-matrix

not-napoleon added a commit to not-napoleon/elasticsearch that referenced this pull request Nov 19, 2019
…nterface (elastic#48320)

This is a pure code rearrangement refactor.  Logic for what specific ValuesSource instance to use for a given type (e.g. script or field) moved out of ValuesSourceConfig and into CoreValuesSourceType (previously just ValueSourceType; we extract an interface for future extensibility).  ValueSourceConfig still selects which case to use, and then the ValuesSourceType instance knows how to construct the ValuesSource for that case.
 Conflicts:
	server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java
	server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregationBuilder.java
	x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/cumulativecardinality/CumulativeCardinalityAggregatorTests.java
not-napoleon added a commit that referenced this pull request Nov 19, 2019
…nterface (#48320) (#49330)

This is a pure code rearrangement refactor.  Logic for what specific ValuesSource instance to use for a given type (e.g. script or field) moved out of ValuesSourceConfig and into CoreValuesSourceType (previously just ValueSourceType; we extract an interface for future extensibility).  ValueSourceConfig still selects which case to use, and then the ValuesSourceType instance knows how to construct the ValuesSource for that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants