diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-02-02 20:47:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-02 20:47:38 +0100 |
commit | 2d9e0965bd2fb10cbf5ffd47fa55a98aea5710b3 (patch) | |
tree | 2051e781b2a94083341681d74bbb5fa4a7e3a51e /container-search/src/main/java/com/yahoo/search/query/profile | |
parent | 99f3a7193090cfcd6b5fdbbe612f53d892f9d86b (diff) |
Revert "Allow extension of implicitly ref'ed query profile types"
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile')
6 files changed, 32 insertions, 62 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java index 11864e60cec..99f1e26b221 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java @@ -135,8 +135,8 @@ public class BackedOverridableQueryProfile extends OverridableQueryProfile imple @Override public List<String> getDimensions() { - List<String> dimensions = super.getDimensions(); - if (dimensions != null) return dimensions; + List<String> dimensions=super.getDimensions(); + if (dimensions!=null) return dimensions; return backingProfile.getDimensions(); } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java index 7ae18f96d86..e9ccdd22f98 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java @@ -100,7 +100,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable public QueryProfileType getType() { return type; } /** Sets the type of this, or set to null to not use any type checking in this profile */ - public void setType(QueryProfileType type) { this.type = type; } + public void setType(QueryProfileType type) { this.type=type; } /** Returns the virtual variants of this, or null if none */ public QueryProfileVariants getVariants() { return variants; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java index 5d4f39cecbf..b250560e2f3 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java @@ -70,7 +70,7 @@ public class QueryProfileProperties extends Properties { * @throws IllegalArgumentException if this property cannot be set in the wrapped query profile */ @Override - public void set(CompoundName name, Object value, Map<String, String> context) { + public void set(CompoundName name, Object value, Map<String,String> context) { // TODO: Refactor try { name = unalias(name, context); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java index 1b1cdce5890..33f07a58195 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileXMLReader.java @@ -33,7 +33,7 @@ public class QueryProfileXMLReader { * Reads all query profile xml files in a given directory, * and all type xml files from the immediate subdirectory "types/" (if any) * - * @throws IllegalArgumentException if the directory is not readable, or if there is some error in the XML + * @throws RuntimeException if <code>directory</code> is not a readable directory, or if there is some error in the XML */ public QueryProfileRegistry read(String directory) { List<NamedReader> queryProfileReaders = new ArrayList<>(); @@ -58,7 +58,7 @@ public class QueryProfileXMLReader { return read(queryProfileTypeReaders,queryProfileReaders); } catch (IOException e) { - throw new IllegalArgumentException("Could not read query profiles from '" + directory + "'", e); + throw new IllegalArgumentException("Could not read query profiles from '" + directory + "'",e); } finally { closeAll(queryProfileReaders); @@ -105,14 +105,14 @@ public class QueryProfileXMLReader { "' must be 'query-profile-type', not '" + root.getNodeName() + "'"); } - String idString = root.getAttribute("id"); + String idString=root.getAttribute("id"); if (idString == null || idString.equals("")) throw new IllegalArgumentException("'" + reader.getName() + "' has no 'id' attribute in the root element"); ComponentId id = new ComponentId(idString); - validateFileNameToId(reader.getName(), id,"query profile type"); + validateFileNameToId(reader.getName(),id,"query profile type"); QueryProfileType type = new QueryProfileType(id); - type.setMatchAsPath(XML.getChild(root, "match") != null); - type.setStrict(XML.getChild(root, "strict") != null); + type.setMatchAsPath(XML.getChild(root,"match") != null); + type.setStrict(XML.getChild(root,"strict") != null); registry.register(type); queryProfileTypeElements.add(root); } @@ -145,7 +145,7 @@ public class QueryProfileXMLReader { queryProfile.setType(type); } - Element dimensions = XML.getChild(root, "dimensions"); + Element dimensions = XML.getChild(root,"dimensions"); if (dimensions != null) queryProfile.setDimensions(toArray(XML.getValue(dimensions))); @@ -215,7 +215,7 @@ public class QueryProfileXMLReader { try { String fieldTypeName = field.getAttribute("type"); if (fieldTypeName == null) throw new IllegalArgumentException("Field '" + field + "' has no 'type' attribute"); - FieldType fieldType = FieldType.fromString(fieldTypeName, registry); + FieldType fieldType=FieldType.fromString(fieldTypeName,registry); type.addField(new FieldDescription(name, fieldType, field.getAttribute("alias"), diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java index 6c30f1a8b05..b8290fa092b 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java @@ -97,7 +97,7 @@ public class FieldDescription implements Comparable<FieldDescription> { this.type = type; // Forbidden until we can figure out the right semantics - if (name.isCompound() && ! aliases.isEmpty()) throw new IllegalArgumentException("Aliases are not allowed with compound names"); + if (name.isCompound() && ! aliases.isEmpty()) throw new IllegalArgumentException("Aliases is not allowed with compound names"); this.aliases = ImmutableList.copyOf(aliases); this.mandatory = mandatory; 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 e3696916c53..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 @@ -6,7 +6,6 @@ import com.google.common.collect.ImmutableMap; import com.yahoo.component.ComponentId; import com.yahoo.component.provider.FreezableSimpleComponent; import com.yahoo.processing.request.CompoundName; -import com.yahoo.search.query.profile.OverridableQueryProfile; import com.yahoo.search.query.profile.QueryProfile; import java.util.ArrayList; @@ -24,8 +23,6 @@ import static com.yahoo.text.Lowercase.toLowerCase; */ public class QueryProfileType extends FreezableSimpleComponent { - private static final String simpleClassName = QueryProfileType.class.getSimpleName(); - private final CompoundName componentIdAsCompoundName; /** The fields of this query profile type */ private Map<String, FieldDescription> fields; @@ -220,38 +217,25 @@ public class QueryProfileType extends FreezableSimpleComponent { /** Returns the type of the given query profile type declared as a field in this */ public QueryProfileType getType(String localName) { - FieldDescription fieldDescription = getField(localName); - if (fieldDescription == null) return null; + FieldDescription fieldDescription=getField(localName); + if (fieldDescription ==null) return null; if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType)) return null; return ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType(); } - /** Returns the field type of the given name under this, of null if none */ - public FieldType getFieldType(CompoundName name) { - FieldDescription field = getField(name.first()); - if (field == null) return null; - - FieldType fieldType = field.getType(); - if (name.size() == 1) return fieldType; - - if ( ! (fieldType instanceof QueryProfileFieldType)) return null; - - return ((QueryProfileFieldType)fieldType).getQueryProfileType().getFieldType(name.rest()); - } - /** * Returns the description of the field with the given name in this type or an inherited type * (depth first left to right search). Returns null if the field is not defined in this or an inherited profile. */ public FieldDescription getField(String name) { - FieldDescription field = fields.get(name); - if ( field != null ) return field; + FieldDescription field=fields.get(name); + if ( field!=null ) return field; if ( isFrozen() ) return null; // Inherited are collapsed into this for (QueryProfileType inheritedType : this.inherited() ) { - field = inheritedType.getField(name); - if (field != null) return field; + field=inheritedType.getField(name); + if (field!=null) return field; } return null; @@ -292,7 +276,7 @@ public class QueryProfileType extends FreezableSimpleComponent { // Add (/to) a query profile type containing the rest of the name. // (we do not need the field description settings for intermediate query profile types // as the leaf entry will enforce them) - QueryProfileType type = extendOrCreateQueryProfileType(name.first(), registry); + QueryProfileType type = getOrCreateQueryProfileType(name.first(), registry); type.addField(fieldDescription.withName(name.rest()), registry); } else { @@ -304,40 +288,27 @@ public class QueryProfileType extends FreezableSimpleComponent { addAlias(alias, fieldDescription.getName()); } - private QueryProfileType extendOrCreateQueryProfileType(String name, QueryProfileTypeRegistry registry) { - QueryProfileType type = null; + private QueryProfileType getOrCreateQueryProfileType(String name, QueryProfileTypeRegistry registry) { FieldDescription fieldDescription = getField(name); if (fieldDescription != null) { - if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType)) + if ( ! ( fieldDescription.getType() instanceof QueryProfileFieldType)) throw new IllegalArgumentException("Cannot use name '" + name + "' as a prefix because it is " + "already a " + fieldDescription.getType()); QueryProfileFieldType fieldType = (QueryProfileFieldType) fieldDescription.getType(); - type = fieldType.getQueryProfileType(); - } - - if (type == null) { - type = registry.getComponent(name); - if (type != null) { // found in registry but not already added in this type: extend it - type = new QueryProfileType(ComponentId.createAnonymousComponentId(type.getIdString()), - new HashMap<>(), - List.of(type)); + QueryProfileType type = fieldType.getQueryProfileType(); + if (type == null) { // an as-yet untyped reference; add type + type = new QueryProfileType(name); + registry.register(type.getId(), type); + fields.put(name, fieldDescription.withType(new QueryProfileFieldType(type))); } - } - - if (type == null) { // create it - type = new QueryProfileType(ComponentId.createAnonymousComponentId(name)); - } - - if (fieldDescription == null) { - fieldDescription = new FieldDescription(name, new QueryProfileFieldType(type)); + return type; } else { - fieldDescription = fieldDescription.withType(new QueryProfileFieldType(type)); + QueryProfileType type = new QueryProfileType(name); + registry.register(type.getId(), type); + fields.put(name, new FieldDescription(name, new QueryProfileFieldType(type))); + return type; } - - registry.register(type); - fields.put(name, fieldDescription); - return type; } private void addAlias(String alias, String field) { @@ -391,7 +362,6 @@ public class QueryProfileType extends FreezableSimpleComponent { return other.getId().equals(this.getId()); } - @Override public String toString() { return "query profile type '" + getId() + "'"; } |