Skip to content

Commit

Permalink
Rename QueryBuilderService, remove query name from inference metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kderusso committed Nov 27, 2024
1 parent 74b4346 commit 5118a7b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ static TransportVersion def(int id) {
public static final TransportVersion INGEST_PIPELINE_CONFIGURATION_AS_MAP = def(8_797_00_0);
public static final TransportVersion INDEXING_PRESSURE_THROTTLING_STATS = def(8_798_00_0);
public static final TransportVersion REINDEX_DATA_STREAMS = def(8_799_00_0);
public static final TransportVersion INFERENCE_FIELD_METADATA_STORE_QUERY_NAME = def(8_800_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

package org.elasticsearch.cluster.metadata;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.cluster.Diff;
import org.elasticsearch.cluster.SimpleDiffable;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -37,26 +36,17 @@ public final class InferenceFieldMetadata implements SimpleDiffable<InferenceFie
private static final String INFERENCE_ID_FIELD = "inference_id";
private static final String SEARCH_INFERENCE_ID_FIELD = "search_inference_id";
private static final String SOURCE_FIELDS_FIELD = "source_fields";
private static final String QUERY_NAME_FIELD = "query_name";

private final String name;
private final String inferenceId;
private final String searchInferenceId;
private final String[] sourceFields;
private final String queryName;

public InferenceFieldMetadata(
String name,
String inferenceId,
String searchInferenceId,
String[] sourceFields,
String queryName
) {

public InferenceFieldMetadata(String name, String inferenceId, String searchInferenceId, String[] sourceFields) {
this.name = Objects.requireNonNull(name);
this.inferenceId = Objects.requireNonNull(inferenceId);
this.searchInferenceId = Objects.requireNonNull(searchInferenceId);
this.sourceFields = Objects.requireNonNull(sourceFields);
this.queryName = Objects.requireNonNull(queryName);
}

public InferenceFieldMetadata(StreamInput input) throws IOException {
Expand All @@ -68,12 +58,6 @@ public InferenceFieldMetadata(StreamInput input) throws IOException {
this.searchInferenceId = this.inferenceId;
}
this.sourceFields = input.readStringArray();

if (input.getTransportVersion().onOrAfter(TransportVersions.INFERENCE_FIELD_METADATA_STORE_QUERY_NAME)) {
this.queryName = input.readOptionalString();
} else {
this.queryName = null;
}
}

@Override
Expand All @@ -84,7 +68,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(searchInferenceId);
}
out.writeStringArray(sourceFields);
out.writeOptionalString(queryName);
}

@Override
Expand All @@ -95,13 +78,12 @@ public boolean equals(Object o) {
return Objects.equals(name, that.name)
&& Objects.equals(inferenceId, that.inferenceId)
&& Objects.equals(searchInferenceId, that.searchInferenceId)
&& Arrays.equals(sourceFields, that.sourceFields)
&& Objects.equals(queryName, that.queryName);
&& Arrays.equals(sourceFields, that.sourceFields);
}

@Override
public int hashCode() {
int result = Objects.hash(name, inferenceId, searchInferenceId, queryName);
int result = Objects.hash(name, inferenceId, searchInferenceId);
result = 31 * result + Arrays.hashCode(sourceFields);
return result;
}
Expand All @@ -122,10 +104,6 @@ public String[] getSourceFields() {
return sourceFields;
}

public String getQueryName() {
return queryName;
}

public static Diff<InferenceFieldMetadata> readDiffFrom(StreamInput in) throws IOException {
return SimpleDiffable.readDiffFrom(InferenceFieldMetadata::new, in);
}
Expand All @@ -138,9 +116,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId);
}
builder.array(SOURCE_FIELDS_FIELD, sourceFields);
if (queryName != null) {
builder.field(QUERY_NAME_FIELD, queryName);
}
return builder.endObject();
}

Expand All @@ -163,8 +138,6 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws
inferenceId = parser.text();
} else if (SEARCH_INFERENCE_ID_FIELD.equals(currentFieldName)) {
searchInferenceId = parser.text();
} else if (QUERY_NAME_FIELD.equals(currentFieldName)) {
queryName = parser.text();
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (SOURCE_FIELDS_FIELD.equals(currentFieldName)) {
Expand All @@ -184,8 +157,7 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws
name,
inferenceId,
searchInferenceId == null ? inferenceId : searchInferenceId,
inputFields.toArray(String[]::new),
queryName
inputFields.toArray(String[]::new)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import java.util.function.BiFunction;

public class QueryBuilderService {
public class InferenceQueryBuilderService {
private final BiFunction<String, String, AbstractQueryBuilder<?>> defaultInferenceQueryBuilder;

QueryBuilderService(BiFunction<String, String, AbstractQueryBuilder<?>> defaultInferenceQueryBuilder) {
InferenceQueryBuilderService(BiFunction<String, String, AbstractQueryBuilder<?>> defaultInferenceQueryBuilder) {
this.defaultInferenceQueryBuilder = defaultInferenceQueryBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import java.util.Objects;
import java.util.function.BiFunction;

public class QueryBuilderServiceBuilder {
public class InferenceQueryBuilderServiceBuilder {
private PluginsService pluginsService;

public QueryBuilderServiceBuilder pluginsService(PluginsService pluginsService) {
public InferenceQueryBuilderServiceBuilder pluginsService(PluginsService pluginsService) {
this.pluginsService = pluginsService;
return this;
}

public QueryBuilderService build() {
public InferenceQueryBuilderService build() {
Objects.requireNonNull(pluginsService);

List<BiFunction<String, String, AbstractQueryBuilder<?>>> definedInferenceQueryBuilders = new ArrayList<>();
Expand All @@ -42,6 +42,6 @@ public QueryBuilderService build() {
);
}

return new QueryBuilderService(definedInferenceQueryBuilders.getFirst());
return new InferenceQueryBuilderService(definedInferenceQueryBuilders.getFirst());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
}

private QueryBuilder createInferenceSubQuery(
QueryBuilderService queryBuilderService,
InferenceQueryBuilderService inferenceQueryBuilderService,
String indexName,
String fieldName,
Object value
) {
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(queryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString()));
boolQueryBuilder.must(inferenceQueryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString()));
boolQueryBuilder.filter(new TermQueryBuilder(IndexFieldMapper.NAME, indexName));
return boolQueryBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class QueryRewriteContext {
protected Predicate<String> allowedFields;
private final ResolvedIndices resolvedIndices;
private final PointInTimeBuilder pit;
private final QueryBuilderService queryBuilderService;
private final InferenceQueryBuilderService inferenceQueryBuilderService;

public QueryRewriteContext(
final XContentParserConfiguration parserConfiguration,
Expand All @@ -88,7 +88,7 @@ public QueryRewriteContext(
final ScriptCompiler scriptService,
final ResolvedIndices resolvedIndices,
final PointInTimeBuilder pit,
final QueryBuilderService queryBuilderService
final InferenceQueryBuilderService inferenceQueryBuilderService
) {

this.parserConfiguration = parserConfiguration;
Expand All @@ -107,7 +107,7 @@ public QueryRewriteContext(
this.scriptService = scriptService;
this.resolvedIndices = resolvedIndices;
this.pit = pit;
this.queryBuilderService = queryBuilderService;
this.inferenceQueryBuilderService = inferenceQueryBuilderService;
}

public QueryRewriteContext(final XContentParserConfiguration parserConfiguration, final Client client, final LongSupplier nowInMillis) {
Expand Down Expand Up @@ -137,7 +137,7 @@ public QueryRewriteContext(
final LongSupplier nowInMillis,
final ResolvedIndices resolvedIndices,
final PointInTimeBuilder pit,
final QueryBuilderService queryBuilderService
final InferenceQueryBuilderService inferenceQueryBuilderService
) {
this(
parserConfiguration,
Expand All @@ -155,7 +155,7 @@ public QueryRewriteContext(
null,
resolvedIndices,
pit,
queryBuilderService
inferenceQueryBuilderService
);
}

Expand Down Expand Up @@ -435,7 +435,7 @@ public String getTierPreference() {
return value.split(",")[0].trim();
}

public QueryBuilderService getQueryBuilderService() {
return queryBuilderService;
public InferenceQueryBuilderService getQueryBuilderService() {
return inferenceQueryBuilderService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
import org.elasticsearch.index.query.CoordinatorRewriteContextProvider;
import org.elasticsearch.index.query.DataRewriteContext;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilderService;
import org.elasticsearch.index.query.QueryBuilderServiceBuilder;
import org.elasticsearch.index.query.InferenceQueryBuilderService;
import org.elasticsearch.index.query.InferenceQueryBuilderServiceBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.recovery.RecoveryStats;
import org.elasticsearch.index.refresh.RefreshStats;
Expand Down Expand Up @@ -263,7 +263,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final MapperMetrics mapperMetrics;
private final PostRecoveryMerger postRecoveryMerger;
private final List<SearchOperationListener> searchOperationListeners;
private final QueryBuilderService queryBuilderService;
private final InferenceQueryBuilderService inferenceQueryBuilderService;

@Override
protected void doStart() {
Expand Down Expand Up @@ -382,7 +382,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon
this.timestampFieldMapperService = new TimestampFieldMapperService(settings, threadPool, this);
this.postRecoveryMerger = new PostRecoveryMerger(settings, threadPool.executor(ThreadPool.Names.FORCE_MERGE), this::getShardOrNull);
this.searchOperationListeners = builder.searchOperationListener;
this.queryBuilderService = new QueryBuilderServiceBuilder().pluginsService(pluginsService).build();
this.inferenceQueryBuilderService = new InferenceQueryBuilderServiceBuilder().pluginsService(pluginsService).build();
}

private static final String DANGLING_INDICES_UPDATE_THREAD_NAME = "DanglingIndices#updateTask";
Expand Down Expand Up @@ -1769,7 +1769,7 @@ public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String
* Returns a new {@link QueryRewriteContext} with the given {@code now} provider
*/
public QueryRewriteContext getRewriteContext(LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit) {
return new QueryRewriteContext(parserConfig, client, nowInMillis, resolvedIndices, pit, queryBuilderService);
return new QueryRewriteContext(parserConfig, client, nowInMillis, resolvedIndices, pit, inferenceQueryBuilderService);
}

public DataRewriteContext getDataRewriteContext(LongSupplier nowInMillis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
import org.elasticsearch.xpack.core.ml.inference.results.TextExpansionResults;
import org.elasticsearch.xpack.inference.queries.SemanticQueryBuilder;
import org.elasticsearch.xpack.inference.queries.SemanticQueryBuilder;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -389,13 +387,7 @@ public InferenceFieldMetadata getMetadata(Set<String> sourcePaths) {
String[] copyFields = sourcePaths.toArray(String[]::new);
// ensure consistent order
Arrays.sort(copyFields);
return new InferenceFieldMetadata(
fullPath(),
fieldType().inferenceId,
fieldType().searchInferenceId,
copyFields,
SemanticQueryBuilder.NAME
);
return new InferenceFieldMetadata(fullPath(), fieldType().inferenceId, fieldType().searchInferenceId, copyFields);
}

@Override
Expand Down

0 comments on commit 5118a7b

Please sign in to comment.