Skip to content

Commit

Permalink
Remove getDefaultScriptingLanguage from QueryParseContext (#23043)
Browse files Browse the repository at this point in the history
The method is not needed anymore, was needed only when we supported setting a legacy default lang, which was removed with #21607

Relates to #21607
  • Loading branch information
javanna authored Feb 9, 2017
1 parent f707132 commit b5f5356
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.Script;

import java.io.IOException;
import java.util.Objects;
Expand All @@ -35,16 +34,9 @@ public class QueryParseContext {
private static final ParseField CACHE_KEY = new ParseField("_cache_key").withAllDeprecated("Filters are always used as cache keys");

private final XContentParser parser;
private final String defaultScriptLanguage;

public QueryParseContext(XContentParser parser) {
this(Script.DEFAULT_SCRIPT_LANG, parser);
}

//TODO this constructor can be removed from master branch
public QueryParseContext(String defaultScriptLanguage, XContentParser parser) {
this.parser = Objects.requireNonNull(parser, "parser cannot be null");
this.defaultScriptLanguage = defaultScriptLanguage;
}

public XContentParser parser() {
Expand Down Expand Up @@ -121,12 +113,4 @@ public QueryBuilder parseInnerQueryBuilder() throws IOException {
}
return result;
}

/**
* Returns the default scripting language, that should be used if scripts don't specify the script language
* explicitly.
*/
public String getDefaultScriptLanguage() {
return defaultScriptLanguage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static ScriptQueryBuilder fromXContent(QueryParseContext parseContext) th
// skip
} else if (token == XContentParser.Token.START_OBJECT) {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, parseContext.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
}
Expand All @@ -110,7 +110,7 @@ public static ScriptQueryBuilder fromXContent(QueryParseContext parseContext) th
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
boost = parser.floatValue();
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, parseContext.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static ScriptScoreFunctionBuilder fromXContent(QueryParseContext parseCon
currentFieldName = parser.currentName();
} else {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, parseContext.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static SignificanceHeuristic parse(QueryParseContext context)
currentFieldName = parser.currentName();
} else {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ public static ScriptedMetricAggregationBuilder parse(String aggregationName, Que
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.VALUE_STRING) {
if (INIT_SCRIPT_FIELD.match(currentFieldName)) {
initScript = Script.parse(parser, context.getDefaultScriptLanguage());
initScript = Script.parse(parser);
} else if (MAP_SCRIPT_FIELD.match(currentFieldName)) {
mapScript = Script.parse(parser, context.getDefaultScriptLanguage());
mapScript = Script.parse(parser);
} else if (COMBINE_SCRIPT_FIELD.match(currentFieldName)) {
combineScript = Script.parse(parser, context.getDefaultScriptLanguage());
combineScript = Script.parse(parser);
} else if (REDUCE_SCRIPT_FIELD.match(currentFieldName)) {
reduceScript = Script.parse(parser, context.getDefaultScriptLanguage());
reduceScript = Script.parse(parser);
} else if (token == XContentParser.Token.START_OBJECT &&
PARAMS_FIELD.match(currentFieldName)) {
params = parser.map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (SearchSourceBuilder.SCRIPT_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else if (SearchSourceBuilder.IGNORE_FAILURE_FIELD.match(currentFieldName)) {
ignoreFailure = parser.booleanValue();
} else {
Expand All @@ -650,7 +650,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (SearchSourceBuilder.SCRIPT_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Unknown key for a " + token + " in [" + currentFieldName + "].",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static BucketScriptPipelineAggregationBuilder parse(String reducerName, Q
} else if (GAP_POLICY.match(currentFieldName)) {
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
Expand All @@ -200,7 +200,7 @@ public static BucketScriptPipelineAggregationBuilder parse(String reducerName, Q
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else if (BUCKETS_PATH.match(currentFieldName)) {
Map<String, Object> map = parser.map();
bucketsPathsMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static BucketSelectorPipelineAggregationBuilder parse(String reducerName,
} else if (GAP_POLICY.match(currentFieldName)) {
gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
Expand All @@ -163,7 +163,7 @@ public static BucketSelectorPipelineAggregationBuilder parse(String reducerName,
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else if (BUCKETS_PATH.match(currentFieldName)) {
Map<String, Object> map = parser.map();
bucketsPathsMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static <VS extends ValuesSource> void declareFields(

if (scriptable) {
objectParser.declareField(ValuesSourceAggregationBuilder::script,
(parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()),
(parser, context) -> Script.parse(parser),
Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ public ScriptField(QueryParseContext context) throws IOException {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (SCRIPT_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else if (IGNORE_FAILURE_FIELD.match(currentFieldName)) {
ignoreFailure = parser.booleanValue();
} else {
Expand All @@ -1368,7 +1368,7 @@ public ScriptField(QueryParseContext context) throws IOException {
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (SCRIPT_FIELD.match(currentFieldName)) {
script = Script.parse(parser, context.getDefaultScriptLanguage());
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName
+ "].", parser.getTokenLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params builderParams)
a -> new ScriptSortBuilder((Script) a[0], (ScriptSortType) a[1]));

static {
PARSER.declareField(constructorArg(), (parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()),
PARSER.declareField(constructorArg(), (parser, context) -> Script.parse(parser),
Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING);
PARSER.declareField(constructorArg(), p -> ScriptSortType.fromString(p.text()), TYPE_FIELD, ValueType.STRING);
PARSER.declareString((b, v) -> b.order(SortOrder.fromString(v)), ORDER_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ public static PhraseSuggestionBuilder fromXContent(XContentParser parser) throws
"suggester[phrase][collate] query already set, doesn't support additional ["
+ currentFieldName + "]");
}
Script template = Script.parse(parser, "mustache");
Script template = Script.parse(parser, Script.DEFAULT_TEMPLATE_LANG);
tmpSuggestion.collateQuery(template);
} else if (PhraseSuggestionBuilder.COLLATE_QUERY_PARAMS.match(currentFieldName)) {
tmpSuggestion.collateParams(parser.map());
Expand Down

0 comments on commit b5f5356

Please sign in to comment.