-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Esql field attribute builder #127851
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
base: main
Are you sure you want to change the base?
Esql field attribute builder #127851
Conversation
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
|
|
||
| private static FieldAttribute intField() { | ||
| return new FieldAttribute(Source.EMPTY, "int", new EsField("int", DataType.INTEGER, Map.of(), true)); | ||
| return new FieldAttribute.FieldAttirbuteBuilder(Source.EMPTY, "int", new EsField("int", DataType.INTEGER, Map.of(), true)).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling.
Maybe should just be FieldAttribute.builder() or new FieldAttribute.Builder()?
…tribute-builder' into esql-field-attribute-builder
| protected PhysicalPlan rule(EsSourceExec plan) { | ||
| var docId = new FieldAttribute(plan.source(), EsQueryExec.DOC_ID_FIELD.getName(), EsQueryExec.DOC_ID_FIELD); | ||
| var docId = new FieldAttribute.FieldAttirbuteBuilder(plan.source(), EsQueryExec.DOC_ID_FIELD.getName(), EsQueryExec.DOC_ID_FIELD) | ||
| .build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several cases when the builder is used like here: Builder(...).build() without extra chain calls.
I wonder if it is possible to still keep a constructor with such signature? This will reduce amount of objects created in prod code (not sure if escape analysis proactively eliminates them).
I also wonder if we could achieve similar level of simplification if we:
-
remove constructors with fewer usages ans supply extra arguments explicitly:
Lines 51 to 53 in e95397c
public FieldAttribute(Source source, @Nullable String parentName, String name, EsField field) { this(source, parentName, name, field, Nullability.TRUE, null, false); }
has 4 usages
Lines 55 to 57 in e95397c
public FieldAttribute(Source source, @Nullable String parentName, String name, EsField field, boolean synthetic) { this(source, parentName, name, field, Nullability.TRUE, null, synthetic); }
has only 1. -
Consider scope
Lines 47 to 49 in e95397c
public FieldAttribute(Source source, String name, EsField field) { this(source, null, name, field); }
this has a lot of usages and all but 4 are test ones. May be it is worth having a test utility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove constructors with fewer usages ans supply extra arguments explicitly
I was under the impression that FieldAttribute, being a sub-class of Node was meant to be immutable. I'm not opposed to adding some setters on it for these optional fields, but if immutability is important for these classes, that seems like a risky plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep it immutable. We certainly could just hard call the ctor every time if we're worried about the allocations, but I haven't been too worried about them in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove constructors with fewer usages and supply extra arguments explicitly
To be precise, supply default argument explicitly via constructor prior constructor was delegating to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote up what I think you're asking for in #127920. Personally, I like the builder better, but I'm open to feedback.
FieldAttribute had seven constructors. This PR removes three of them, and replaces them with a more readable builder pattern.