Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <[email protected]>
  • Loading branch information
penghuo committed Jan 26, 2022
1 parent e9aed4d commit 04517f5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void copyCurrent(int slot) {
int compare(int from, int to) {
if (missingBucket) {
int result = missingOrder.compare(() -> Objects.isNull(values.get(from)), () -> Objects.isNull(values.get(to)), reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -116,7 +116,7 @@ int compare(int from, int to) {
int compareCurrent(int slot) {
if (missingBucket) {
int result = missingOrder.compare(() -> Objects.isNull(currentValue), () -> Objects.isNull(values.get(slot)), reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -127,7 +127,7 @@ int compareCurrent(int slot) {
int compareCurrentWithAfter() {
if (missingBucket) {
int result = missingOrder.compare(() -> Objects.isNull(currentValue), () -> Objects.isNull(afterValue), reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)
if (format != null) {
builder.field("format", format);
}
if (!MissingOrder.isDefault(missingOrder)) {
builder.field("missing_order", missingOrder.toString());
if (MissingOrder.isDefault(missingOrder) == false) {
builder.field(MissingOrder.NAME, missingOrder.toString());
}
builder.field("order", order);
doXContentBody(builder, params);
Expand Down Expand Up @@ -325,7 +325,7 @@ protected abstract CompositeValuesSourceConfig innerBuild(QueryShardContext quer

public final CompositeValuesSourceConfig build(QueryShardContext queryShardContext) throws IOException {
if (missingBucket == false && missingOrder != MissingOrder.DEFAULT) {
throw new IllegalArgumentException("missing_order required missing_bucket is true");
throw new IllegalArgumentException(MissingOrder.NAME + " require missing_bucket is true");
}
ValuesSourceConfig config = ValuesSourceConfig.resolve(
queryShardContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ boolean missingBucket() {
}

/**
* If true, an explicit `null bucket represents documents with missing values.
* Return the {@link MissingOrder} for the config.
*/
MissingOrder missingOrder() {
return missingOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.script.Script;
import org.opensearch.search.aggregations.bucket.missing.MissingOrder;
import org.opensearch.search.aggregations.support.ValueType;

import java.io.IOException;
Expand All @@ -54,7 +55,7 @@ public class CompositeValuesSourceParserHelper {
static <VB extends CompositeValuesSourceBuilder<VB>, T> void declareValuesSourceFields(AbstractObjectParser<VB, T> objectParser) {
objectParser.declareField(VB::field, XContentParser::text, new ParseField("field"), ObjectParser.ValueType.STRING);
objectParser.declareBoolean(VB::missingBucket, new ParseField("missing_bucket"));
objectParser.declareString(VB::missingOrder, new ParseField("missing_order"));
objectParser.declareString(VB::missingOrder, new ParseField(MissingOrder.NAME));

objectParser.declareField(VB::userValuetypeHint, p -> {
ValueType valueType = ValueType.lenientParse(p.text());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void copyCurrent(int slot) {
int compare(int from, int to) {
if (missingBucket) {
int result = missingOrder.compare(() -> bits.get(from) == false, () -> bits.get(to) == false, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -103,7 +103,7 @@ int compare(int from, int to) {
int compareCurrent(int slot) {
if (missingBucket) {
int result = missingOrder.compare(() -> missingCurrentValue, () -> bits.get(slot) == false, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -114,7 +114,7 @@ int compareCurrent(int slot) {
int compareCurrentWithAfter() {
if (missingBucket) {
int result = missingOrder.compare(() -> missingCurrentValue, () -> afterValue == null, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void copyCurrent(int slot) {
int compare(int from, int to) {
if (missingBucket) {
int result = missingOrder.compare(() -> values.get(from) == -1, () -> values.get(to) == -1, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -102,7 +102,7 @@ int compare(int from, int to) {
int compareCurrent(int slot) {
if (missingBucket) {
int result = missingOrder.compare(() -> currentValue == -1, () -> values.get(slot) == -1, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -113,7 +113,7 @@ int compareCurrent(int slot) {
int compareCurrentWithAfter() {
if (missingBucket) {
int result = missingOrder.compare(() -> currentValue == -1, () -> afterValueGlobalOrd == -1, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void copyCurrent(int slot) {
int compare(int from, int to) {
if (missingBucket) {
int result = missingOrder.compare(() -> bits.get(from) == false, () -> bits.get(to) == false, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -122,7 +122,7 @@ int compare(int from, int to) {
int compareCurrent(int slot) {
if (missingBucket) {
int result = missingOrder.compare(() -> missingCurrentValue, () -> bits.get(slot) == false, reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand All @@ -133,7 +133,7 @@ int compareCurrent(int slot) {
int compareCurrentWithAfter() {
if (missingBucket) {
int result = missingOrder.compare(() -> missingCurrentValue, () -> Objects.isNull(afterValue), reverseMul);
if (!MissingOrder.unknownOrder(result)) {
if (MissingOrder.unknownOrder(result) == false) {
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public String toString() {
}
};

public static final String NAME = "missing_order";

private static int MISSING_ORDER_UNKNOWN = Integer.MIN_VALUE;

public static MissingOrder readFromStream(StreamInput in) throws IOException {
Expand Down

0 comments on commit 04517f5

Please sign in to comment.