aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-06-14 14:14:27 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-06-14 14:14:27 +0200
commit2858a63291a87d06592ddc45b5865f324fac214f (patch)
treece82850873fbc176a86e825cb52b478857091c44 /container-search/src/main/java/com/yahoo/search
parenta3c43101c7ed2cfe152e5a3222958974e0499e47 (diff)
Avoid creating CompoundNames on the fly.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java23
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java24
2 files changed, 30 insertions, 17 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java
index 766af8f05fd..7105ba8c7ad 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -236,15 +236,16 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
propertyAliases = ImmutableMap.copyOf(propertyAliasesBuilder);
}
private static void addAliases(QueryProfileType arguments, Map<String, CompoundName> aliases) {
- String prefix = getPrefix(arguments);
+ CompoundName prefix = getPrefix(arguments);
for (FieldDescription field : arguments.fields().values()) {
for (String alias : field.getAliases())
- aliases.put(alias, new CompoundName(prefix+field.getName()));
+ aliases.put(alias, prefix.append(field.getName()));
}
}
- private static String getPrefix(QueryProfileType type) {
- if (type.getId().getName().equals("native")) return ""; // The arguments of this directly
- return type.getId().getName() + ".";
+
+ private static CompoundName getPrefix(QueryProfileType type) {
+ if (type.getId().getName().equals("native")) return CompoundName.empty; // The arguments of this directly
+ return type.getComponentIdAsCompoundName();
}
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) {
@@ -391,22 +392,22 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
* dependent objects for the appropriate subset of the given property values
*/
private void setFieldsFrom(Properties properties, Map<String, String> context) {
- setFrom("", properties, Query.getArgumentType(), context);
+ setFrom(CompoundName.empty, properties, Query.getArgumentType(), context);
}
/**
* For each field in the given query profile type, take the corresponding value from originalProperties
* (if any) set it to properties(), recursively.
*/
- private void setFrom(String prefix, Properties originalProperties, QueryProfileType arguments, Map<String, String> context) {
- prefix = prefix + getPrefix(arguments);
+ private void setFrom(CompoundName prefix, Properties originalProperties, QueryProfileType arguments, Map<String, String> context) {
+ prefix = prefix.append(getPrefix(arguments));
for (FieldDescription field : arguments.fields().values()) {
if (field.getType() == FieldType.genericQueryProfileType) { // Generic map
- CompoundName fullName = new CompoundName(prefix + field.getName());
+ CompoundName fullName = prefix.append(field.getName());
for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName, context).entrySet()) {
try {
- properties().set(fullName + "." + entry.getKey(), entry.getValue(), context);
+ properties().set(fullName.append(entry.getKey()), entry.getValue(), context);
} catch (IllegalArgumentException e) {
throw new QueryException("Invalid request parameter", e);
}
@@ -416,7 +417,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
setFrom(prefix, originalProperties, ((QueryProfileFieldType)field.getType()).getQueryProfileType(), context);
}
else {
- CompoundName fullName = new CompoundName(prefix + field.getName());
+ CompoundName fullName = prefix.append(field.getName());
Object value = originalProperties.get(fullName, context);
if (value != null) {
try {
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
index 2ec3df4a976..07c9e4475ec 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
@@ -8,7 +8,11 @@ import com.yahoo.component.provider.FreezableSimpleComponent;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.query.profile.QueryProfile;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import static com.yahoo.text.Lowercase.toLowerCase;
@@ -19,11 +23,12 @@ import static com.yahoo.text.Lowercase.toLowerCase;
*/
public class QueryProfileType extends FreezableSimpleComponent {
+ private final CompoundName componentIdAsCompoundName;
/** The fields of this query profile type */
- private Map<String, FieldDescription> fields = new HashMap<>();
+ private Map<String, FieldDescription> fields;
/** The query profile types this inherits */
- private List<QueryProfileType> inherited = new ArrayList<>();
+ private List<QueryProfileType> inherited;
/** If this is true, keys which are not declared in this type cannot be set in instances */
private boolean strict = false;
@@ -41,15 +46,20 @@ public class QueryProfileType extends FreezableSimpleComponent {
}
public QueryProfileType(ComponentId id) {
+ this(id, new HashMap<>(), new ArrayList<>());
+ }
+
+ private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited) {
super(id);
QueryProfile.validateName(id.getName());
+ componentIdAsCompoundName = new CompoundName(getId().getName());
+ this.fields = fields;
+ this.inherited = inherited;
}
private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited,
boolean strict, boolean matchAsPath, boolean builtin, Map<String,String> aliases) {
- super(id);
- this.fields = new HashMap<>(fields);
- this.inherited = new ArrayList<>(inherited);
+ this(id, new HashMap<>(fields), new ArrayList<>(inherited));
this.strict = strict;
this.matchAsPath = matchAsPath;
this.builtin = builtin;
@@ -84,6 +94,8 @@ public class QueryProfileType extends FreezableSimpleComponent {
return new QueryProfileType(getId(), unfrozenFields, unfrozenInherited, strict, matchAsPath, builtin, aliases);
}
+ public CompoundName getComponentIdAsCompoundName() { return componentIdAsCompoundName; }
+
/** Mark this type as built into the system. Do not use */
public void setBuiltin(boolean builtin) { this.builtin=builtin; }