9
9
10
10
import org .elasticsearch .common .xcontent .ParseField ;
11
11
import org .elasticsearch .common .xcontent .ObjectParser ;
12
- import org .elasticsearch .common .xcontent .ObjectParser .ValueType ;
13
12
import org .elasticsearch .common .xcontent .ToXContentObject ;
14
13
import org .elasticsearch .common .xcontent .XContentBuilder ;
15
- import org .elasticsearch .common .xcontent .XContentParser ;
16
14
17
15
import java .io .IOException ;
18
16
import java .util .Locale ;
@@ -31,12 +29,7 @@ public class DataDescription implements ToXContentObject {
31
29
* Enum of the acceptable data formats.
32
30
*/
33
31
public enum DataFormat {
34
- XCONTENT ,
35
-
36
- /**
37
- * This is deprecated
38
- */
39
- DELIMITED ;
32
+ XCONTENT ;
40
33
41
34
/**
42
35
* Case-insensitive from string method.
@@ -56,11 +49,8 @@ public String toString() {
56
49
}
57
50
58
51
private static final ParseField DATA_DESCRIPTION_FIELD = new ParseField ("data_description" );
59
- private static final ParseField FORMAT_FIELD = new ParseField ("format" );
60
52
private static final ParseField TIME_FIELD_NAME_FIELD = new ParseField ("time_field" );
61
53
private static final ParseField TIME_FORMAT_FIELD = new ParseField ("time_format" );
62
- private static final ParseField FIELD_DELIMITER_FIELD = new ParseField ("field_delimiter" );
63
- private static final ParseField QUOTE_CHARACTER_FIELD = new ParseField ("quote_character" );
64
54
65
55
/**
66
56
* Special time format string for epoch times (seconds)
@@ -77,70 +67,39 @@ public String toString() {
77
67
*/
78
68
public static final String DEFAULT_TIME_FIELD = "time" ;
79
69
80
- /**
81
- * The default field delimiter expected by the native autodetect
82
- * program.
83
- */
84
- public static final char DEFAULT_DELIMITER = '\t' ;
85
-
86
- /**
87
- * The default quote character used to escape text in
88
- * delimited data formats
89
- */
90
- public static final char DEFAULT_QUOTE_CHAR = '"' ;
91
-
92
- private final DataFormat dataFormat ;
93
70
private final String timeFieldName ;
94
71
private final String timeFormat ;
95
- private final Character fieldDelimiter ;
96
- private final Character quoteCharacter ;
97
72
98
73
public static final ObjectParser <Builder , Void > PARSER =
99
74
new ObjectParser <>(DATA_DESCRIPTION_FIELD .getPreferredName (), true , Builder ::new );
100
75
101
76
static {
102
- PARSER .declareString (Builder ::setFormat , FORMAT_FIELD );
103
77
PARSER .declareString (Builder ::setTimeField , TIME_FIELD_NAME_FIELD );
104
78
PARSER .declareString (Builder ::setTimeFormat , TIME_FORMAT_FIELD );
105
- PARSER .declareField (Builder ::setFieldDelimiter , DataDescription ::extractChar , FIELD_DELIMITER_FIELD , ValueType .STRING );
106
- PARSER .declareField (Builder ::setQuoteCharacter , DataDescription ::extractChar , QUOTE_CHARACTER_FIELD , ValueType .STRING );
107
79
}
108
80
109
- public DataDescription (DataFormat dataFormat , String timeFieldName , String timeFormat , Character fieldDelimiter ,
110
- Character quoteCharacter ) {
111
- this .dataFormat = dataFormat ;
81
+ public DataDescription (String timeFieldName , String timeFormat ) {
112
82
this .timeFieldName = timeFieldName ;
113
83
this .timeFormat = timeFormat ;
114
- this .fieldDelimiter = fieldDelimiter ;
115
- this .quoteCharacter = quoteCharacter ;
116
84
}
117
85
118
86
@ Override
119
87
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
120
88
builder .startObject ();
121
- if (dataFormat != DataFormat .XCONTENT ) {
122
- builder .field (FORMAT_FIELD .getPreferredName (), dataFormat );
123
- }
124
89
builder .field (TIME_FIELD_NAME_FIELD .getPreferredName (), timeFieldName );
125
90
builder .field (TIME_FORMAT_FIELD .getPreferredName (), timeFormat );
126
- if (fieldDelimiter != null ) {
127
- builder .field (FIELD_DELIMITER_FIELD .getPreferredName (), String .valueOf (fieldDelimiter ));
128
- }
129
- if (quoteCharacter != null ) {
130
- builder .field (QUOTE_CHARACTER_FIELD .getPreferredName (), String .valueOf (quoteCharacter ));
131
- }
132
91
builder .endObject ();
133
92
return builder ;
134
93
}
135
94
136
95
/**
137
96
* The format of the data to be processed.
138
- * Defaults to {@link DataDescription.DataFormat#XCONTENT}
97
+ * Always {@link DataDescription.DataFormat#XCONTENT}
139
98
*
140
99
* @return The data format
141
100
*/
142
101
public DataFormat getFormat () {
143
- return dataFormat ;
102
+ return DataFormat . XCONTENT ;
144
103
}
145
104
146
105
/**
@@ -164,39 +123,6 @@ public String getTimeFormat() {
164
123
return timeFormat ;
165
124
}
166
125
167
- /**
168
- * If the data is in a delimited format with a header e.g. csv or tsv
169
- * this is the delimiter character used. This is only applicable if
170
- * {@linkplain #getFormat()} is {@link DataDescription.DataFormat#DELIMITED}.
171
- * The default value for delimited format is {@value #DEFAULT_DELIMITER}.
172
- *
173
- * @return A char
174
- */
175
- public Character getFieldDelimiter () {
176
- return fieldDelimiter ;
177
- }
178
-
179
- /**
180
- * The quote character used in delimited formats.
181
- * The default value for delimited format is {@value #DEFAULT_QUOTE_CHAR}.
182
- *
183
- * @return The delimited format quote character
184
- */
185
- public Character getQuoteCharacter () {
186
- return quoteCharacter ;
187
- }
188
-
189
- private static Character extractChar (XContentParser parser ) throws IOException {
190
- if (parser .currentToken () == XContentParser .Token .VALUE_STRING ) {
191
- String charStr = parser .text ();
192
- if (charStr .length () != 1 ) {
193
- throw new IllegalArgumentException ("String must be a single character, found [" + charStr + "]" );
194
- }
195
- return charStr .charAt (0 );
196
- }
197
- throw new IllegalArgumentException ("Unsupported token [" + parser .currentToken () + "]" );
198
- }
199
-
200
126
/**
201
127
* Overridden equality test
202
128
*/
@@ -212,33 +138,21 @@ public boolean equals(Object other) {
212
138
213
139
DataDescription that = (DataDescription ) other ;
214
140
215
- return this .dataFormat == that .dataFormat &&
216
- Objects .equals (this .quoteCharacter , that .quoteCharacter ) &&
217
- Objects .equals (this .timeFieldName , that .timeFieldName ) &&
218
- Objects .equals (this .timeFormat , that .timeFormat ) &&
219
- Objects .equals (this .fieldDelimiter , that .fieldDelimiter );
141
+ return Objects .equals (this .timeFieldName , that .timeFieldName ) && Objects .equals (this .timeFormat , that .timeFormat );
220
142
}
221
143
222
144
@ Override
223
145
public int hashCode () {
224
- return Objects .hash (dataFormat , quoteCharacter , timeFieldName , timeFormat , fieldDelimiter );
146
+ return Objects .hash (timeFieldName , timeFormat );
225
147
}
226
148
227
149
public static class Builder {
228
150
229
- private DataFormat dataFormat = DataFormat .XCONTENT ;
230
151
private String timeFieldName = DEFAULT_TIME_FIELD ;
231
152
private String timeFormat = EPOCH_MS ;
232
- private Character fieldDelimiter ;
233
- private Character quoteCharacter ;
234
153
235
154
public Builder setFormat (DataFormat format ) {
236
- dataFormat = Objects .requireNonNull (format );
237
- return this ;
238
- }
239
-
240
- private Builder setFormat (String format ) {
241
- setFormat (DataFormat .forString (format ));
155
+ Objects .requireNonNull (format );
242
156
return this ;
243
157
}
244
158
@@ -252,26 +166,8 @@ public Builder setTimeFormat(String format) {
252
166
return this ;
253
167
}
254
168
255
- public Builder setFieldDelimiter (Character delimiter ) {
256
- fieldDelimiter = delimiter ;
257
- return this ;
258
- }
259
-
260
- public Builder setQuoteCharacter (Character value ) {
261
- quoteCharacter = value ;
262
- return this ;
263
- }
264
-
265
169
public DataDescription build () {
266
- if (dataFormat == DataFormat .DELIMITED ) {
267
- if (fieldDelimiter == null ) {
268
- fieldDelimiter = DEFAULT_DELIMITER ;
269
- }
270
- if (quoteCharacter == null ) {
271
- quoteCharacter = DEFAULT_QUOTE_CHAR ;
272
- }
273
- }
274
- return new DataDescription (dataFormat , timeFieldName , timeFormat , fieldDelimiter , quoteCharacter );
170
+ return new DataDescription (timeFieldName , timeFormat );
275
171
}
276
172
}
277
173
}
0 commit comments