Skip to content

Commit d9ba96c

Browse files
authored
QL: Remove constant_keyword field type (#60524)
* Remove constant_keyword field type
1 parent 0fd70ae commit d9ba96c

File tree

17 files changed

+11
-149
lines changed

17 files changed

+11
-149
lines changed

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/execution/search/extractor/AbstractFieldHitExtractor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Objects;
2929
import java.util.StringJoiner;
3030

31-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
3231
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
3332
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
3433
import static org.elasticsearch.xpack.ql.type.DataTypes.SCALED_FLOAT;
@@ -214,7 +213,6 @@ protected Object unwrapMultiValue(Object values) {
214213
protected boolean isFromDocValuesOnly(DataType dataType) {
215214
return dataType == KEYWORD // because of ignore_above.
216215
|| dataType == DATETIME
217-
|| dataType == CONSTANT_KEYWORD // because a non-existent value is considered the constant value itself
218216
|| dataType == SCALED_FLOAT; // because of scaling_factor
219217
}
220218

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.common.util.set.Sets;
2828
import org.elasticsearch.index.IndexNotFoundException;
2929
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
30-
import org.elasticsearch.xpack.ql.type.ConstantKeywordEsField;
3130
import org.elasticsearch.xpack.ql.type.DataType;
3231
import org.elasticsearch.xpack.ql.type.DataTypeRegistry;
3332
import org.elasticsearch.xpack.ql.type.DateEsField;
@@ -65,7 +64,6 @@
6564
import static java.util.Collections.emptyMap;
6665
import static java.util.Collections.emptySet;
6766
import static org.elasticsearch.action.ActionListener.wrap;
68-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
6967
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
7068
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
7169
import static org.elasticsearch.xpack.ql.type.DataTypes.OBJECT;
@@ -313,13 +311,8 @@ public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, Stri
313311
StringBuilder errorMessage = new StringBuilder();
314312

315313
boolean hasUnmapped = types.containsKey(UNMAPPED);
316-
// a keyword field and a constant_keyword field with the same name in two different indices are considered "compatible"
317-
// since a common use case of constant_keyword field involves two indices with a field having the same name: one being
318-
// a keyword, the other being a constant_keyword
319-
boolean hasCompatibleKeywords = types.containsKey(KEYWORD.esType()) && types.containsKey(CONSTANT_KEYWORD.esType());
320-
int allowedTypesCount = (hasUnmapped ? 2 : 1) + (hasCompatibleKeywords ? 1 : 0);
321314

322-
if (types.size() > allowedTypesCount) {
315+
if (types.size() > (hasUnmapped ? 2 : 1)) {
323316
// build the error message
324317
// and create a MultiTypeField
325318

@@ -364,11 +357,6 @@ public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, Stri
364357
}
365358
}
366359

367-
// if there are both a keyword and a constant_keyword type for this field, only keep the keyword as a common compatible type
368-
if (hasCompatibleKeywords) {
369-
types.remove(CONSTANT_KEYWORD.esType());
370-
}
371-
372360
// everything checks
373361
return null;
374362
});
@@ -460,9 +448,6 @@ private static EsField createField(DataTypeRegistry typeRegistry, String fieldNa
460448
if (esType == DATETIME) {
461449
return new DateEsField(fieldName, props, isAggregateable);
462450
}
463-
if (esType == CONSTANT_KEYWORD) {
464-
return new ConstantKeywordEsField(fieldName);
465-
}
466451
if (esType == UNSUPPORTED) {
467452
return new UnsupportedEsField(fieldName, typeName, null, props);
468453
}
@@ -567,7 +552,6 @@ private static List<EsIndex> buildIndices(DataTypeRegistry typeRegistry, String[
567552
}
568553

569554
Map<String, FieldCapabilities> types = new LinkedHashMap<>(entry.getValue());
570-
// apply verification and possibly remove the "duplicate" CONSTANT_KEYWORD field type
571555
final InvalidMappedField invalidField = validityVerifier.apply(fieldName, types);
572556
// apply verification for fields belonging to index aliases
573557
Map<String, InvalidMappedField> invalidFieldsForAliases = getInvalidFieldsForAliases(fieldName, types, aliases);

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/ConstantKeywordEsField.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypeConverter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
2323
import static org.elasticsearch.xpack.ql.type.DataTypes.BYTE;
24-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
2524
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
2625
import static org.elasticsearch.xpack.ql.type.DataTypes.DOUBLE;
2726
import static org.elasticsearch.xpack.ql.type.DataTypes.FLOAT;
@@ -124,7 +123,7 @@ public static Converter converterFor(DataType from, DataType to) {
124123
return DefaultConverter.TO_NULL;
125124
}
126125
// proper converters
127-
if (to == KEYWORD || to == TEXT || to == CONSTANT_KEYWORD) {
126+
if (to == KEYWORD || to == TEXT) {
128127
return conversionToString(from);
129128
}
130129
if (to == LONG) {

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/DataTypes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public final class DataTypes {
3636
// string
3737
public static final DataType KEYWORD = new DataType("keyword", Integer.MAX_VALUE, false, false, true);
3838
public static final DataType TEXT = new DataType("text", Integer.MAX_VALUE, false, false, false);
39-
public static final DataType CONSTANT_KEYWORD = new DataType("constant_keyword", Integer.MAX_VALUE, false, false, true);
4039
// date
4140
public static final DataType DATETIME = new DataType("DATETIME", "date", Long.BYTES, false, false, true);
4241
// ip
@@ -62,7 +61,6 @@ public final class DataTypes {
6261
SCALED_FLOAT,
6362
KEYWORD,
6463
TEXT,
65-
CONSTANT_KEYWORD,
6664
DATETIME,
6765
IP,
6866
BINARY,
@@ -134,7 +132,7 @@ public static boolean isUnsupported(DataType from) {
134132
}
135133

136134
public static boolean isString(DataType t) {
137-
return t == KEYWORD || t == TEXT || t == CONSTANT_KEYWORD;
135+
return t == KEYWORD || t == TEXT;
138136
}
139137

140138
public static boolean isPrimitive(DataType t) {

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/TextEsField.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.Map;
1212
import java.util.function.Function;
1313

14-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
1514
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
1615
import static org.elasticsearch.xpack.ql.type.DataTypes.TEXT;
1716

@@ -45,7 +44,7 @@ public Exact getExactInfo() {
4544
private Tuple<EsField, String> findExact() {
4645
EsField field = null;
4746
for (EsField property : getProperties().values()) {
48-
if ((property.getDataType() == KEYWORD || property.getDataType() == CONSTANT_KEYWORD) && property.getExactInfo().hasExact()) {
47+
if (property.getDataType() == KEYWORD && property.getExactInfo().hasExact()) {
4948
if (field != null) {
5049
return new Tuple<>(null, "Multiple exact keyword candidates available for [" + getName() +
5150
"]; specify which one to use");

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/type/Types.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Map.Entry;
1515

1616
import static java.util.Collections.emptyMap;
17-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
1817
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
1918
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
2019
import static org.elasticsearch.xpack.ql.type.DataTypes.NESTED;
@@ -49,7 +48,7 @@ private static Map<String, EsField> startWalking(DataTypeRegistry typeRegistry,
4948
private static DataType getType(DataTypeRegistry typeRegistry, Map<String, Object> content) {
5049
if (content.containsKey("type")) {
5150
String typeName = content.get("type").toString();
52-
if ("wildcard".equals(typeName)) {
51+
if ("constant_keyword".equals(typeName) || "wildcard".equals(typeName)) {
5352
return KEYWORD;
5453
}
5554
try {
@@ -94,8 +93,6 @@ private static void walkMapping(DataTypeRegistry typeRegistry, String name, Obje
9493
int length = intSetting(content.get("ignore_above"), Short.MAX_VALUE);
9594
boolean normalized = Strings.hasText(textSetting(content.get("normalizer"), null));
9695
field = new KeywordEsField(name, properties, docValues, length, normalized);
97-
} else if (esDataType == CONSTANT_KEYWORD) {
98-
field = new ConstantKeywordEsField(name);
9996
} else if (esDataType == DATETIME) {
10097
field = new DateEsField(name, properties, docValues);
10198
} else if (esDataType == UNSUPPORTED) {

x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/type/DataTypeConversionTests.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.elasticsearch.xpack.ql.type.DataTypeConverter.converterFor;
1818
import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
1919
import static org.elasticsearch.xpack.ql.type.DataTypes.BYTE;
20-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
2120
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
2221
import static org.elasticsearch.xpack.ql.type.DataTypes.DOUBLE;
2322
import static org.elasticsearch.xpack.ql.type.DataTypes.FLOAT;
@@ -373,7 +372,6 @@ public void testCommonType() {
373372
assertEquals(BOOLEAN, commonType(BOOLEAN, BOOLEAN));
374373
assertEquals(NULL, commonType(NULL, NULL));
375374
assertEquals(INTEGER, commonType(INTEGER, KEYWORD));
376-
assertEquals(DOUBLE, commonType(DOUBLE, CONSTANT_KEYWORD));
377375
assertEquals(LONG, commonType(TEXT, LONG));
378376
assertEquals(SHORT, commonType(SHORT, BYTE));
379377
assertEquals(FLOAT, commonType(BYTE, FLOAT));
@@ -383,11 +381,6 @@ public void testCommonType() {
383381
// strings
384382
assertEquals(TEXT, commonType(TEXT, KEYWORD));
385383
assertEquals(TEXT, commonType(KEYWORD, TEXT));
386-
assertEquals(TEXT, commonType(TEXT, CONSTANT_KEYWORD));
387-
assertEquals(TEXT, commonType(CONSTANT_KEYWORD, TEXT));
388-
assertEquals(KEYWORD, commonType(KEYWORD, CONSTANT_KEYWORD));
389-
assertEquals(KEYWORD, commonType(CONSTANT_KEYWORD, KEYWORD));
390-
assertEquals(CONSTANT_KEYWORD, commonType(CONSTANT_KEYWORD, CONSTANT_KEYWORD));
391384
}
392385

393386
public void testEsDataTypes() {

x-pack/plugin/ql/src/test/java/org/elasticsearch/xpack/ql/type/TypesTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Map;
1515

1616
import static java.util.Collections.emptyMap;
17-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
1817
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
1918
import static org.elasticsearch.xpack.ql.type.DataTypes.INTEGER;
2019
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
@@ -139,7 +138,6 @@ public void testMultiField() {
139138
assertThat(fields.size(), is(4));
140139
assertThat(fields.get("raw").getDataType(), is(KEYWORD));
141140
assertThat(fields.get("english").getDataType(), is(TEXT));
142-
assertThat(fields.get("constant").getDataType(), is(CONSTANT_KEYWORD));
143141
assertThat(fields.get("wildcard").getDataType(), is(KEYWORD));
144142
}
145143

@@ -154,7 +152,6 @@ public void testMultiFieldTooManyOptions() {
154152
assertThat(fields.size(), is(4));
155153
assertThat(fields.get("raw").getDataType(), is(KEYWORD));
156154
assertThat(fields.get("english").getDataType(), is(TEXT));
157-
assertThat(fields.get("constant").getDataType(), is(CONSTANT_KEYWORD));
158155
assertThat(fields.get("wildcard").getDataType(), is(KEYWORD));
159156
}
160157

@@ -182,7 +179,7 @@ public void testConstantKeywordField() {
182179
Map<String, EsField> mapping = loadMapping("mapping-constant-keyword.json");
183180
assertThat(mapping.size(), is(1));
184181
EsField dt = mapping.get("full_name");
185-
assertThat(dt.getDataType().typeName(), is("constant_keyword"));
182+
assertThat(dt.getDataType().typeName(), is("keyword"));
186183
}
187184

188185
public void testWildcardField() {

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/EsType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public enum EsType implements SQLType {
2525
SCALED_FLOAT( Types.FLOAT),
2626
KEYWORD( Types.VARCHAR),
2727
TEXT( Types.VARCHAR),
28-
CONSTANT_KEYWORD( Types.VARCHAR),
2928
OBJECT( Types.STRUCT),
3029
NESTED( Types.STRUCT),
3130
BINARY( Types.VARBINARY),

0 commit comments

Comments
 (0)