Skip to content

Commit ab174a8

Browse files
committed
[ML][Data Frame] removing format support (elastic#43659)
1 parent 74dd6e4 commit ab174a8

File tree

9 files changed

+43
-85
lines changed

9 files changed

+43
-85
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/transforms/pivot/DateHistogramGroupSource.java

+5-30
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
public class DateHistogramGroupSource extends SingleGroupSource implements ToXContentObject {
4646

4747
private static final ParseField TIME_ZONE = new ParseField("time_zone");
48-
private static final ParseField FORMAT = new ParseField("format");
4948

5049
// From DateHistogramAggregationBuilder in core, transplanted and modified to a set
5150
// so we don't need to import a dependency on the class
@@ -195,8 +194,7 @@ public int hashCode() {
195194
}
196195

197196
ZoneId zoneId = (ZoneId) args[3];
198-
String format = (String) args[4];
199-
return new DateHistogramGroupSource(field, interval, format, zoneId);
197+
return new DateHistogramGroupSource(field, interval, zoneId);
200198
});
201199

202200
static {
@@ -212,22 +210,18 @@ public int hashCode() {
212210
return ZoneOffset.ofHours(p.intValue());
213211
}
214212
}, TIME_ZONE, ObjectParser.ValueType.LONG);
215-
216-
PARSER.declareString(optionalConstructorArg(), FORMAT);
217213
}
218214

219215
public static DateHistogramGroupSource fromXContent(final XContentParser parser) {
220216
return PARSER.apply(parser, null);
221217
}
222218

223219
private final Interval interval;
224-
private final String format;
225220
private final ZoneId timeZone;
226221

227-
DateHistogramGroupSource(String field, Interval interval, String format, ZoneId timeZone) {
222+
DateHistogramGroupSource(String field, Interval interval, ZoneId timeZone) {
228223
super(field);
229224
this.interval = interval;
230-
this.format = format;
231225
this.timeZone = timeZone;
232226
}
233227

@@ -240,10 +234,6 @@ public Interval getInterval() {
240234
return interval;
241235
}
242236

243-
public String getFormat() {
244-
return format;
245-
}
246-
247237
public ZoneId getTimeZone() {
248238
return timeZone;
249239
}
@@ -258,9 +248,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
258248
if (timeZone != null) {
259249
builder.field(TIME_ZONE.getPreferredName(), timeZone.toString());
260250
}
261-
if (format != null) {
262-
builder.field(FORMAT.getPreferredName(), format);
263-
}
264251
builder.endObject();
265252
return builder;
266253
}
@@ -279,13 +266,12 @@ public boolean equals(Object other) {
279266

280267
return Objects.equals(this.field, that.field) &&
281268
Objects.equals(this.interval, that.interval) &&
282-
Objects.equals(this.timeZone, that.timeZone) &&
283-
Objects.equals(this.format, that.format);
269+
Objects.equals(this.timeZone, that.timeZone);
284270
}
285271

286272
@Override
287273
public int hashCode() {
288-
return Objects.hash(field, interval, timeZone, format);
274+
return Objects.hash(field, interval, timeZone);
289275
}
290276

291277
public static Builder builder() {
@@ -296,7 +282,6 @@ public static class Builder {
296282

297283
private String field;
298284
private Interval interval;
299-
private String format;
300285
private ZoneId timeZone;
301286

302287
/**
@@ -319,16 +304,6 @@ public Builder setInterval(Interval interval) {
319304
return this;
320305
}
321306

322-
/**
323-
* Set the optional String formatting for the time interval.
324-
* @param format The format of the output for the time interval key
325-
* @return The {@link Builder} with the format set.
326-
*/
327-
public Builder setFormat(String format) {
328-
this.format = format;
329-
return this;
330-
}
331-
332307
/**
333308
* Sets the time zone to use for this aggregation
334309
* @param timeZone The zoneId for the timeZone
@@ -340,7 +315,7 @@ public Builder setTimeZone(ZoneId timeZone) {
340315
}
341316

342317
public DateHistogramGroupSource build() {
343-
return new DateHistogramGroupSource(field, interval, format, timeZone);
318+
return new DateHistogramGroupSource(field, interval, timeZone);
344319
}
345320
}
346321
}

client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/pivot/DateHistogramGroupSourceTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static DateHistogramGroupSource randomDateHistogramGroupSource() {
3939
String field = randomAlphaOfLengthBetween(1, 20);
4040
return new DateHistogramGroupSource(field,
4141
randomDateHistogramInterval(),
42-
randomBoolean() ? randomAlphaOfLength(10) : null,
4342
randomBoolean() ? randomZone() : null);
4443
}
4544

client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/pivot/hlrc/DateHistogramGroupSourceTests.java

-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public static DateHistogramGroupSource randomDateHistogramGroupSource() {
4444
if (randomBoolean()) {
4545
dateHistogramGroupSource.setTimeZone(randomZone());
4646
}
47-
if (randomBoolean()) {
48-
dateHistogramGroupSource.setFormat(randomAlphaOfLength(10));
49-
}
5047
return dateHistogramGroupSource;
5148
}
5249

@@ -64,7 +61,6 @@ protected org.elasticsearch.client.dataframe.transforms.pivot.DateHistogramGroup
6461
protected void assertInstances(DateHistogramGroupSource serverTestInstance,
6562
org.elasticsearch.client.dataframe.transforms.pivot.DateHistogramGroupSource clientInstance) {
6663
assertThat(serverTestInstance.getField(), equalTo(clientInstance.getField()));
67-
assertThat(serverTestInstance.getFormat(), equalTo(clientInstance.getFormat()));
6864
assertSameInterval(serverTestInstance.getInterval(), clientInstance.getInterval());
6965
assertThat(serverTestInstance.getTimeZone(), equalTo(clientInstance.getTimeZone()));
7066
assertThat(serverTestInstance.getType().name(), equalTo(clientInstance.getType().name()));

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/pivot/DateHistogramGroupSource.java

+11-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.core.dataframe.transforms.pivot;
77

8+
import org.elasticsearch.Version;
89
import org.elasticsearch.common.ParseField;
910
import org.elasticsearch.common.io.stream.StreamInput;
1011
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -187,13 +188,11 @@ private void writeInterval(Interval interval, StreamOutput out) throws IOExcepti
187188

188189
private static final String NAME = "data_frame_date_histogram_group";
189190
private static final ParseField TIME_ZONE = new ParseField("time_zone");
190-
private static final ParseField FORMAT = new ParseField("format");
191191

192192
private static final ConstructingObjectParser<DateHistogramGroupSource, Void> STRICT_PARSER = createParser(false);
193193
private static final ConstructingObjectParser<DateHistogramGroupSource, Void> LENIENT_PARSER = createParser(true);
194194

195195
private final Interval interval;
196-
private String format;
197196
private ZoneId timeZone;
198197

199198
public DateHistogramGroupSource(String field, Interval interval) {
@@ -205,7 +204,10 @@ public DateHistogramGroupSource(StreamInput in) throws IOException {
205204
super(in);
206205
this.interval = readInterval(in);
207206
this.timeZone = in.readOptionalZoneId();
208-
this.format = in.readOptionalString();
207+
// Format was optional in 7.2.x, removed in 7.3+
208+
if (in.getVersion().before(Version.V_7_3_0)) {
209+
in.readOptionalString();
210+
}
209211
}
210212

211213
private static ConstructingObjectParser<DateHistogramGroupSource, Void> createParser(boolean lenient) {
@@ -242,7 +244,6 @@ private static ConstructingObjectParser<DateHistogramGroupSource, Void> createPa
242244
}
243245
}, TIME_ZONE, ObjectParser.ValueType.LONG);
244246

245-
parser.declareString(DateHistogramGroupSource::setFormat, FORMAT);
246247
return parser;
247248
}
248249

@@ -259,14 +260,6 @@ public Interval getInterval() {
259260
return interval;
260261
}
261262

262-
public String getFormat() {
263-
return format;
264-
}
265-
266-
public void setFormat(String format) {
267-
this.format = format;
268-
}
269-
270263
public ZoneId getTimeZone() {
271264
return timeZone;
272265
}
@@ -280,7 +273,10 @@ public void writeTo(StreamOutput out) throws IOException {
280273
out.writeOptionalString(field);
281274
writeInterval(interval, out);
282275
out.writeOptionalZoneId(timeZone);
283-
out.writeOptionalString(format);
276+
// Format was optional in 7.2.x, removed in 7.3+
277+
if (out.getVersion().before(Version.V_7_3_0)) {
278+
out.writeOptionalString(null);
279+
}
284280
}
285281

286282
@Override
@@ -293,9 +289,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
293289
if (timeZone != null) {
294290
builder.field(TIME_ZONE.getPreferredName(), timeZone.toString());
295291
}
296-
if (format != null) {
297-
builder.field(FORMAT.getPreferredName(), format);
298-
}
299292
builder.endObject();
300293
return builder;
301294
}
@@ -314,13 +307,12 @@ public boolean equals(Object other) {
314307

315308
return Objects.equals(this.field, that.field) &&
316309
Objects.equals(interval, that.interval) &&
317-
Objects.equals(timeZone, that.timeZone) &&
318-
Objects.equals(format, that.format);
310+
Objects.equals(timeZone, that.timeZone);
319311
}
320312

321313
@Override
322314
public int hashCode() {
323-
return Objects.hash(field, interval, timeZone, format);
315+
return Objects.hash(field, interval, timeZone);
324316
}
325317

326318
@Override

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/pivot/DateHistogramGroupSourceTests.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
package org.elasticsearch.xpack.core.dataframe.transforms.pivot;
88

9+
import org.elasticsearch.Version;
10+
import org.elasticsearch.common.io.stream.BytesStreamOutput;
11+
import org.elasticsearch.common.io.stream.StreamInput;
912
import org.elasticsearch.common.io.stream.Writeable.Reader;
1013
import org.elasticsearch.common.xcontent.XContentParser;
1114
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
@@ -29,12 +32,22 @@ public static DateHistogramGroupSource randomDateHistogramGroupSource() {
2932
if (randomBoolean()) {
3033
dateHistogramGroupSource.setTimeZone(randomZone());
3134
}
32-
if (randomBoolean()) {
33-
dateHistogramGroupSource.setFormat(randomAlphaOfLength(10));
34-
}
3535
return dateHistogramGroupSource;
3636
}
3737

38+
public void testBackwardsSerialization() throws IOException {
39+
DateHistogramGroupSource groupSource = randomDateHistogramGroupSource();
40+
try (BytesStreamOutput output = new BytesStreamOutput()) {
41+
output.setVersion(Version.V_7_2_0);
42+
groupSource.writeTo(output);
43+
try (StreamInput in = output.bytes().streamInput()) {
44+
in.setVersion(Version.V_7_2_0);
45+
DateHistogramGroupSource streamedGroupSource = new DateHistogramGroupSource(in);
46+
assertEquals(groupSource, streamedGroupSource);
47+
}
48+
}
49+
}
50+
3851
@Override
3952
protected DateHistogramGroupSource doParseInstance(XContentParser parser) throws IOException {
4053
return DateHistogramGroupSource.fromXContent(parser, false);

x-pack/plugin/data-frame/qa/multi-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameIntegTestCase.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,21 @@ protected void waitUntilCheckpoint(String id, long checkpoint, TimeValue waitTim
143143

144144
protected DateHistogramGroupSource createDateHistogramGroupSourceWithFixedInterval(String field,
145145
DateHistogramInterval interval,
146-
ZoneId zone,
147-
String format) {
146+
ZoneId zone) {
148147
DateHistogramGroupSource.Builder builder = DateHistogramGroupSource.builder()
149148
.setField(field)
150149
.setInterval(new DateHistogramGroupSource.FixedInterval(interval))
151-
.setTimeZone(zone)
152-
.setFormat(format);
150+
.setTimeZone(zone);
153151
return builder.build();
154152
}
155153

156154
protected DateHistogramGroupSource createDateHistogramGroupSourceWithCalendarInterval(String field,
157155
DateHistogramInterval interval,
158-
ZoneId zone,
159-
String format) {
156+
ZoneId zone) {
160157
DateHistogramGroupSource.Builder builder = DateHistogramGroupSource.builder()
161158
.setField(field)
162159
.setInterval(new DateHistogramGroupSource.CalendarInterval(interval))
163-
.setTimeZone(zone)
164-
.setFormat(format);
160+
.setTimeZone(zone);
165161
return builder.build();
166162
}
167163

x-pack/plugin/data-frame/qa/multi-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameTransformIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testDataFrameTransformCrud() throws Exception {
4545
createReviewsIndex(indexName, 100);
4646

4747
Map<String, SingleGroupSource> groups = new HashMap<>();
48-
groups.put("by-day", createDateHistogramGroupSourceWithCalendarInterval("timestamp", DateHistogramInterval.DAY, null, null));
48+
groups.put("by-day", createDateHistogramGroupSourceWithCalendarInterval("timestamp", DateHistogramInterval.DAY, null));
4949
groups.put("by-user", TermsGroupSource.builder().setField("user_id").build());
5050
groups.put("by-business", TermsGroupSource.builder().setField("business_id").build());
5151

@@ -82,7 +82,7 @@ public void testContinuousDataFrameTransformCrud() throws Exception {
8282
createReviewsIndex(indexName, 100);
8383

8484
Map<String, SingleGroupSource> groups = new HashMap<>();
85-
groups.put("by-day", createDateHistogramGroupSourceWithCalendarInterval("timestamp", DateHistogramInterval.DAY, null, null));
85+
groups.put("by-day", createDateHistogramGroupSourceWithCalendarInterval("timestamp", DateHistogramInterval.DAY, null));
8686
groups.put("by-user", TermsGroupSource.builder().setField("user_id").build());
8787
groups.put("by-business", TermsGroupSource.builder().setField("business_id").build());
8888

x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFramePivotRestIT.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void testDateHistogramPivot() throws Exception {
373373
+ " \"group_by\": {"
374374
+ " \"by_hr\": {"
375375
+ " \"date_histogram\": {"
376-
+ " \"fixed_interval\": \"1h\",\"field\":\"timestamp\",\"format\":\"yyyy-MM-dd_HH\""
376+
+ " \"fixed_interval\": \"1h\",\"field\":\"timestamp\""
377377
+ " } } },"
378378
+ " \"aggregations\": {"
379379
+ " \"avg_rating\": {"
@@ -407,7 +407,7 @@ public void testPreviewTransform() throws Exception {
407407
config += " \"pivot\": {"
408408
+ " \"group_by\": {"
409409
+ " \"user.id\": {\"terms\": { \"field\": \"user_id\" }},"
410-
+ " \"by_day\": {\"date_histogram\": {\"fixed_interval\": \"1d\",\"field\":\"timestamp\",\"format\":\"yyyy-MM-dd\"}}},"
410+
+ " \"by_day\": {\"date_histogram\": {\"fixed_interval\": \"1d\",\"field\":\"timestamp\"}}},"
411411
+ " \"aggregations\": {"
412412
+ " \"user.avg_rating\": {"
413413
+ " \"avg\": {"
@@ -457,7 +457,7 @@ public void testPreviewTransformWithPipeline() throws Exception {
457457
+ " \"pivot\": {"
458458
+ " \"group_by\": {"
459459
+ " \"user.id\": {\"terms\": { \"field\": \"user_id\" }},"
460-
+ " \"by_day\": {\"date_histogram\": {\"fixed_interval\": \"1d\",\"field\":\"timestamp\",\"format\":\"yyyy-MM-dd\"}}},"
460+
+ " \"by_day\": {\"date_histogram\": {\"fixed_interval\": \"1d\",\"field\":\"timestamp\"}}},"
461461
+ " \"aggregations\": {"
462462
+ " \"user.avg_rating\": {"
463463
+ " \"avg\": {"
@@ -497,7 +497,7 @@ public void testPivotWithMaxOnDateField() throws Exception {
497497
config +=" \"pivot\": { \n" +
498498
" \"group_by\": {\n" +
499499
" \"by_day\": {\"date_histogram\": {\n" +
500-
" \"fixed_interval\": \"1d\",\"field\":\"timestamp\",\"format\":\"yyyy-MM-dd\"\n" +
500+
" \"fixed_interval\": \"1d\",\"field\":\"timestamp\"\n" +
501501
" }}\n" +
502502
" },\n" +
503503
" \n" +

0 commit comments

Comments
 (0)