aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-02-08 12:28:33 +0100
committerJon Bratseth <bratseth@gmail.com>2022-02-08 12:28:33 +0100
commit5193d40052fa46bdc18940bad765a0b5195689ca (patch)
tree0c2229fd52853d88726441a2eacf19fc648043fd /container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
parentba895eb72333231b976274e5f68e2ce80c7c3bbd (diff)
Extract method
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java98
1 files changed, 49 insertions, 49 deletions
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 878a937ec67..f58395fd5bb 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
@@ -87,7 +87,6 @@ public class QueryProfileProperties extends Properties {
*/
@Override
public void set(CompoundName name, Object value, Map<String, String> context) {
- // TODO: Refactor
try {
name = unalias(name, context);
@@ -101,54 +100,8 @@ public class QueryProfileProperties extends Properties {
if (runtimeReference != null && ! runtimeReference.getSecond().isOverridable(name.rest(runtimeReference.getFirst().size()), context))
return;
- // Check types
- if ( ! profile.getTypes().isEmpty()) {
- QueryProfileType type;
- QueryProfileType explicitTypeFromField = null;
- for (int i = 0; i < name.size(); i++) {
- if (explicitTypeFromField != null)
- type = explicitTypeFromField;
- else
- type = profile.getType(name.first(i), context);
- if (type == null) continue;
-
- String localName = name.get(i);
- FieldDescription fieldDescription = type.getField(localName);
- if (fieldDescription == null && type.isStrict())
- throw new IllegalInputException("'" + localName + "' is not declared in " + type + ", and the type is strict");
- // TODO: In addition to strictness, check legality along the way
-
- if (fieldDescription != null) {
- if (i == name.size() - 1) { // at the end of the path, check the assignment type
- var conversionContext = new ConversionContext(localName, profile.getRegistry(), embedder, context);
- var convertedValue = fieldDescription.getType().convertFrom(value, conversionContext);
- if (convertedValue == null
- && fieldDescription.getType() instanceof QueryProfileFieldType
- && ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType() != null) {
- // Try the value of the query profile itself instead
- var queryProfileValueDescription = ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType().getField("");
- if (queryProfileValueDescription != null) {
- convertedValue = queryProfileValueDescription.getType().convertFrom(value, conversionContext);
- if (convertedValue == null)
- throw new IllegalInputException("'" + value + "' is neither a " +
- fieldDescription.getType().toInstanceDescription() + " nor a " +
- queryProfileValueDescription.getType().toInstanceDescription());
- }
- }
- else if (convertedValue == null)
- throw new IllegalInputException("'" + value + "' is not a " +
- fieldDescription.getType().toInstanceDescription());
-
- value = convertedValue;
- }
- else if (fieldDescription.getType() instanceof QueryProfileFieldType) {
- // If a type is specified, use that instead of the type implied by the name
- explicitTypeFromField = ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType();
- }
- }
-
- }
- }
+ if ( ! profile.getTypes().isEmpty())
+ value = convertByType(name, value, context);
if (value instanceof String && value.toString().startsWith("ref:")) {
if (profile.getRegistry() == null)
@@ -176,6 +129,53 @@ public class QueryProfileProperties extends Properties {
}
}
+ private Object convertByType(CompoundName name, Object value, Map<String, String> context) {
+ QueryProfileType type;
+ QueryProfileType explicitTypeFromField = null;
+ for (int i = 0; i < name.size(); i++) {
+ if (explicitTypeFromField != null)
+ type = explicitTypeFromField;
+ else
+ type = profile.getType(name.first(i), context);
+ if (type == null) continue;
+
+ String localName = name.get(i);
+ FieldDescription fieldDescription = type.getField(localName);
+ if (fieldDescription == null && type.isStrict())
+ throw new IllegalInputException("'" + localName + "' is not declared in " + type + ", and the type is strict");
+ // TODO: In addition to strictness, check legality along the way
+
+ if (fieldDescription != null) {
+ if (i == name.size() - 1) { // at the end of the path, check the assignment type
+ var conversionContext = new ConversionContext(localName, profile.getRegistry(), embedder, context);
+ var convertedValue = fieldDescription.getType().convertFrom(value, conversionContext);
+ if (convertedValue == null
+ && fieldDescription.getType() instanceof QueryProfileFieldType
+ && ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType() != null) {
+ // Try the value of the query profile itself instead
+ var queryProfileValueDescription = ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType().getField("");
+ if (queryProfileValueDescription != null) {
+ convertedValue = queryProfileValueDescription.getType().convertFrom(value, conversionContext);
+ if (convertedValue == null)
+ throw new IllegalInputException("'" + value + "' is neither a " +
+ fieldDescription.getType().toInstanceDescription() + " nor a " +
+ queryProfileValueDescription.getType().toInstanceDescription());
+ }
+ } else if (convertedValue == null)
+ throw new IllegalInputException("'" + value + "' is not a " +
+ fieldDescription.getType().toInstanceDescription());
+
+ value = convertedValue;
+ } else if (fieldDescription.getType() instanceof QueryProfileFieldType) {
+ // If a type is specified, use that instead of the type implied by the name
+ explicitTypeFromField = ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType();
+ }
+ }
+
+ }
+ return value;
+ }
+
@Override
public void clearAll(CompoundName name, Map<String, String> context) {
if (references == null)