Skip to content

Commit bcd79b6

Browse files
committed
Add missing method and test for missing methods
Signed-off-by: Michael Froh <[email protected]>
1 parent 5180b1a commit bcd79b6

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.mapper;
10+
11+
import org.opensearch.test.OpenSearchTestCase;
12+
13+
import java.lang.reflect.Method;
14+
import java.lang.reflect.Modifier;
15+
import java.util.Arrays;
16+
import java.util.HashSet;
17+
import java.util.Objects;
18+
import java.util.Set;
19+
20+
public class FilterFieldTypeTest extends OpenSearchTestCase {
21+
22+
private static final class MethodSignature {
23+
private final String name;
24+
private final Class<?> returnType;
25+
private final Class<?>[] parameterTypes;
26+
27+
public MethodSignature(String name, Class<?> returnType, Class<?>[] parameterTypes) {
28+
this.name = name;
29+
this.returnType = returnType;
30+
this.parameterTypes = parameterTypes;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (o == null || getClass() != o.getClass()) return false;
36+
MethodSignature that = (MethodSignature) o;
37+
return Objects.equals(name, that.name)
38+
&& Objects.equals(returnType, that.returnType)
39+
&& Objects.deepEquals(parameterTypes, that.parameterTypes);
40+
}
41+
42+
@Override
43+
public int hashCode() {
44+
return Objects.hash(name, returnType, Arrays.hashCode(parameterTypes));
45+
}
46+
}
47+
48+
private static final Set<MethodSignature> EXCLUDED_SIGNATURES = Set.of(new MethodSignature("typeName", String.class, new Class<?>[0]));
49+
50+
public void testAllMethodsDelegated() {
51+
Method[] mappedFieldTypeMethods = MappedFieldType.class.getMethods();
52+
Method[] filterFieldTypeMethods = FilterFieldType.class.getMethods();
53+
54+
Set<MethodSignature> mappedFieldTypeMethodSignatures = new HashSet<>();
55+
for (Method method : mappedFieldTypeMethods) {
56+
if (method.getDeclaringClass() == MappedFieldType.class
57+
&& Modifier.isFinal(method.getModifiers()) == false
58+
&& Modifier.isStatic(method.getModifiers()) == false) {
59+
mappedFieldTypeMethodSignatures.add(
60+
new MethodSignature(method.getName(), method.getReturnType(), method.getParameterTypes())
61+
);
62+
}
63+
}
64+
65+
Set<MethodSignature> filterFieldTypeMethodSignatures = new HashSet<>();
66+
for (Method method : filterFieldTypeMethods) {
67+
if (method.getDeclaringClass() == FilterFieldType.class) {
68+
filterFieldTypeMethodSignatures.add(
69+
new MethodSignature(method.getName(), method.getReturnType(), method.getParameterTypes())
70+
);
71+
}
72+
}
73+
for (MethodSignature methodSignature : mappedFieldTypeMethodSignatures) {
74+
if (filterFieldTypeMethodSignatures.contains(methodSignature)) {
75+
assertFalse(
76+
"Method " + methodSignature.name + " should NOT be implemented in " + FilterFieldType.class.getSimpleName(),
77+
EXCLUDED_SIGNATURES.contains(methodSignature)
78+
);
79+
} else {
80+
assertTrue(
81+
"Method " + methodSignature.name + " should be implemented in " + FilterFieldType.class.getSimpleName(),
82+
EXCLUDED_SIGNATURES.contains(methodSignature)
83+
);
84+
}
85+
}
86+
}
87+
88+
}

server/src/main/java/org/opensearch/index/mapper/FilterFieldType.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.opensearch.common.time.DateMathParser;
2020
import org.opensearch.common.unit.Fuzziness;
2121
import org.opensearch.index.analysis.NamedAnalyzer;
22+
import org.opensearch.index.fielddata.IndexFieldData;
2223
import org.opensearch.index.query.IntervalMode;
2324
import org.opensearch.index.query.QueryRewriteContext;
2425
import org.opensearch.index.query.QueryShardContext;
@@ -30,6 +31,7 @@
3031
import java.util.List;
3132
import java.util.Map;
3233
import java.util.function.Function;
34+
import java.util.function.Supplier;
3335

3436
public abstract class FilterFieldType<T extends MappedFieldType> extends MappedFieldType {
3537
protected final T delegate;
@@ -271,6 +273,11 @@ public TextSearchInfo getTextSearchInfo() {
271273
return delegate.getTextSearchInfo();
272274
}
273275

276+
@Override
277+
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
278+
return delegate.fielddataBuilder(fullyQualifiedIndexName, searchLookup);
279+
}
280+
274281
@Override
275282
public MappedFieldType unwrap() {
276283
return delegate.unwrap();

0 commit comments

Comments
 (0)