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

Switch type of expandNested from boolean to Boolean #2333

Merged
merged 1 commit into from
Dec 14, 2024
Merged
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
@@ -50,7 +50,7 @@ public static class CreateQueryRequest {
private QueryBuilder filter;
private QueryShardContext context;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Optional<QueryBuilder> getFilter() {
return Optional.ofNullable(filter);
@@ -63,6 +63,10 @@ public Optional<QueryShardContext> getContext() {
public Optional<RescoreContext> getRescoreContext() {
return Optional.ofNullable(rescoreContext);
}

public Optional<Boolean> getExpandNested() {
return Optional.ofNullable(expandNested);
}
Comment on lines +67 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add the default value directly here rather than in src/main/java/org/opensearch/knn/index/query/KNNQueryFactory.java ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will let the factory to decide on default value to be consist with other values. For example, rescoreContext's default value is null but we are still wrapping it as Optional instead of just returning null.

}

/**
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ public class KNNQueryBuilder extends AbstractQueryBuilder<KNNQueryBuilder> {
@Getter
private RescoreContext rescoreContext;
@Getter
private boolean expandNested;
private Boolean expandNested;

/**
* Constructs a new query with the given field name and vector
@@ -151,7 +151,7 @@ public static class Builder {
private String queryName;
private float boost = DEFAULT_BOOST;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Builder() {}

@@ -210,7 +210,7 @@ public Builder rescoreContext(RescoreContext rescoreContext) {
return this;
}

public Builder expandNested(boolean expandNested) {
public Builder expandNested(Boolean expandNested) {
this.expandNested = expandNested;
return this;
}
@@ -330,7 +330,7 @@ public KNNQueryBuilder(String fieldName, float[] vector, int k, QueryBuilder fil
this.maxDistance = null;
this.minScore = null;
this.rescoreContext = null;
this.expandNested = false;
this.expandNested = null;
}

public static void initialize(ModelDao modelDao) {
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public static Query create(CreateQueryRequest createQueryRequest) {
final Map<String, ?> methodParameters = createQueryRequest.getMethodParameters();
final RescoreContext rescoreContext = createQueryRequest.getRescoreContext().orElse(null);
final KNNEngine knnEngine = createQueryRequest.getKnnEngine();
final boolean expandNested = createQueryRequest.isExpandNested();
final boolean expandNested = createQueryRequest.getExpandNested().orElse(false);
BitSetProducer parentFilter = null;
if (createQueryRequest.getContext().isPresent()) {
QueryShardContext context = createQueryRequest.getContext().get();
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public static KNNQueryBuilder.Builder streamInput(StreamInput in, Function<Strin
}

if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
builder.expandNested(in.readBoolean());
builder.expandNested(in.readOptionalBoolean());
}

return builder;
@@ -169,7 +169,7 @@ public static void streamOutput(StreamOutput out, KNNQueryBuilder builder, Funct
RescoreParser.streamOutput(out, builder.getRescoreContext());
}
if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
out.writeBoolean(builder.isExpandNested());
out.writeOptionalBoolean(builder.getExpandNested());
}
}

@@ -245,8 +245,8 @@ public static void toXContent(XContentBuilder builder, ToXContent.Params params,
if (knnQueryBuilder.queryName() != null) {
builder.field(NAME_FIELD.getPreferredName(), knnQueryBuilder.queryName());
}
if (knnQueryBuilder.isExpandNested()) {
builder.field(EXPAND_NESTED, knnQueryBuilder.isExpandNested());
if (knnQueryBuilder.getExpandNested() != null) {
builder.field(EXPAND_NESTED, knnQueryBuilder.getExpandNested());
}

builder.endObject();