Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Jan 6, 2020

We very commonly have object with ctors like:

public Foo(String name)

And then declare a bunch of setters on the object. Every aggregation
works like this, for example. This change teaches ObjectParser how to
build these aggregations all on its own, without any help. This'll make
it much cleaner to parse aggs, and, probably, a bunch of other things.
It'll let us remove lots of wrapping. I've used this new power for the
avg aggregation just to prove that it works outside of a unit test.

We *very* commonly have object with ctors like:
```
public Foo(String name)
```

And then declare a bunch of setters on the object. Every aggregation
works like this, for example. This change teaches `ObjectParser` how to
build these aggregations all on its own, without any help. This'll make
it much cleaner to parse aggs, and, probably, a bunch of other things.
It'll let us remove lots of wrapping. I've used this new power for the
`avg` aggregation just to prove that it works outside of a unit test.
@nik9000 nik9000 added >non-issue :Core/Infra/Core Core issues without another label v8.0.0 v7.6.0 labels Jan 6, 2020
@nik9000 nik9000 requested review from romseygeek and talevy January 6, 2020 23:10
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Core)


public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException {
return PARSER.parse(parser, new AvgAggregationBuilder(aggregationName), null);
return PARSER.parse(parser, aggregationName);
Copy link
Member Author

Choose a reason for hiding this comment

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

From here the payoff doesn't look that good, but we can remove the parses method entirely in a follow-up and call the parser directly. We can't do it right now because the order of the arguments is backwards.

private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");

private static final ObjectParser<InnerBuilder, Void> QUERY_RESCORE_PARSER = new ObjectParser<>(NAME, null);
private static final ObjectParser<InnerBuilder, Void> QUERY_RESCORE_PARSER = new ObjectParser<>(NAME);
Copy link
Member Author

Choose a reason for hiding this comment

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

All of these are because it couldn't compile now that there are two methods that take two args. It is better not to have the null anyway.

assertThat(ex.getMessage(), containsString("[foo] failed to parse field [int_array]"));
}

private static final Supplier<AtomicReference<String>> NEW_EMPTY_STRING_REF = AtomicReference::new;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is because there are two ctors on atomic reference. One that looks like a function and one that looks like a supplier. The compiler was confused when I passed ::new to the ctor.

Copy link
Contributor

@romseygeek romseygeek 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 will make a whole bunch of stuff much cleaner.

@nik9000
Copy link
Member Author

nik9000 commented Jan 7, 2020

Oh neat! These compile failures don't show up in Eclipse.

@nik9000
Copy link
Member Author

nik9000 commented Jan 7, 2020

Oh neat! These compile failures don't show up in Eclipse.

OK! I have a solution. A static method instead of a ctor. Testing locally.

This is really a place where the builder pattern could be nice, but we've historically not liked it so I'm not using it.

@nik9000 nik9000 merged commit 792b5e1 into elastic:master Jan 7, 2020
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Jan 7, 2020
We *very* commonly have object with ctors like:
```
public Foo(String name)
```

And then declare a bunch of setters on the object. Every aggregation
works like this, for example. This change teaches `ObjectParser` how to
build these aggregations all on its own, without any help. This'll make
it much cleaner to parse aggs, and, probably, a bunch of other things.
It'll let us remove lots of wrapping. I've used this new power for the
`avg` aggregation just to prove that it works outside of a unit test.
nik9000 added a commit that referenced this pull request Jan 7, 2020
We *very* commonly have object with ctors like:
```
public Foo(String name)
```

And then declare a bunch of setters on the object. Every aggregation
works like this, for example. This change teaches `ObjectParser` how to
build these aggregations all on its own, without any help. This'll make
it much cleaner to parse aggs, and, probably, a bunch of other things.
It'll let us remove lots of wrapping. I've used this new power for the
`avg` aggregation just to prove that it works outside of a unit test.
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
We *very* commonly have object with ctors like:
```
public Foo(String name)
```

And then declare a bunch of setters on the object. Every aggregation
works like this, for example. This change teaches `ObjectParser` how to
build these aggregations all on its own, without any help. This'll make
it much cleaner to parse aggs, and, probably, a bunch of other things.
It'll let us remove lots of wrapping. I've used this new power for the
`avg` aggregation just to prove that it works outside of a unit test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants