1919
2020package org .elasticsearch .client .dataframe .transforms ;
2121
22+ import org .elasticsearch .Version ;
2223import org .elasticsearch .client .dataframe .transforms .pivot .PivotConfig ;
24+ import org .elasticsearch .client .dataframe .transforms .util .TimeUtil ;
2325import org .elasticsearch .common .Nullable ;
2426import org .elasticsearch .common .ParseField ;
2527import org .elasticsearch .common .Strings ;
2628import org .elasticsearch .common .xcontent .ConstructingObjectParser ;
29+ import org .elasticsearch .common .xcontent .ObjectParser ;
2730import org .elasticsearch .common .xcontent .ToXContentObject ;
2831import org .elasticsearch .common .xcontent .XContentBuilder ;
2932import org .elasticsearch .common .xcontent .XContentParser ;
3033
3134import java .io .IOException ;
35+ import java .time .Instant ;
3236import java .util .Objects ;
3337
3438import static org .elasticsearch .common .xcontent .ConstructingObjectParser .constructorArg ;
@@ -40,6 +44,8 @@ public class DataFrameTransformConfig implements ToXContentObject {
4044 public static final ParseField SOURCE = new ParseField ("source" );
4145 public static final ParseField DEST = new ParseField ("dest" );
4246 public static final ParseField DESCRIPTION = new ParseField ("description" );
47+ public static final ParseField VERSION = new ParseField ("version" );
48+ public static final ParseField CREATE_TIME = new ParseField ("create_time" );
4349 // types of transforms
4450 public static final ParseField PIVOT_TRANSFORM = new ParseField ("pivot" );
4551
@@ -48,6 +54,8 @@ public class DataFrameTransformConfig implements ToXContentObject {
4854 private final DestConfig dest ;
4955 private final PivotConfig pivotConfig ;
5056 private final String description ;
57+ private final Version transformVersion ;
58+ private final Instant createTime ;
5159
5260 public static final ConstructingObjectParser <DataFrameTransformConfig , Void > PARSER =
5361 new ConstructingObjectParser <>("data_frame_transform" , true ,
@@ -57,7 +65,9 @@ public class DataFrameTransformConfig implements ToXContentObject {
5765 DestConfig dest = (DestConfig ) args [2 ];
5866 PivotConfig pivotConfig = (PivotConfig ) args [3 ];
5967 String description = (String )args [4 ];
60- return new DataFrameTransformConfig (id , source , dest , pivotConfig , description );
68+ Instant createTime = (Instant )args [5 ];
69+ String transformVersion = (String )args [6 ];
70+ return new DataFrameTransformConfig (id , source , dest , pivotConfig , description , createTime , transformVersion );
6171 });
6272
6373 static {
@@ -66,6 +76,9 @@ public class DataFrameTransformConfig implements ToXContentObject {
6676 PARSER .declareObject (constructorArg (), (p , c ) -> DestConfig .PARSER .apply (p , null ), DEST );
6777 PARSER .declareObject (optionalConstructorArg (), (p , c ) -> PivotConfig .fromXContent (p ), PIVOT_TRANSFORM );
6878 PARSER .declareString (optionalConstructorArg (), DESCRIPTION );
79+ PARSER .declareField (optionalConstructorArg (),
80+ p -> TimeUtil .parseTimeFieldToInstant (p , CREATE_TIME .getPreferredName ()), CREATE_TIME , ObjectParser .ValueType .VALUE );
81+ PARSER .declareString (optionalConstructorArg (), VERSION );
6982 }
7083
7184 public static DataFrameTransformConfig fromXContent (final XContentParser parser ) {
@@ -84,19 +97,23 @@ public static DataFrameTransformConfig fromXContent(final XContentParser parser)
8497 * @return A DataFrameTransformConfig to preview, NOTE it will have a {@code null} id, destination and index.
8598 */
8699 public static DataFrameTransformConfig forPreview (final SourceConfig source , final PivotConfig pivotConfig ) {
87- return new DataFrameTransformConfig (null , source , null , pivotConfig , null );
100+ return new DataFrameTransformConfig (null , source , null , pivotConfig , null , null , null );
88101 }
89102
90103 DataFrameTransformConfig (final String id ,
91104 final SourceConfig source ,
92105 final DestConfig dest ,
93106 final PivotConfig pivotConfig ,
94- final String description ) {
107+ final String description ,
108+ final Instant createTime ,
109+ final String version ) {
95110 this .id = id ;
96111 this .source = source ;
97112 this .dest = dest ;
98113 this .pivotConfig = pivotConfig ;
99114 this .description = description ;
115+ this .createTime = createTime == null ? null : Instant .ofEpochMilli (createTime .toEpochMilli ());
116+ this .transformVersion = version == null ? null : Version .fromString (version );
100117 }
101118
102119 public String getId () {
@@ -115,6 +132,14 @@ public PivotConfig getPivotConfig() {
115132 return pivotConfig ;
116133 }
117134
135+ public Version getVersion () {
136+ return transformVersion ;
137+ }
138+
139+ public Instant getCreateTime () {
140+ return createTime ;
141+ }
142+
118143 @ Nullable
119144 public String getDescription () {
120145 return description ;
@@ -138,6 +163,12 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
138163 if (description != null ) {
139164 builder .field (DESCRIPTION .getPreferredName (), description );
140165 }
166+ if (createTime != null ) {
167+ builder .timeField (CREATE_TIME .getPreferredName (), CREATE_TIME .getPreferredName () + "_string" , createTime .toEpochMilli ());
168+ }
169+ if (transformVersion != null ) {
170+ builder .field (VERSION .getPreferredName (), transformVersion );
171+ }
141172 builder .endObject ();
142173 return builder ;
143174 }
@@ -155,15 +186,17 @@ public boolean equals(Object other) {
155186 final DataFrameTransformConfig that = (DataFrameTransformConfig ) other ;
156187
157188 return Objects .equals (this .id , that .id )
158- && Objects .equals (this .source , that .source )
159- && Objects .equals (this .dest , that .dest )
160- && Objects .equals (this .description , that .description )
161- && Objects .equals (this .pivotConfig , that .pivotConfig );
189+ && Objects .equals (this .source , that .source )
190+ && Objects .equals (this .dest , that .dest )
191+ && Objects .equals (this .description , that .description )
192+ && Objects .equals (this .transformVersion , that .transformVersion )
193+ && Objects .equals (this .createTime , that .createTime )
194+ && Objects .equals (this .pivotConfig , that .pivotConfig );
162195 }
163196
164197 @ Override
165198 public int hashCode () {
166- return Objects .hash (id , source , dest , pivotConfig , description );
199+ return Objects .hash (id , source , dest , pivotConfig , description , createTime , transformVersion );
167200 }
168201
169202 @ Override
@@ -209,7 +242,7 @@ public Builder setDescription(String description) {
209242 }
210243
211244 public DataFrameTransformConfig build () {
212- return new DataFrameTransformConfig (id , source , dest , pivotConfig , description );
245+ return new DataFrameTransformConfig (id , source , dest , pivotConfig , description , null , null );
213246 }
214247 }
215248}
0 commit comments