Skip to content

Commit

Permalink
s/defaultFields/defaultField
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Nov 6, 2024
1 parent 8503c6d commit ee4ffeb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ public static Builder builder(QueryRewriteContext queryRewriteContext) {
private QueryRewriteContext queryRewriteContext;
private final boolean caseInsensitive;
private final ZoneId timeZone;
private final String defaultField;

private final String defaultFields;

public KqlParsingContext(QueryRewriteContext queryRewriteContext, boolean caseInsensitive, ZoneId timeZone, String defaultFields) {
public KqlParsingContext(QueryRewriteContext queryRewriteContext, boolean caseInsensitive, ZoneId timeZone, String defaultField) {
this.queryRewriteContext = queryRewriteContext;
this.caseInsensitive = caseInsensitive;
this.timeZone = timeZone;
this.defaultFields = defaultFields;
this.defaultField = defaultField;
}

public Iterable<Tuple<String, MappedFieldType>> resolveFields(KqlBaseParser.FieldNameContext fieldNameContext) {
Expand Down Expand Up @@ -98,14 +97,14 @@ public static class Builder {
private final QueryRewriteContext queryRewriteContext;
private boolean caseInsensitive = true;
private ZoneId timeZone = null;
private String defaultFields = null;
private String defaultField = null;

private Builder(QueryRewriteContext queryRewriteContext) {
this.queryRewriteContext = queryRewriteContext;
}

public KqlParsingContext build() {
return new KqlParsingContext(queryRewriteContext, caseInsensitive, timeZone, defaultFields);
return new KqlParsingContext(queryRewriteContext, caseInsensitive, timeZone, defaultField);
}

public Builder caseInsensitive(boolean caseInsensitive) {
Expand All @@ -118,8 +117,8 @@ public Builder timeZone(ZoneId timeZone) {
return this;
}

public Builder defaultFields(String defaultFields) {
this.defaultFields = defaultFields;
public Builder defaultField(String defaultField) {
this.defaultField = defaultField;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class KqlQueryBuilder extends AbstractQueryBuilder<KqlQueryBuilder> {
}

if (a[3] != null) {
kqlQuery.defaultFields((String) a[3]);
kqlQuery.defaultField((String) a[3]);
}

return kqlQuery;
Expand All @@ -71,7 +71,7 @@ public class KqlQueryBuilder extends AbstractQueryBuilder<KqlQueryBuilder> {
private final String query;
private boolean caseInsensitive;
private ZoneId timeZone;
private String defaultFields;
private String defaultField;

public KqlQueryBuilder(String query) {
this.query = Objects.requireNonNull(query, "query can not be null");
Expand All @@ -82,7 +82,7 @@ public KqlQueryBuilder(StreamInput in) throws IOException {
query = in.readString();
caseInsensitive = in.readBoolean();
timeZone = in.readOptionalZoneId();
defaultFields = in.readOptionalString();
defaultField = in.readOptionalString();
}

public static KqlQueryBuilder fromXContent(XContentParser parser) {
Expand Down Expand Up @@ -120,12 +120,12 @@ public KqlQueryBuilder timeZone(String timeZone) {
return this;
}

public String defaultFields() {
return defaultFields;
public String defaultField() {
return defaultField;
}

public KqlQueryBuilder defaultFields(String defaultFields) {
this.defaultFields = defaultFields;
public KqlQueryBuilder defaultField(String defaultField) {
this.defaultField = defaultField;
return this;
}

Expand All @@ -136,8 +136,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field(QUERY_FIELD.getPreferredName(), query);
builder.field(CASE_INSENSITIVE_FIELD.getPreferredName(), caseInsensitive);

if (defaultFields != null) {
builder.field(DEFAULT_FIELD_FIELD.getPreferredName(), defaultFields);
if (defaultField != null) {
builder.field(DEFAULT_FIELD_FIELD.getPreferredName(), defaultField);
}

if (timeZone != null) {
Expand Down Expand Up @@ -170,7 +170,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeString(query);
out.writeBoolean(caseInsensitive);
out.writeOptionalZoneId(timeZone);
out.writeOptionalString(defaultFields);
out.writeOptionalString(defaultField);
}

@Override
Expand All @@ -180,22 +180,22 @@ public String getWriteableName() {

@Override
protected int doHashCode() {
return Objects.hash(query, caseInsensitive, timeZone, defaultFields);
return Objects.hash(query, caseInsensitive, timeZone, defaultField);
}

@Override
protected boolean doEquals(KqlQueryBuilder other) {
return Objects.equals(query, other.query)
&& Objects.equals(timeZone, other.timeZone)
&& Objects.equals(defaultFields, other.defaultFields)
&& Objects.equals(defaultField, other.defaultField)
&& caseInsensitive == other.caseInsensitive;
}

private KqlParsingContext createKqlParserContext(QueryRewriteContext queryRewriteContext) {
return KqlParsingContext.builder(queryRewriteContext)
.caseInsensitive(caseInsensitive)
.timeZone(timeZone)
.defaultFields(defaultFields)
.defaultField(defaultField)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected KqlQueryBuilder doCreateTestQueryBuilder() {
}

if (randomBoolean()) {
kqlQueryBuilder.defaultFields(randomFrom("*", "mapped_*", KEYWORD_FIELD_NAME, TEXT_FIELD_NAME));
kqlQueryBuilder.defaultField(randomFrom("*", "mapped_*", KEYWORD_FIELD_NAME, TEXT_FIELD_NAME));
}

return kqlQueryBuilder;
Expand All @@ -57,7 +57,7 @@ public KqlQueryBuilder mutateInstance(KqlQueryBuilder instance) throws IOExcepti
KqlQueryBuilder kqlQueryBuilder = new KqlQueryBuilder(randomValueOtherThan(instance.queryString(), this::generateRandomKqlQuery))
.caseInsensitive(instance.caseInsensitive())
.timeZone(instance.timeZone() != null ? instance.timeZone().getId() : null)
.defaultFields(instance.defaultFields());
.defaultField(instance.defaultField());

if (kqlQueryBuilder.queryString().equals(instance.queryString()) == false) {
return kqlQueryBuilder;
Expand All @@ -68,12 +68,12 @@ public KqlQueryBuilder mutateInstance(KqlQueryBuilder instance) throws IOExcepti
kqlQueryBuilder.caseInsensitive(instance.caseInsensitive() == false);
}
case 1 -> {
if (randomBoolean() && instance.defaultFields() != null) {
kqlQueryBuilder.defaultFields(null);
if (randomBoolean() && instance.defaultField() != null) {
kqlQueryBuilder.defaultField(null);
} else {
kqlQueryBuilder.defaultFields(
kqlQueryBuilder.defaultField(
randomValueOtherThan(
instance.defaultFields(),
instance.defaultField(),
() -> randomFrom("*", "mapped_*", KEYWORD_FIELD_NAME, TEXT_FIELD_NAME)
)
);
Expand Down

0 comments on commit ee4ffeb

Please sign in to comment.