Skip to content

Commit 93f8609

Browse files
committed
Addressed feedback - renamed some functions, converted all snake case test names to camel case
1 parent 84755a6 commit 93f8609

File tree

10 files changed

+53
-41
lines changed

10 files changed

+53
-41
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,21 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
294294
) {
295295
assert searchExecutionContext.isSourceSynthetic() : "Synthetic source should be enabled";
296296

297-
String parentField = searchExecutionContext.parentPath(name());
298-
var parent = searchExecutionContext.lookup().fieldType(parentField);
297+
String parentFieldName = searchExecutionContext.parentPath(name());
298+
var parent = searchExecutionContext.lookup().fieldType(parentFieldName);
299299

300300
if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent && keywordParent.ignoreAbove().isSet()) {
301-
final String parentFieldName = keywordParent.syntheticSourceFallbackFieldName();
301+
final String parentFallbackFieldName = keywordParent.syntheticSourceFallbackFieldName();
302302
if (parent.isStored()) {
303-
return storedFieldFetcher(parentField, parentFieldName);
303+
return storedFieldFetcher(parentFieldName, parentFallbackFieldName);
304304
} else if (parent.hasDocValues()) {
305305
var ifd = searchExecutionContext.getForField(parent, MappedFieldType.FielddataOperation.SEARCH);
306-
return combineFieldFetchers(docValuesFieldFetcher(ifd), storedFieldFetcher(parentFieldName));
306+
return combineFieldFetchers(docValuesFieldFetcher(ifd), storedFieldFetcher(parentFallbackFieldName));
307307
}
308308
}
309309

310310
if (parent.isStored()) {
311-
return storedFieldFetcher(parentField);
311+
return storedFieldFetcher(parentFieldName);
312312
} else if (parent.hasDocValues()) {
313313
var ifd = searchExecutionContext.getForField(parent, MappedFieldType.FielddataOperation.SEARCH);
314314
return docValuesFieldFetcher(ifd);
@@ -701,7 +701,7 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
701701
context.addToFieldNames(fieldType().name());
702702

703703
// match_only_text isn't stored, so if synthetic source needs to be supported, we must do something about it
704-
if (fieldType().textFieldType.needsToSupportSyntheticSource(indexCreatedVersion)) {
704+
if (fieldType().textFieldType.shouldStoreFieldForSyntheticSource(indexCreatedVersion)) {
705705
// check if we can use the delegate
706706
if (fieldType().canUseSyntheticSourceDelegateForSyntheticSource(value)) {
707707
return;

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void testRangeIntervals() {
225225
);
226226
}
227227

228-
public void test_block_loader_uses_stored_fields_for_loading_when_synthetic_source_delegate_is_absent() {
228+
public void testBlockLoaderUsesStoredFieldsForLoadingWhenSyntheticSourceDelegateIsAbsent() {
229229
// given
230230
MatchOnlyTextFieldMapper.MatchOnlyTextFieldType ft = new MatchOnlyTextFieldMapper.MatchOnlyTextFieldType(
231231
"parent",
@@ -246,7 +246,7 @@ public void test_block_loader_uses_stored_fields_for_loading_when_synthetic_sour
246246
assertThat(blockLoader, Matchers.instanceOf(MatchOnlyTextFieldType.BytesFromMixedStringsBytesRefBlockLoader.class));
247247
}
248248

249-
public void test_block_loader_uses_synthetic_source_delegate_when_ignore_above_is_not_set() {
249+
public void testBlockLoaderUsesSyntheticSourceDelegateWhenIgnoreAboveIsNotSet() {
250250
// given
251251
KeywordFieldMapper.KeywordFieldType syntheticSourceDelegate = new KeywordFieldMapper.KeywordFieldType(
252252
"child",
@@ -274,7 +274,7 @@ public void test_block_loader_uses_synthetic_source_delegate_when_ignore_above_i
274274
assertThat(blockLoader, Matchers.instanceOf(BlockLoader.Delegating.class));
275275
}
276276

277-
public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore_above_is_set() {
277+
public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSet() {
278278
// given
279279
Settings settings = Settings.builder()
280280
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -322,7 +322,7 @@ public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore
322322
assertThat(blockLoader, Matchers.not(Matchers.instanceOf(BlockLoader.Delegating.class)));
323323
}
324324

325-
public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore_above_is_set_at_index_level() {
325+
public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSetAtIndexLevel() {
326326
// given
327327
Settings settings = Settings.builder()
328328
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())

plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
583583
}
584584

585585
private boolean needsToSupportSyntheticSource() {
586-
if (TextFieldMapper.multiFieldsNotStoredByDefault_indexVersionCheck(indexCreatedVersion)) {
586+
if (TextFieldMapper.multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
587587
// if we're within a multi field, then supporting synthetic source isn't necessary as that's the responsibility of the parent
588588
return fieldType().isSyntheticSourceEnabled() && fieldType().isWithinMultiField() == false;
589589
}

plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void testEnableStore() throws IOException {
293293
assertTrue(fields.get(0).fieldType().stored());
294294
}
295295

296-
public void test_store_parameter_defaults_to_false_in_latest_index_version_when_synthetic_source_is_enabled() throws IOException {
296+
public void testStoreParameterDefaultsToFalse() throws IOException {
297297
// given
298298
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> { b.field("type", "annotated_text"); }));
299299

@@ -305,7 +305,21 @@ public void test_store_parameter_defaults_to_false_in_latest_index_version_when_
305305
assertFalse(fields.getFirst().fieldType().stored());
306306
}
307307

308-
public void testStoreParameterDefaultsBwc() throws IOException {
308+
public void testStoreParameterDefaultsToFalseWhenSyntheticSourceIsEnabled() throws IOException {
309+
// given
310+
var indexSettings = getIndexSettingsBuilder().put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic").build();
311+
DocumentMapper mapper = createMapperService(indexSettings, fieldMapping(b -> { b.field("type", "annotated_text"); }))
312+
.documentMapper();
313+
314+
// when
315+
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "1234")));
316+
317+
// then
318+
List<IndexableField> fields = doc.rootDoc().getFields("field");
319+
assertFalse(fields.getFirst().fieldType().stored());
320+
}
321+
322+
public void testStoreParameterDefaultsWhenIndexVersionIsNotLatest() throws IOException {
309323
var timeSeriesIndexMode = randomBoolean();
310324
var isStored = randomBoolean();
311325
var hasKeywordFieldForSyntheticSource = randomBoolean();

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ public FieldMapper.Builder getMergeBuilder() {
13161316
enableDocValuesSkipper,
13171317
forceDocValuesSkipper,
13181318
indexSourceKeepMode,
1319-
fieldType().isWithinMultiField() // TODO: is this ok?
1319+
fieldType().isWithinMultiField()
13201320
).dimension(fieldType().isDimension()).init(this);
13211321
}
13221322

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public Builder(
326326
}
327327

328328
// however, because historically we set store to true to support synthetic source, we must also keep that logic:
329-
if (multiFieldsNotStoredByDefault_indexVersionCheck(indexCreatedVersion)) {
329+
if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
330330
return isSyntheticSourceEnabled
331331
&& isWithinMultiField == false
332332
&& multiFieldsBuilder.hasSyntheticSourceCompatibleKeywordField() == false;
@@ -1063,8 +1063,8 @@ public boolean canUseSyntheticSourceDelegateForQueryingEquality(String str) {
10631063
return syntheticSourceDelegate.get().ignoreAbove().isIgnored(str) == false;
10641064
}
10651065

1066-
public boolean needsToSupportSyntheticSource(final IndexVersion indexCreatedVersion) {
1067-
if (multiFieldsNotStoredByDefault_indexVersionCheck(indexCreatedVersion)) {
1066+
public boolean shouldStoreFieldForSyntheticSource(final IndexVersion indexCreatedVersion) {
1067+
if (multiFieldsNotStoredByDefaultIndexVersionCheck(indexCreatedVersion)) {
10681068
// if we're within a multi field, then supporting synthetic source isn't necessary as that's the responsibility of the
10691069
// parent
10701070
return isSyntheticSourceEnabled() && isWithinMultiField() == false;
@@ -1419,8 +1419,8 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
14191419
}
14201420
}
14211421

1422-
// if synthetic source needs to be supported, yet the field isn't stored, then we need to rely on something else
1423-
if (fieldType().needsToSupportSyntheticSource(indexCreatedVersion) && fieldType.stored() == false) {
1422+
// store the field if isn't stored yet, and we need it to be stored for synthetic source
1423+
if (fieldType.stored() == false && fieldType().shouldStoreFieldForSyntheticSource(indexCreatedVersion)) {
14241424
// if we can rely on the synthetic source delegate for synthetic source, then exit as there is nothing to do
14251425
if (fieldType().canUseSyntheticSourceDelegateForSyntheticSource(value)) {
14261426
return;
@@ -1443,7 +1443,7 @@ public static boolean keywordMultiFieldsNotStoredWhenIgnoredIndexVersionCheck(fi
14431443
/**
14441444
* Returns whether the current index version supports not storing fields by default when they're multi fields.
14451445
*/
1446-
public static boolean multiFieldsNotStoredByDefault_indexVersionCheck(final IndexVersion indexCreatedVersion) {
1446+
public static boolean multiFieldsNotStoredByDefaultIndexVersionCheck(final IndexVersion indexCreatedVersion) {
14471447
return indexCreatedVersion.onOrAfter(IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED)
14481448
|| indexCreatedVersion.between(
14491449
IndexVersions.MAPPER_TEXT_MATCH_ONLY_MULTI_FIELDS_DEFAULT_NOT_STORED_8_19,

server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
import static org.hamcrest.Matchers.greaterThan;
6565
import static org.hamcrest.Matchers.hasSize;
6666
import static org.hamcrest.Matchers.instanceOf;
67-
import static org.junit.Assert.assertFalse;
68-
import static org.junit.Assert.assertTrue;
6967

7068
public class KeywordFieldMapperTests extends MapperTestCase {
7169

@@ -247,7 +245,7 @@ public void testIgnoreAbove() throws IOException {
247245
assertTrue(doc.rootDoc().getFields("_ignored").stream().anyMatch(field -> "field".equals(field.stringValue())));
248246
}
249247

250-
public void test_ignore_above_index_level_setting() throws IOException {
248+
public void testIgnoreAboveIndexLevelSetting() throws IOException {
251249
// given
252250
final MapperService mapperService = createMapperService(
253251
Settings.builder()
@@ -269,7 +267,7 @@ public void test_ignore_above_index_level_setting() throws IOException {
269267
assertTrue(mapper.fieldType().ignoreAbove().isSet());
270268
}
271269

272-
public void test_ignore_above_index_level_setting_is_overridden_by_field_level_ignore_above_in_standard_indices() throws IOException {
270+
public void testIgnoreAboveIndexLevelSettingIsOverriddenByFieldLevelIgnoreAboveInStandardIndices() throws IOException {
273271
// given
274272
final MapperService mapperService = createMapperService(
275273
Settings.builder()
@@ -309,7 +307,7 @@ public void test_ignore_above_index_level_setting_is_overridden_by_field_level_i
309307
assertTrue(fieldMapper3.fieldType().ignoreAbove().isSet());
310308
}
311309

312-
public void test_ignore_above_index_level_setting_is_overridden_by_field_level_ignore_above_in_logsdb_indices() throws IOException {
310+
public void testIgnoreAboveIndexLevelSettingIsOverriddenByFieldLevelIgnoreAboveInLogsdbIndices() throws IOException {
313311
// given
314312
final MapperService mapperService = createMapperService(
315313
Settings.builder()
@@ -1066,7 +1064,7 @@ public void testFieldTypeDefault_IndexedFalseDocValuesFalse() throws IOException
10661064
assertFalse(mapper.fieldType().hasDocValuesSkipper());
10671065
}
10681066

1069-
public void test_value_is_stored_when_it_exceeds_ignore_above_and_field_is_not_a_multi_field() throws IOException {
1067+
public void testValueIsStoredWhenItExceedsIgnoreAboveAndFieldIsNotAMultiField() throws IOException {
10701068
// given
10711069
MapperService mapperService = createSytheticSourceMapperService(mapping(b -> {
10721070
b.startObject("potato");
@@ -1085,7 +1083,7 @@ public void test_value_is_stored_when_it_exceeds_ignore_above_and_field_is_not_a
10851083
assertThat(doc.rootDoc().getField(mapper.fieldType().syntheticSourceFallbackFieldName()), Matchers.notNullValue());
10861084
}
10871085

1088-
public void test_value_is_not_stored_when_it_exceeds_ignore_above_and_field_is_a_multi_field() throws IOException {
1086+
public void testValueIsNotStoredWhenItExceedsIgnoreAboveAndFieldIsAMultiField() throws IOException {
10891087
// given
10901088
MapperService mapperService = createSytheticSourceMapperService(mapping(b -> {
10911089
b.startObject("potato").field("type", "text");
@@ -1112,7 +1110,7 @@ public void test_value_is_not_stored_when_it_exceeds_ignore_above_and_field_is_a
11121110
assertThat(doc.rootDoc().getField(mapper.fieldType().syntheticSourceFallbackFieldName()), Matchers.nullValue());
11131111
}
11141112

1115-
public void test_value_exceeds_ignore_above_when_synthetic_source_disabled() throws IOException {
1113+
public void testValueExceedsIgnoreAboveWhenSyntheticSourceDisabled() throws IOException {
11161114
// given
11171115
final MapperService mapperService = createMapperService(mapping(b -> {
11181116
b.startObject("potato");

server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldTypeTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public void testGetTerms() throws IOException {
298298
}
299299
}
300300

301-
public void test_ignore_above_index_level_setting() {
301+
public void testIgnoreAboveIndexLevelSetting() {
302302
// given
303303
Settings settings = Settings.builder()
304304
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -330,7 +330,7 @@ public void test_ignore_above_index_level_setting() {
330330
assertEquals(123, fieldType.ignoreAbove().get());
331331
}
332332

333-
public void test_ignore_above_isSet_returns_true_when_ignore_above_is_given() {
333+
public void testIgnoreAboveIsSetReturnsTrueWhenIgnoreAboveIsGiven() {
334334
// given
335335
Settings settings = Settings.builder()
336336
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -362,7 +362,7 @@ public void test_ignore_above_isSet_returns_true_when_ignore_above_is_given() {
362362
assertEquals(123, fieldType.ignoreAbove().get());
363363
}
364364

365-
public void test_ignore_above_isSet_returns_false_when_ignore_above_is_not_given() {
365+
public void testIgnoreAboveIsSetReturnsFalseWhenIgnoreAboveIsNotGiven() {
366366
// given
367367
Settings settings = Settings.builder()
368368
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -393,7 +393,7 @@ public void test_ignore_above_isSet_returns_false_when_ignore_above_is_not_given
393393
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, fieldType.ignoreAbove().get());
394394
}
395395

396-
public void test_ignore_above_isSet_returns_false_when_ignore_above_is_given_but_its_the_same_as_default() {
396+
public void testIgnoreAboveIsSetReturnsFalseWhenIgnoreAboveIsGivenButItsTheSameAsDefault() {
397397
// given
398398
Settings settings = Settings.builder()
399399
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -425,7 +425,7 @@ public void test_ignore_above_isSet_returns_false_when_ignore_above_is_given_but
425425
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, fieldType.ignoreAbove().get());
426426
}
427427

428-
public void test_ignore_above_isSet_returns_false_when_ignore_above_is_given_but_its_the_same_as_default_for_logsdb_indices() {
428+
public void testIgnoreAboveIsSetReturnsFalseWhenIgnoreAboveIsGivenButItsTheSameAsDefaultForLogsdbIndices() {
429429
// given
430430
Settings settings = Settings.builder()
431431
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -457,7 +457,7 @@ public void test_ignore_above_isSet_returns_false_when_ignore_above_is_given_but
457457
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, fieldType.ignoreAbove().get());
458458
}
459459

460-
public void test_ignore_above_isSet_returns_true_when_ignore_above_is_given_as_logsdb_default_but_index_mod_is_not_logsdb() {
460+
public void testIgnoreAboveIsSetReturnsTrueWhenIgnoreAboveIsGivenAsLogsdbDefaultButIndexModIsNotLogsdb() {
461461
// given
462462
Settings settings = Settings.builder()
463463
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -489,7 +489,7 @@ public void test_ignore_above_isSet_returns_true_when_ignore_above_is_given_as_l
489489
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, fieldType.ignoreAbove().get());
490490
}
491491

492-
public void test_ignore_above_isSet_returns_true_when_ignore_above_is_configured_at_index_level() {
492+
public void testIgnoreAboveIsSetReturnsTrueWhenIgnoreAboveIsConfiguredAtIndexLevel() {
493493
// given
494494
Settings settings = Settings.builder()
495495
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -521,7 +521,7 @@ public void test_ignore_above_isSet_returns_true_when_ignore_above_is_configured
521521
assertEquals(123, fieldType.ignoreAbove().get());
522522
}
523523

524-
public void test_ignore_above_isSet_returns_false_for_non_primary_constructor() {
524+
public void testIgnoreAboveIsSetReturnsFalseForNonPrimaryConstructor() {
525525
// given
526526
KeywordFieldType fieldType1 = new KeywordFieldType("field");
527527
KeywordFieldType fieldType2 = new KeywordFieldType("field", mock(FieldType.class));

server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void testStoreParameterDefaults() throws IOException {
312312
}
313313
}
314314

315-
public void test_store_parameter_defaults_to_false_with_latest_index_version_when_synthetic_source_is_enabled() throws IOException {
315+
public void testStoreParameterDefaultsToFalseWithLatestIndexVersionWhenSyntheticSourceIsEnabled() throws IOException {
316316
var indexSettings = getIndexSettingsBuilder().put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic").build();
317317

318318
var mapping = mapping(b -> {

server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void testRangeIntervals() {
301301
);
302302
}
303303

304-
public void test_block_loader_uses_synthetic_source_delegate_when_ignore_above_is_not_set() {
304+
public void testBlockLoaderUsesSyntheticSourceDelegateWhenIgnoreAboveIsNotSet() {
305305
// given
306306
KeywordFieldMapper.KeywordFieldType syntheticSourceDelegate = new KeywordFieldMapper.KeywordFieldType(
307307
"child",
@@ -332,7 +332,7 @@ public void test_block_loader_uses_synthetic_source_delegate_when_ignore_above_i
332332
assertThat(((BlockLoader.Delegating) blockLoader).delegatingTo(), equalTo("child"));
333333
}
334334

335-
public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore_above_is_set() {
335+
public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSet() {
336336
// given
337337
Settings settings = Settings.builder()
338338
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
@@ -381,7 +381,7 @@ public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore
381381
assertFalse(blockLoader instanceof BlockLoader.Delegating);
382382
}
383383

384-
public void test_block_loader_does_not_use_synthetic_source_delegate_when_ignore_above_is_set_at_index_level() {
384+
public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSetAtIndexLevel() {
385385
// given
386386
Settings settings = Settings.builder()
387387
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())

0 commit comments

Comments
 (0)