in x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/textstructure/structurefinder/TextStructure.java [676:826]
public TextStructure build() {
if (numLinesAnalyzed <= 0) {
throw new IllegalArgumentException("Number of lines analyzed must be positive.");
}
if (numMessagesAnalyzed <= 0) {
throw new IllegalArgumentException("Number of messages analyzed must be positive.");
}
if (numMessagesAnalyzed > numLinesAnalyzed) {
throw new IllegalArgumentException("Number of messages analyzed cannot be greater than number of lines analyzed.");
}
if (sampleStart == null || sampleStart.isEmpty()) {
throw new IllegalArgumentException("Sample start must be specified.");
}
if (charset == null || charset.isEmpty()) {
throw new IllegalArgumentException("A character set must be specified.");
}
if (charset.toUpperCase(Locale.ROOT).startsWith("UTF") == false && hasByteOrderMarker != null) {
throw new IllegalArgumentException("A byte order marker is only possible for UTF character sets.");
}
switch (format) {
case NDJSON:
if (shouldTrimFields != null) {
throw new IllegalArgumentException("Should trim fields may not be specified for [" + format + "] structures.");
}
// $FALL-THROUGH$
case XML:
if (columnNames != null) {
throw new IllegalArgumentException("Column names may not be specified for [" + format + "] structures.");
}
if (hasHeaderRow != null) {
throw new IllegalArgumentException("Has header row may not be specified for [" + format + "] structures.");
}
if (delimiter != null) {
throw new IllegalArgumentException("Delimiter may not be specified for [" + format + "] structures.");
}
if (quote != null) {
throw new IllegalArgumentException("Quote may not be specified for [" + format + "] structures.");
}
if (grokPattern != null) {
throw new IllegalArgumentException("Grok pattern may not be specified for [" + format + "] structures.");
}
break;
case DELIMITED:
if (columnNames == null || columnNames.isEmpty()) {
throw new IllegalArgumentException("Column names must be specified for [" + format + "] structures.");
}
if (hasHeaderRow == null) {
throw new IllegalArgumentException("Has header row must be specified for [" + format + "] structures.");
}
if (delimiter == null) {
throw new IllegalArgumentException("Delimiter must be specified for [" + format + "] structures.");
}
if (grokPattern != null) {
throw new IllegalArgumentException("Grok pattern may not be specified for [" + format + "] structures.");
}
break;
case SEMI_STRUCTURED_TEXT:
if (columnNames != null) {
throw new IllegalArgumentException("Column names may not be specified for [" + format + "] structures.");
}
if (hasHeaderRow != null) {
throw new IllegalArgumentException("Has header row may not be specified for [" + format + "] structures.");
}
if (delimiter != null) {
throw new IllegalArgumentException("Delimiter may not be specified for [" + format + "] structures.");
}
if (quote != null) {
throw new IllegalArgumentException("Quote may not be specified for [" + format + "] structures.");
}
if (shouldTrimFields != null) {
throw new IllegalArgumentException("Should trim fields may not be specified for [" + format + "] structures.");
}
if (grokPattern == null || grokPattern.isEmpty()) {
throw new IllegalArgumentException("Grok pattern must be specified for [" + format + "] structures.");
}
if (ecsCompatibility != null
&& ecsCompatibility.isEmpty() == false
&& GrokBuiltinPatterns.isValidEcsCompatibilityMode(ecsCompatibility) == false) {
throw new IllegalArgumentException(
ECS_COMPATIBILITY.getPreferredName()
+ "] must be one of ["
+ String.join(", ", GrokBuiltinPatterns.ECS_COMPATIBILITY_MODES)
+ "] if specified"
);
}
break;
default:
throw new IllegalStateException("enum value [" + format + "] missing from switch.");
}
boolean isTimestampFieldSpecified = (timestampField != null);
boolean isJodaTimestampFormatsSpecified = (jodaTimestampFormats != null && jodaTimestampFormats.isEmpty() == false);
boolean isJavaTimestampFormatsSpecified = (javaTimestampFormats != null && javaTimestampFormats.isEmpty() == false);
if (isTimestampFieldSpecified != isJodaTimestampFormatsSpecified) {
throw new IllegalArgumentException(
"Timestamp field and Joda timestamp formats must both be specified or neither be specified."
);
}
if (isTimestampFieldSpecified != isJavaTimestampFormatsSpecified) {
throw new IllegalArgumentException(
"Timestamp field and Java timestamp formats must both be specified or neither be specified."
);
}
if (needClientTimezone && isTimestampFieldSpecified == false) {
throw new IllegalArgumentException("Client timezone cannot be needed if there is no timestamp field.");
}
if (mappings == null || mappings.isEmpty()) {
throw new IllegalArgumentException("Mappings must be specified.");
}
if (explanation == null || explanation.isEmpty()) {
throw new IllegalArgumentException("Explanation must be specified.");
}
return new TextStructure(
numLinesAnalyzed,
numMessagesAnalyzed,
sampleStart,
charset,
hasByteOrderMarker,
format,
multilineStartPattern,
excludeLinesPattern,
columnNames,
hasHeaderRow,
delimiter,
quote,
shouldTrimFields,
grokPattern,
ecsCompatibility,
timestampField,
jodaTimestampFormats,
javaTimestampFormats,
needClientTimezone,
mappings,
ingestPipeline,
fieldStats,
explanation
);
}