@@ -34,12 +34,13 @@ public class SettingsConfig implements Writeable, ToXContentObject {
34
34
private static final int DEFAULT_MAX_PAGE_SEARCH_SIZE = -1 ;
35
35
private static final float DEFAULT_DOCS_PER_SECOND = -1F ;
36
36
private static final int DEFAULT_DATES_AS_EPOCH_MILLIS = -1 ;
37
+ private static final int DEFAULT_INTERIM_RESULTS = -1 ;
37
38
38
39
private static ConstructingObjectParser <SettingsConfig , Void > createParser (boolean lenient ) {
39
40
ConstructingObjectParser <SettingsConfig , Void > parser = new ConstructingObjectParser <>(
40
41
"transform_config_settings" ,
41
42
lenient ,
42
- args -> new SettingsConfig ((Integer ) args [0 ], (Float ) args [1 ], (Integer ) args [2 ])
43
+ args -> new SettingsConfig ((Integer ) args [0 ], (Float ) args [1 ], (Integer ) args [2 ], ( Integer ) args [ 3 ] )
43
44
);
44
45
parser .declareIntOrNull (optionalConstructorArg (), DEFAULT_MAX_PAGE_SEARCH_SIZE , TransformField .MAX_PAGE_SEARCH_SIZE );
45
46
parser .declareFloatOrNull (optionalConstructorArg (), DEFAULT_DOCS_PER_SECOND , TransformField .DOCS_PER_SECOND );
@@ -50,25 +51,39 @@ private static ConstructingObjectParser<SettingsConfig, Void> createParser(boole
50
51
TransformField .DATES_AS_EPOCH_MILLIS ,
51
52
ValueType .BOOLEAN_OR_NULL
52
53
);
54
+ // this boolean requires 4 possible values: true, false, not_specified, default, therefore using a custom parser
55
+ parser .declareField (
56
+ optionalConstructorArg (),
57
+ p -> p .currentToken () == XContentParser .Token .VALUE_NULL ? DEFAULT_INTERIM_RESULTS : p .booleanValue () ? 1 : 0 ,
58
+ TransformField .INTERIM_RESULTS ,
59
+ ValueType .BOOLEAN_OR_NULL
60
+ );
53
61
return parser ;
54
62
}
55
63
56
64
private final Integer maxPageSearchSize ;
57
65
private final Float docsPerSecond ;
58
66
private final Integer datesAsEpochMillis ;
67
+ private final Integer interimResults ;
59
68
60
69
public SettingsConfig () {
61
- this (null , null , (Integer ) null );
70
+ this (null , null , (Integer ) null , ( Integer ) null );
62
71
}
63
72
64
- public SettingsConfig (Integer maxPageSearchSize , Float docsPerSecond , Boolean datesAsEpochMillis ) {
65
- this (maxPageSearchSize , docsPerSecond , datesAsEpochMillis == null ? null : datesAsEpochMillis ? 1 : 0 );
73
+ public SettingsConfig (Integer maxPageSearchSize , Float docsPerSecond , Boolean datesAsEpochMillis , Boolean interimResults ) {
74
+ this (
75
+ maxPageSearchSize ,
76
+ docsPerSecond ,
77
+ datesAsEpochMillis == null ? null : datesAsEpochMillis ? 1 : 0 ,
78
+ interimResults == null ? null : interimResults ? 1 : 0
79
+ );
66
80
}
67
81
68
- public SettingsConfig (Integer maxPageSearchSize , Float docsPerSecond , Integer datesAsEpochMillis ) {
82
+ public SettingsConfig (Integer maxPageSearchSize , Float docsPerSecond , Integer datesAsEpochMillis , Integer interimResults ) {
69
83
this .maxPageSearchSize = maxPageSearchSize ;
70
84
this .docsPerSecond = docsPerSecond ;
71
85
this .datesAsEpochMillis = datesAsEpochMillis ;
86
+ this .interimResults = interimResults ;
72
87
}
73
88
74
89
public SettingsConfig (final StreamInput in ) throws IOException {
@@ -79,6 +94,11 @@ public SettingsConfig(final StreamInput in) throws IOException {
79
94
} else {
80
95
this .datesAsEpochMillis = DEFAULT_DATES_AS_EPOCH_MILLIS ;
81
96
}
97
+ if (in .getVersion ().onOrAfter (Version .CURRENT )) { // TODO: 7.15
98
+ this .interimResults = in .readOptionalInt ();
99
+ } else {
100
+ this .interimResults = DEFAULT_INTERIM_RESULTS ;
101
+ }
82
102
}
83
103
84
104
public Integer getMaxPageSearchSize () {
@@ -97,6 +117,14 @@ public Integer getDatesAsEpochMillisForUpdate() {
97
117
return datesAsEpochMillis ;
98
118
}
99
119
120
+ public Boolean getInterimResults () {
121
+ return interimResults != null ? interimResults > 0 : null ;
122
+ }
123
+
124
+ public Integer getInterimResultsForUpdate () {
125
+ return interimResults ;
126
+ }
127
+
100
128
public ActionRequestValidationException validate (ActionRequestValidationException validationException ) {
101
129
if (maxPageSearchSize != null && (maxPageSearchSize < 10 || maxPageSearchSize > MultiBucketConsumerService .DEFAULT_MAX_BUCKETS )) {
102
130
validationException = addValidationError (
@@ -118,6 +146,9 @@ public void writeTo(StreamOutput out) throws IOException {
118
146
if (out .getVersion ().onOrAfter (Version .V_7_11_0 )) {
119
147
out .writeOptionalInt (datesAsEpochMillis );
120
148
}
149
+ if (out .getVersion ().onOrAfter (Version .CURRENT )) { // TODO: 7.15
150
+ out .writeOptionalInt (interimResults );
151
+ }
121
152
}
122
153
123
154
@ Override
@@ -133,6 +164,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
133
164
if (datesAsEpochMillis != null && (datesAsEpochMillis .equals (DEFAULT_DATES_AS_EPOCH_MILLIS ) == false )) {
134
165
builder .field (TransformField .DATES_AS_EPOCH_MILLIS .getPreferredName (), datesAsEpochMillis > 0 ? true : false );
135
166
}
167
+ if (interimResults != null && (interimResults .equals (DEFAULT_INTERIM_RESULTS ) == false )) {
168
+ builder .field (TransformField .INTERIM_RESULTS .getPreferredName (), interimResults > 0 ? true : false );
169
+ }
136
170
builder .endObject ();
137
171
return builder ;
138
172
}
@@ -149,12 +183,13 @@ public boolean equals(Object other) {
149
183
SettingsConfig that = (SettingsConfig ) other ;
150
184
return Objects .equals (maxPageSearchSize , that .maxPageSearchSize )
151
185
&& Objects .equals (docsPerSecond , that .docsPerSecond )
152
- && Objects .equals (datesAsEpochMillis , that .datesAsEpochMillis );
186
+ && Objects .equals (datesAsEpochMillis , that .datesAsEpochMillis )
187
+ && Objects .equals (interimResults , that .interimResults );
153
188
}
154
189
155
190
@ Override
156
191
public int hashCode () {
157
- return Objects .hash (maxPageSearchSize , docsPerSecond , datesAsEpochMillis );
192
+ return Objects .hash (maxPageSearchSize , docsPerSecond , datesAsEpochMillis , interimResults );
158
193
}
159
194
160
195
@ Override
@@ -170,6 +205,7 @@ public static class Builder {
170
205
private Integer maxPageSearchSize ;
171
206
private Float docsPerSecond ;
172
207
private Integer datesAsEpochMillis ;
208
+ private Integer interimResults ;
173
209
174
210
/**
175
211
* Default builder
@@ -185,6 +221,7 @@ public Builder(SettingsConfig base) {
185
221
this .maxPageSearchSize = base .maxPageSearchSize ;
186
222
this .docsPerSecond = base .docsPerSecond ;
187
223
this .datesAsEpochMillis = base .datesAsEpochMillis ;
224
+ this .interimResults = base .interimResults ;
188
225
}
189
226
190
227
/**
@@ -231,6 +268,19 @@ public Builder setDatesAsEpochMillis(Boolean datesAsEpochMillis) {
231
268
return this ;
232
269
}
233
270
271
+ /**
272
+ * Whether to write interim results in transform checkpoints.
273
+ *
274
+ * An explicit `null` resets to default.
275
+ *
276
+ * @param interimResults true if interim results should be written.
277
+ * @return the {@link Builder} with interimResults set.
278
+ */
279
+ public Builder setInterimResults (Boolean interimResults ) {
280
+ this .interimResults = interimResults == null ? DEFAULT_INTERIM_RESULTS : interimResults ? 1 : 0 ;
281
+ return this ;
282
+ }
283
+
234
284
/**
235
285
* Update settings according to given settings config.
236
286
*
@@ -253,12 +303,17 @@ public Builder update(SettingsConfig update) {
253
303
? null
254
304
: update .getDatesAsEpochMillisForUpdate ();
255
305
}
306
+ if (update .getInterimResultsForUpdate () != null ) {
307
+ this .interimResults = update .getInterimResultsForUpdate ().equals (DEFAULT_INTERIM_RESULTS )
308
+ ? null
309
+ : update .getInterimResultsForUpdate ();
310
+ }
256
311
257
312
return this ;
258
313
}
259
314
260
315
public SettingsConfig build () {
261
- return new SettingsConfig (maxPageSearchSize , docsPerSecond , datesAsEpochMillis );
316
+ return new SettingsConfig (maxPageSearchSize , docsPerSecond , datesAsEpochMillis , interimResults );
262
317
}
263
318
}
264
319
}
0 commit comments