Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename field_masking_span to span_field_masking #1606

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.Objects;

public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
public static final String NAME = "field_masking_span";
public static final ParseField SPAN_FIELD_MASKING_FIELD = new ParseField("span_field_masking", "field_masking_span");

private static final ParseField FIELD_FIELD = new ParseField("field");
private static final ParseField QUERY_FIELD = new ParseField("query");
Expand Down Expand Up @@ -105,7 +105,7 @@ public SpanQueryBuilder innerQuery() {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME);
builder.startObject(SPAN_FIELD_MASKING_FIELD.getPreferredName());
builder.field(QUERY_FIELD.getPreferredName());
queryBuilder.toXContent(builder, params);
builder.field(FIELD_FIELD.getPreferredName(), fieldName);
Expand All @@ -129,13 +129,16 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
QueryBuilder query = parseInnerQueryBuilder(parser);
if (query instanceof SpanQueryBuilder == false) {
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
throw new ParsingException(
parser.getTokenLocation(),
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query must be of type span query"
);
}
inner = (SpanQueryBuilder) query;
} else {
throw new ParsingException(
parser.getTokenLocation(),
"[field_masking_span] query does not support [" + currentFieldName + "]"
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query does not support [" + currentFieldName + "]"
);
}
} else {
Expand All @@ -148,16 +151,22 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
} else {
throw new ParsingException(
parser.getTokenLocation(),
"[field_masking_span] query does not support [" + currentFieldName + "]"
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query does not support [" + currentFieldName + "]"
);
}
}
}
if (inner == null) {
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [query] span query clause");
throw new ParsingException(
parser.getTokenLocation(),
SPAN_FIELD_MASKING_FIELD.getPreferredName() + " must have [query] span query clause"
);
}
if (field == null) {
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [field] set for it");
throw new ParsingException(
parser.getTokenLocation(),
SPAN_FIELD_MASKING_FIELD.getPreferredName() + " must have [field] set for it"
);
}

FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder(inner, field);
Expand Down Expand Up @@ -190,6 +199,6 @@ protected boolean doEquals(FieldMaskingSpanQueryBuilder other) {

@Override
public String getWriteableName() {
return NAME;
return SPAN_FIELD_MASKING_FIELD.getPreferredName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ private void registerQueryParsers(List<SearchPlugin> plugins) {
);
registerQuery(
new QuerySpec<>(
FieldMaskingSpanQueryBuilder.NAME,
FieldMaskingSpanQueryBuilder.SPAN_FIELD_MASKING_FIELD,
FieldMaskingSpanQueryBuilder::new,
FieldMaskingSpanQueryBuilder::fromXContent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.io.IOException;

import static org.opensearch.index.query.FieldMaskingSpanQueryBuilder.SPAN_FIELD_MASKING_FIELD;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;

Expand Down Expand Up @@ -73,7 +74,9 @@ public void testIllegalArguments() {

public void testFromJson() throws IOException {
String json = "{\n"
+ " \"field_masking_span\" : {\n"
+ " \""
+ SPAN_FIELD_MASKING_FIELD.getPreferredName()
+ "\" : {\n"
+ " \"query\" : {\n"
+ " \"span_term\" : {\n"
+ " \"value\" : {\n"
Expand All @@ -92,4 +95,25 @@ public void testFromJson() throws IOException {
assertEquals(json, 42.0, parsed.boost(), 0.00001);
assertEquals(json, 0.23, parsed.innerQuery().boost(), 0.00001);
}

public void testDeprecatedName() throws IOException {
String json = "{\n"
+ " \"field_masking_span\" : {\n"
+ " \"query\" : {\n"
+ " \"span_term\" : {\n"
+ " \"value\" : {\n"
+ " \"value\" : \"foo\"\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"field\" : \"mapped_geo_shape\",\n"
+ " \"boost\" : 42.0,\n"
+ " \"_name\" : \"KPI\"\n"
+ " }\n"
+ "}";
FieldMaskingSpanQueryBuilder parsed = (FieldMaskingSpanQueryBuilder) parseQuery(json);
assertWarnings(
"Deprecated field [field_masking_span] used, expected [" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] instead"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void testRegisteredQueries() {
Set<String> registeredNonDeprecated = module.getNamedXContents()
.stream()
.filter(e -> e.categoryClass.equals(QueryBuilder.class))
.filter(e -> e.name.getDeprecatedNames().length == 0)
.filter(e -> e.name.getAllReplacedWith() == null)
.map(e -> e.name.getPreferredName())
.collect(toSet());
Set<String> registeredAll = module.getNamedXContents()
Expand Down Expand Up @@ -422,7 +422,6 @@ public List<RescorerSpec<?>> getRescorers() {
"constant_score",
"dis_max",
"exists",
"field_masking_span",
"function_score",
"fuzzy",
"geo_bounding_box",
Expand All @@ -448,6 +447,7 @@ public List<RescorerSpec<?>> getRescorers() {
"script_score",
"simple_query_string",
"span_containing",
"span_field_masking",
"span_first",
"span_gap",
"span_multi",
Expand All @@ -465,7 +465,7 @@ public List<RescorerSpec<?>> getRescorers() {
"distance_feature" };

// add here deprecated queries to make sure we log a deprecation warnings when they are used
private static final String[] DEPRECATED_QUERIES = new String[] { "common" };
private static final String[] DEPRECATED_QUERIES = new String[] { "common", "field_masking_span" };

/**
* Dummy test {@link AggregationBuilder} used to test registering aggregation builders.
Expand Down