Skip to content

Commit 1d54310

Browse files
bpinteaastefan
andauthored
QL: Remove constant_keyword field type (#60524) (#64661)
* Remove constant_keyword field type (cherry picked from commit d9ba96c) Co-authored-by: Andrei Stefan <astefan@users.noreply.github.com>
1 parent e92c5d6 commit 1d54310

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
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.collect.ImmutableOpenMap;
2727
import org.elasticsearch.index.IndexNotFoundException;
2828
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
29-
import org.elasticsearch.xpack.ql.type.ConstantKeywordEsField;
3029
import org.elasticsearch.xpack.ql.type.DataType;
3130
import org.elasticsearch.xpack.ql.type.DataTypeRegistry;
3231
import org.elasticsearch.xpack.ql.type.DateEsField;
@@ -64,7 +63,6 @@
6463
import static java.util.Collections.emptyMap;
6564
import static java.util.Collections.emptySet;
6665
import static org.elasticsearch.action.ActionListener.wrap;
67-
import static org.elasticsearch.xpack.ql.type.DataTypes.CONSTANT_KEYWORD;
6866
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
6967
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
7068
import static org.elasticsearch.xpack.ql.type.DataTypes.OBJECT;
@@ -312,13 +310,8 @@ public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, Stri
312310
StringBuilder errorMessage = new StringBuilder();
313311

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

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

@@ -363,11 +356,6 @@ public static IndexResolution mergedMappings(DataTypeRegistry typeRegistry, Stri
363356
}
364357
}
365358

366-
// if there are both a keyword and a constant_keyword type for this field, only keep the keyword as a common compatible type
367-
if (hasCompatibleKeywords) {
368-
types.remove(CONSTANT_KEYWORD.esType());
369-
}
370-
371359
// everything checks
372360
return null;
373361
});
@@ -459,9 +447,6 @@ private static EsField createField(DataTypeRegistry typeRegistry, String fieldNa
459447
if (esType == DATETIME) {
460448
return new DateEsField(fieldName, props, isAggregateable);
461449
}
462-
if (esType == CONSTANT_KEYWORD) {
463-
return new ConstantKeywordEsField(fieldName);
464-
}
465450
if (esType == UNSUPPORTED) {
466451
return new UnsupportedEsField(fieldName, typeName, null, props);
467452
}
@@ -566,7 +551,6 @@ private static List<EsIndex> buildIndices(DataTypeRegistry typeRegistry, String[
566551
}
567552

568553
Map<String, FieldCapabilities> types = new LinkedHashMap<>(entry.getValue());
569-
// apply verification and possibly remove the "duplicate" CONSTANT_KEYWORD field type
570554
final InvalidMappedField invalidField = validityVerifier.apply(fieldName, types);
571555
// apply verification for fields belonging to index aliases
572556
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
@@ -38,7 +38,6 @@ public final class DataTypes {
3838
// string
3939
public static final DataType KEYWORD = new DataType("keyword", Integer.MAX_VALUE, false, false, true);
4040
public static final DataType TEXT = new DataType("text", Integer.MAX_VALUE, false, false, false);
41-
public static final DataType CONSTANT_KEYWORD = new DataType("constant_keyword", Integer.MAX_VALUE, false, false, true);
4241
// date
4342
public static final DataType DATETIME = new DataType("DATETIME", "date", Long.BYTES, false, false, true);
4443
// ip
@@ -64,7 +63,6 @@ public final class DataTypes {
6463
SCALED_FLOAT,
6564
KEYWORD,
6665
TEXT,
67-
CONSTANT_KEYWORD,
6866
DATETIME,
6967
IP,
7068
BINARY,
@@ -136,7 +134,7 @@ public static boolean isUnsupported(DataType from) {
136134
}
137135

138136
public static boolean isString(DataType t) {
139-
return t == KEYWORD || t == TEXT || t == CONSTANT_KEYWORD;
137+
return t == KEYWORD || t == TEXT;
140138
}
141139

142140
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;
@@ -370,7 +369,6 @@ public void testCommonType() {
370369
assertEquals(BOOLEAN, commonType(BOOLEAN, BOOLEAN));
371370
assertEquals(NULL, commonType(NULL, NULL));
372371
assertEquals(INTEGER, commonType(INTEGER, KEYWORD));
373-
assertEquals(DOUBLE, commonType(DOUBLE, CONSTANT_KEYWORD));
374372
assertEquals(LONG, commonType(TEXT, LONG));
375373
assertEquals(SHORT, commonType(SHORT, BYTE));
376374
assertEquals(FLOAT, commonType(BYTE, FLOAT));
@@ -380,11 +378,6 @@ public void testCommonType() {
380378
// strings
381379
assertEquals(TEXT, commonType(TEXT, KEYWORD));
382380
assertEquals(TEXT, commonType(KEYWORD, TEXT));
383-
assertEquals(TEXT, commonType(TEXT, CONSTANT_KEYWORD));
384-
assertEquals(TEXT, commonType(CONSTANT_KEYWORD, TEXT));
385-
assertEquals(KEYWORD, commonType(KEYWORD, CONSTANT_KEYWORD));
386-
assertEquals(KEYWORD, commonType(CONSTANT_KEYWORD, KEYWORD));
387-
assertEquals(CONSTANT_KEYWORD, commonType(CONSTANT_KEYWORD, CONSTANT_KEYWORD));
388381
}
389382

390383
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)