-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[ML] data frame, adding builder classes for complex config classes #41638
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
Changes from 1 commit
f8d46ce
d5445e3
a365134
3cc3d36
40b3768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,4 +168,55 @@ public boolean equals(Object other) { | |
| public int hashCode() { | ||
| return Objects.hash(field, interval, dateHistogramInterval, timeZone, format); | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private String field; | ||
| private long interval = 0; | ||
| private DateHistogramInterval dateHistogramInterval; | ||
| private String format; | ||
| private ZoneId timeZone; | ||
|
|
||
| public Builder setField(String field) { | ||
| this.field = field; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setInterval(long interval) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this method accept "Duration" instead of "long"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to make this parallel the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, if we talk about usability here, it is usually error-prone if the user has to provide "long" but does not know what the unit is.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @przemekwitek I added some docs and a new method that accepts a |
||
| this.interval = interval; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setDateHistgramInterval(DateHistogramInterval interval) { | ||
| this.dateHistogramInterval = interval; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setFormat(String format) { | ||
| this.format = format; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setTimeZone(ZoneId timeZone) { | ||
| this.timeZone = timeZone; | ||
| return this; | ||
| } | ||
|
|
||
| public DateHistogramGroupSource build() { | ||
| DateHistogramGroupSource groupSource = new DateHistogramGroupSource(field); | ||
|
||
| if (dateHistogramInterval != null) { | ||
| groupSource.setDateHistogramInterval(dateHistogramInterval); | ||
| } | ||
| if (interval >= 1.0) { | ||
| groupSource.setInterval(interval); | ||
| } | ||
| groupSource.setFormat(format); | ||
| groupSource.setTimeZone(timeZone); | ||
| return groupSource; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import org.elasticsearch.common.xcontent.XContentParser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -174,4 +175,25 @@ public int hashCode() { | |
| public String toString() { | ||
| return Strings.toString(this, true, true); | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private final Map<String, SingleGroupSource> groups; | ||
|
|
||
| public Builder() { | ||
| this.groups = new HashMap<>(); | ||
|
||
| } | ||
|
|
||
| public Builder groupBy(String name, SingleGroupSource group) { | ||
| groups.put(name, group); | ||
| return this; | ||
| } | ||
|
|
||
| public GroupConfig build() { | ||
| return new GroupConfig(groups); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,4 +97,28 @@ public boolean equals(Object other) { | |
| public int hashCode() { | ||
| return Objects.hash(field, interval); | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, I cannot leave comment in the line 55. Anyway, leaving it here: Please make the constructor package-private |
||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private String field; | ||
| private double interval; | ||
|
|
||
| public Builder setField(String field) { | ||
| this.field = field; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setInterval(double interval) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question, should we use "Duration" here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that does not make sense here as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A, ok. So this was my misunderstanding (I associated "interval" with some time duration). |
||
| this.interval = interval; | ||
| return this; | ||
| } | ||
|
|
||
| public HistogramGroupSource build() { | ||
| return new HistogramGroupSource(field, interval); | ||
| } | ||
| } | ||
| } | ||
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.
Do you think it would make sense to make DataFrameTransformConfig constructor private now that we have "builder()" as a recommended entry point to this class? The same question for other classes...
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.
That is a good thought, How about "package private" so that tests can still utilize it?
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.
Package-private SGTM