Skip to content

Commit 05af853

Browse files
committed
More tests
1 parent dadb6c5 commit 05af853

File tree

14 files changed

+364
-129
lines changed

14 files changed

+364
-129
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -824,16 +824,14 @@ NamedAnalyzer normalizer() {
824824
@Override
825825
public BlockLoader blockLoader(BlockLoaderContext blContext) {
826826
if (hasDocValues() && (blContext.fieldExtractPreference() != FieldExtractPreference.STORED || isSyntheticSourceEnabled())) {
827-
return switch (blContext.blockLoaderFunctionConfig()) {
828-
case null -> new BytesRefsFromOrdsBlockLoader(name());
829-
case BlockLoaderFunctionConfig.Named named -> switch (named.name()) {
830-
case "LENGTH" -> new Utf8CodePointsFromOrdsBlockLoader(named.warnings(), name());
831-
default -> throw new UnsupportedOperationException("unknown fusion config [" + named.name() + "]");
832-
};
833-
default -> throw new UnsupportedOperationException(
834-
"unknown fusion config [" + blContext.blockLoaderFunctionConfig() + "]"
835-
);
836-
};
827+
BlockLoaderFunctionConfig cfg = blContext.blockLoaderFunctionConfig();
828+
if (cfg == null) {
829+
return new BytesRefsFromOrdsBlockLoader(name());
830+
}
831+
if (cfg.function() == BlockLoaderFunctionConfig.Function.LENGTH) {
832+
return new Utf8CodePointsFromOrdsBlockLoader(((BlockLoaderFunctionConfig.JustWarnings) cfg).warnings(), name());
833+
}
834+
throw new UnsupportedOperationException("unknown fusion config [" + cfg.function() + "]");
837835
}
838836
if (blContext.blockLoaderFunctionConfig() != null) {
839837
throw new UnsupportedOperationException("function fusing only supported for doc values");
@@ -863,7 +861,7 @@ public Builder builder(BlockFactory factory, int expectedCount) {
863861
@Override
864862
public boolean supportsBlockLoaderConfig(BlockLoaderFunctionConfig config, FieldExtractPreference preference) {
865863
if (hasDocValues() && (preference != FieldExtractPreference.STORED || isSyntheticSourceEnabled())) {
866-
return config.name().equals("LENGTH");
864+
return config.function() == BlockLoaderFunctionConfig.Function.LENGTH;
867865
}
868866
return false;
869867
}

server/src/main/java/org/elasticsearch/index/mapper/blockloader/BlockLoaderFunctionConfig.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,16 @@ public interface BlockLoaderFunctionConfig {
2222
/**
2323
* Name used in descriptions.
2424
*/
25-
String name();
25+
Function function();
2626

27-
record Named(String name, Warnings warnings) implements BlockLoaderFunctionConfig {
28-
@Override
29-
public int hashCode() {
30-
return name.hashCode();
31-
}
27+
record JustWarnings(Function function, Warnings warnings) implements BlockLoaderFunctionConfig {}
3228

33-
@Override
34-
public boolean equals(Object o) {
35-
if (o == null || getClass() != o.getClass()) {
36-
return false;
37-
}
38-
Named named = (Named) o;
39-
return name.equals(named.name);
40-
}
29+
enum Function {
30+
LENGTH,
31+
V_COSINE,
32+
V_DOT_PRODUCT,
33+
V_HAMMING,
34+
V_L1NORM,
35+
V_L2NORM,
4136
}
4237
}

server/src/main/java/org/elasticsearch/index/mapper/blockloader/docvalues/DenseVectorBlockLoaderProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void process(byte[] vector, BlockLoader.DoubleBuilder builder) {
112112

113113
@Override
114114
public String name() {
115-
return config.similarityFunction().toString();
115+
return config.similarityFunction().function().toString();
116116
}
117117
}
118118
}

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,31 +2855,34 @@ public BlockLoader blockLoader(MappedFieldType.BlockLoaderContext blContext) {
28552855
return BlockLoader.CONSTANT_NULLS;
28562856
}
28572857

2858-
BlockLoaderFunctionConfig functionConfig = blContext.blockLoaderFunctionConfig();
2858+
BlockLoaderFunctionConfig cfg = blContext.blockLoaderFunctionConfig();
28592859
if (indexed) {
2860-
if (functionConfig == null) {
2860+
if (cfg == null) {
28612861
return new DenseVectorBlockLoader<>(
28622862
name(),
28632863
dims,
28642864
this,
28652865
new DenseVectorBlockLoaderProcessor.DenseVectorLoaderProcessor()
28662866
);
2867-
} else if (functionConfig instanceof VectorSimilarityFunctionConfig similarityConfig) {
2868-
if (getElementType() == ElementType.BYTE || getElementType() == ElementType.BIT) {
2869-
similarityConfig = similarityConfig.forByteVector();
2870-
}
2871-
return new DenseVectorBlockLoader<>(
2872-
name(),
2873-
dims,
2874-
this,
2875-
new DenseVectorBlockLoaderProcessor.DenseVectorSimilarityProcessor(similarityConfig)
2876-
);
2877-
} else {
2878-
throw new UnsupportedOperationException("Unknown block loader function config: " + functionConfig.getClass());
28792867
}
2868+
return switch (cfg.function()) {
2869+
case V_COSINE, V_DOT_PRODUCT, V_HAMMING, V_L1NORM, V_L2NORM -> {
2870+
VectorSimilarityFunctionConfig similarityConfig = (VectorSimilarityFunctionConfig) cfg;
2871+
if (getElementType() == ElementType.BYTE || getElementType() == ElementType.BIT) {
2872+
similarityConfig = similarityConfig.forByteVector();
2873+
}
2874+
yield new DenseVectorBlockLoader<>(
2875+
name(),
2876+
dims,
2877+
this,
2878+
new DenseVectorBlockLoaderProcessor.DenseVectorSimilarityProcessor(similarityConfig)
2879+
);
2880+
}
2881+
default -> throw new UnsupportedOperationException("Unknown block loader function config: " + cfg.function());
2882+
};
28802883
}
28812884

2882-
if (functionConfig != null) {
2885+
if (cfg != null) {
28832886
throw new IllegalArgumentException(
28842887
"Field ["
28852888
+ name()
@@ -2908,7 +2911,10 @@ public boolean supportsBlockLoaderConfig(BlockLoaderFunctionConfig config, Field
29082911
}
29092912

29102913
if (indexed) {
2911-
return config instanceof VectorSimilarityFunctionConfig;
2914+
return switch (config.function()) {
2915+
case V_COSINE, V_DOT_PRODUCT, V_HAMMING, V_L1NORM, V_L2NORM -> true;
2916+
default -> false;
2917+
};
29122918
}
29132919
return false;
29142920
}
@@ -3387,6 +3393,8 @@ public interface SimilarityFunction {
33873393
float calculateSimilarity(float[] leftVector, float[] rightVector);
33883394

33893395
float calculateSimilarity(byte[] leftVector, byte[] rightVector);
3396+
3397+
BlockLoaderFunctionConfig.Function function();
33903398
}
33913399

33923400
/**
@@ -3416,8 +3424,8 @@ public VectorSimilarityFunctionConfig forByteVector() {
34163424
}
34173425

34183426
@Override
3419-
public String name() {
3420-
return similarityFunction.toString();
3427+
public Function function() {
3428+
return similarityFunction.function();
34213429
}
34223430

34233431
public byte[] vectorAsBytes() {

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/FunctionEsField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public Exact getExactInfo() {
7979
* is a `FunctionEsField` which *looks* pushable without
8080
* the inexact match.
8181
*/
82-
return new Exact(false, "merged with " + functionConfig.name());
82+
return new Exact(false, "merged with " + functionConfig.function());
8383
}
8484
}

0 commit comments

Comments
 (0)