Skip to content

Commit ee00d63

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent 3546602 commit ee00d63

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

server/src/test/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapperTests.java

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class SparseVectorFieldMapperTests extends SyntheticVectorsMapperTestCase
7575

7676
@Override
7777
protected Object getSampleValueForDocument() {
78-
//randomMap(1, 5, () -> Tuple.tuple(randomAlphaOfLengthBetween(5, 10), Float.valueOf(randomIntBetween(1, 127))))
78+
// randomMap(1, 5, () -> Tuple.tuple(randomAlphaOfLengthBetween(5, 10), Float.valueOf(randomIntBetween(1, 127))))
7979
Map<String, Float> map = new TreeMap<>();
8080

8181
// High weight tokens - low freq (should survive strict pruning)
@@ -700,10 +700,8 @@ public enum PruningScenario {
700700
STRICT_PRUNING // Stricter pruning with higher thresholds
701701
}
702702

703-
private void withSearchExecutionContext(
704-
MapperService mapperService,
705-
CheckedConsumer<SearchExecutionContext, IOException> consumer
706-
) throws IOException {
703+
private void withSearchExecutionContext(MapperService mapperService, CheckedConsumer<SearchExecutionContext, IOException> consumer)
704+
throws IOException {
707705
var mapper = mapperService.documentMapper();
708706
try (Directory directory = newDirectory()) {
709707
RandomIndexWriter iw = new RandomIndexWriter(random(), directory);
@@ -748,14 +746,11 @@ private void withSearchExecutionContext(
748746
}
749747
}
750748

751-
//@TestLogging(value = "org.elasticsearch.index.mapper.vectors.SparseVectorFieldMapperTests:TRACE", reason = "debug")
749+
// @TestLogging(value = "org.elasticsearch.index.mapper.vectors.SparseVectorFieldMapperTests:TRACE", reason = "debug")
752750
// TODO(mromaios): remove
753751
public void testTypeQueryFinalizationPruningScenarios() throws Exception {
754752
for (int i = 0; i < 60; i++) {
755-
runTestTypeQueryFinalization(
756-
randomFrom(IndexPruningScenario.values()),
757-
randomFrom(QueryPruningScenario.values())
758-
);
753+
runTestTypeQueryFinalization(randomFrom(IndexPruningScenario.values()), randomFrom(QueryPruningScenario.values()));
759754
}
760755
}
761756

@@ -774,8 +769,13 @@ public void testTypeQueryFinalizationDefaultsPreviousVersion() throws Exception
774769
SparseVectorFieldMapper.SparseVectorFieldType ft = (SparseVectorFieldMapper.SparseVectorFieldType) mapperService.fieldType(
775770
"field"
776771
);
777-
Query finalizedQuery = ft.finalizeSparseVectorQuery(context,
778-
"field", QUERY_VECTORS, queryPruneConfig.v1(), queryPruneConfig.v2());
772+
Query finalizedQuery = ft.finalizeSparseVectorQuery(
773+
context,
774+
"field",
775+
QUERY_VECTORS,
776+
queryPruneConfig.v1(),
777+
queryPruneConfig.v2()
778+
);
779779
// query should _not_ be pruned by default on older index versions
780780
assertQueryWasPruned(finalizedQuery, PruningScenario.NO_PRUNING);
781781
});
@@ -788,7 +788,7 @@ private XContentBuilder getIndexMapping(IndexPruningScenario pruningScenario) th
788788
case PRUNE_TRUE_NO_CONFIG -> fieldMapping(this::mappingWithIndexOptionsOnlyPruneTrue);
789789
case PRUNE_TRUE_WITH_CONFIG -> fieldMapping(this::minimalMappingWithExplicitIndexOptions);
790790
case PRUNE_NULL_NO_CONFIG -> fieldMapping(this::minimalMapping);
791-
//case PRUNE_NULL_NO_CONFIG, PREVIOUS_VERSION_NO_PRUNING -> fieldMapping(this::minimalMapping); //TODO(mromaios): revisit
791+
// case PRUNE_NULL_NO_CONFIG, PREVIOUS_VERSION_NO_PRUNING -> fieldMapping(this::minimalMapping); //TODO(mromaios): revisit
792792
};
793793
}
794794

@@ -813,25 +813,28 @@ private PruningScenario getEffectivePruningScenario(
813813
IndexPruningScenario indexPruningScenario,
814814
QueryPruningScenario queryPruningScenario
815815
) {
816-
//TODO(mromaios): Double check expected behavior with previous index version
817-
//if (indexPruningScenario == IndexPruningScenario.PREVIOUS_VERSION_NO_PRUNING) {
818-
// return PruningScenario.NO_PRUNING;
819-
//}
816+
// TODO(mromaios): Double check expected behavior with previous index version
817+
// if (indexPruningScenario == IndexPruningScenario.PREVIOUS_VERSION_NO_PRUNING) {
818+
// return PruningScenario.NO_PRUNING;
819+
// }
820820

821821
PruningScenario effectivePruningScenario = null;
822822
if (queryPruningScenario != null) {
823823
effectivePruningScenario = switch (queryPruningScenario) {
824-
case PRUNE_FALSE_NO_CONFIG, PRUNE_FALSE_WITH_CONFIG -> PruningScenario.NO_PRUNING;
825-
case PRUNE_TRUE_WITH_CONFIG -> PruningScenario.STRICT_PRUNING;
826-
case PRUNE_TRUE_NO_CONFIG, PRUNE_NULL_NO_CONFIG, PRUNE_NULL_WITH_CONFIG -> null; // Need to compare with indexPruningScenario
824+
case PRUNE_FALSE_NO_CONFIG, PRUNE_FALSE_WITH_CONFIG -> PruningScenario.NO_PRUNING;
825+
case PRUNE_TRUE_WITH_CONFIG -> PruningScenario.STRICT_PRUNING;
826+
case PRUNE_TRUE_NO_CONFIG, PRUNE_NULL_NO_CONFIG, PRUNE_NULL_WITH_CONFIG -> null; // Need to compare with
827+
// indexPruningScenario
827828
};
828829
}
829830

830831
if (effectivePruningScenario != null) {
831832
return effectivePruningScenario;
832833
}
833-
Set<IndexPruningScenario> indexOptionsWithoutConfig = EnumSet.of(IndexPruningScenario.PRUNE_NULL_NO_CONFIG,
834-
IndexPruningScenario.PRUNE_TRUE_NO_CONFIG);
834+
Set<IndexPruningScenario> indexOptionsWithoutConfig = EnumSet.of(
835+
IndexPruningScenario.PRUNE_NULL_NO_CONFIG,
836+
IndexPruningScenario.PRUNE_TRUE_NO_CONFIG
837+
);
835838

836839
if (queryPruningScenario == QueryPruningScenario.PRUNE_NULL_NO_CONFIG) {
837840
if (indexPruningScenario == IndexPruningScenario.PRUNE_FALSE_NO_CONFIG) return PruningScenario.NO_PRUNING;
@@ -862,7 +865,8 @@ public enum QueryPruningScenario {
862865
}
863866

864867
public enum IndexPruningScenario {
865-
//PREVIOUS_VERSION_NO_PRUNING, //TODO(mromaios): This fails when combined with query pruning that overrides the index options, check.
868+
// PREVIOUS_VERSION_NO_PRUNING, //TODO(mromaios): This fails when combined with query pruning that overrides the index options,
869+
// check.
866870
PRUNE_FALSE_NO_CONFIG,
867871
PRUNE_TRUE_NO_CONFIG,
868872
PRUNE_TRUE_WITH_CONFIG,
@@ -874,35 +878,41 @@ private Tuple<Boolean, TokenPruningConfig> getQueryPruneConfig(QueryPruningScena
874878
case PRUNE_FALSE_NO_CONFIG -> new Tuple<>(false, null);
875879
case PRUNE_FALSE_WITH_CONFIG -> new Tuple<>(false, new TokenPruningConfig());
876880
case PRUNE_TRUE_NO_CONFIG -> new Tuple<>(true, null);
877-
case PRUNE_TRUE_WITH_CONFIG -> new Tuple<>(true, new TokenPruningConfig(STRICT_TOKENS_FREQ_RATIO_THRESHOLD, STRICT_TOKENS_WEIGHT_THRESHOLD, false));
878-
case PRUNE_NULL_WITH_CONFIG -> new Tuple<>(null, new TokenPruningConfig(STRICT_TOKENS_FREQ_RATIO_THRESHOLD, STRICT_TOKENS_WEIGHT_THRESHOLD, false));
881+
case PRUNE_TRUE_WITH_CONFIG -> new Tuple<>(
882+
true,
883+
new TokenPruningConfig(STRICT_TOKENS_FREQ_RATIO_THRESHOLD, STRICT_TOKENS_WEIGHT_THRESHOLD, false)
884+
);
885+
case PRUNE_NULL_WITH_CONFIG -> new Tuple<>(
886+
null,
887+
new TokenPruningConfig(STRICT_TOKENS_FREQ_RATIO_THRESHOLD, STRICT_TOKENS_WEIGHT_THRESHOLD, false)
888+
);
879889
case PRUNE_NULL_NO_CONFIG -> new Tuple<>(null, null);
880890
};
881891
}
882892

883-
private void runTestTypeQueryFinalization(
884-
IndexPruningScenario indexPruningScenario,
885-
QueryPruningScenario queryPruningScenario
886-
) throws IOException {
887-
logger.debug("Running test with indexPruningScenario: {}, queryPruningScenario: {}",
888-
indexPruningScenario, queryPruningScenario);
893+
private void runTestTypeQueryFinalization(IndexPruningScenario indexPruningScenario, QueryPruningScenario queryPruningScenario)
894+
throws IOException {
895+
logger.debug("Running test with indexPruningScenario: {}, queryPruningScenario: {}", indexPruningScenario, queryPruningScenario);
889896
IndexVersion indexVersion = getIndexVersionForTest(
890-
//indexPruningScenario == IndexPruningScenario.PREVIOUS_VERSION_NO_PRUNING //TODO(mromaios): revisit, adding one specific UT for it for now
897+
// indexPruningScenario == IndexPruningScenario.PREVIOUS_VERSION_NO_PRUNING //TODO(mromaios): revisit, adding one specific UT
898+
// for it for now
891899
false
892900
);
893901
MapperService mapperService = createMapperService(indexVersion, getIndexMapping(indexPruningScenario));
894902
logger.debug("Index mapping: {}", mapperService.documentMapper().mappingSource().toString());
895903
Tuple<Boolean, TokenPruningConfig> queryPruneConfig = getQueryPruneConfig(queryPruningScenario);
896-
PruningScenario effectivePruningScenario = getEffectivePruningScenario(
897-
indexPruningScenario,
898-
queryPruningScenario
899-
);
904+
PruningScenario effectivePruningScenario = getEffectivePruningScenario(indexPruningScenario, queryPruningScenario);
900905
withSearchExecutionContext(mapperService, (context) -> {
901906
SparseVectorFieldMapper.SparseVectorFieldType ft = (SparseVectorFieldMapper.SparseVectorFieldType) mapperService.fieldType(
902907
"field"
903908
);
904-
Query finalizedQuery = ft.finalizeSparseVectorQuery(context, "field", QUERY_VECTORS, queryPruneConfig.v1(),
905-
queryPruneConfig.v2());
909+
Query finalizedQuery = ft.finalizeSparseVectorQuery(
910+
context,
911+
"field",
912+
QUERY_VECTORS,
913+
queryPruneConfig.v1(),
914+
queryPruneConfig.v2()
915+
);
906916
assertQueryWasPruned(finalizedQuery, effectivePruningScenario);
907917
});
908918
}

0 commit comments

Comments
 (0)