aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-08-05 12:04:41 +0200
committerJon Bratseth <bratseth@gmail.com>2020-08-05 12:04:41 +0200
commit3ef825fc121ab64c2ae643f4a86445e449dfef49 (patch)
tree9068636396146f5178a588e603425c953eb9ba42 /container-search
parent75b7675c38fddf27daf17bcb46fc575d8dc8049e (diff)
Remove incorrect provenance info
When we combine all resolutions of some value the provenance information carried by the value becomes ptoentially incorrect. Since we do this for efficiency and tracking provenance info is just helper functionality, we remove the provenance info in these cases.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java8
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java23
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java16
5 files changed, 41 insertions, 10 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index 37a75f39e87..fb83f194cc5 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -6168,6 +6168,8 @@
"public boolean isQueryProfile()",
"public com.yahoo.search.query.profile.types.QueryProfileType queryProfileType()",
"public com.yahoo.search.query.profile.compiled.ValueWithSource withValue(java.lang.Object)",
+ "public com.yahoo.search.query.profile.compiled.ValueWithSource withSource(java.lang.String)",
+ "public com.yahoo.search.query.profile.compiled.ValueWithSource withVariant(java.util.Optional)",
"public java.util.Optional variant()",
"public int hashCode()",
"public boolean equals(java.lang.Object)",
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
index 9eb50c0f72e..7c3307223c3 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
@@ -21,7 +21,7 @@ public class DimensionValues implements Comparable<DimensionValues> {
public static final DimensionValues empty = new DimensionValues(new String[] {});
public static DimensionValues createFrom(String[] values) {
- if (values==null || values.length==0 || containsAllNulls(values)) return empty;
+ if (values == null || values.length == 0 || containsAllNulls(values)) return empty;
return new DimensionValues(values);
}
@@ -34,10 +34,10 @@ public class DimensionValues implements Comparable<DimensionValues> {
*/
private DimensionValues(String[] values) {
if (values == null) throw new NullPointerException("Dimension values cannot be null");
- this.values=Arrays.copyOf(values, values.length);
+ this.values = Arrays.copyOf(values, values.length);
}
- /** Returns true if this is has the same value every place it has a value as the givenValues. */
+ /** Returns true if this is has the same value every place it has a value as the given values. */
public boolean matches(DimensionValues givenValues) {
for (int i = 0; i < this.size() || i < givenValues.size() ; i++)
if ( ! matches(this.get(i), givenValues.get(i)))
@@ -73,7 +73,7 @@ public class DimensionValues implements Comparable<DimensionValues> {
/** Helper method which uses compareTo to return whether this is most specific */
public boolean isMoreSpecificThan(DimensionValues other) {
- return this.compareTo(other)<0;
+ return this.compareTo(other) < 0;
}
@Override
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
index c6b0f4a533b..d3abbbe4097 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
@@ -180,6 +180,8 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable
public final Object get(CompoundName name, Map<String, String> context, Properties substitution) {
ValueWithSource value = entries.get(name, context);
if (value == null) return null;
+ if (name.last().equals("streams"))
+ System.out.println(value);
return substitute(value.value(), context, substitution);
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
index cd1eabc2e32..a44ce2034fc 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/DimensionalValue.java
@@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
/**
@@ -83,7 +84,7 @@ public class DimensionalValue<VALUE> {
variant = new Value.Builder<>(value);
buildableVariants.put(value, variant);
}
- variant.addVariant(variantBinding);
+ variant.addVariant(variantBinding, value);
}
public DimensionalValue<VALUE> build(Map<CompoundName, DimensionalValue.Builder<VALUE>> entries) {
@@ -140,7 +141,7 @@ public class DimensionalValue<VALUE> {
private static class Builder<VALUE> {
- private final VALUE value;
+ private VALUE value;
/**
* The set of bindings this value is for.
@@ -154,8 +155,24 @@ public class DimensionalValue<VALUE> {
}
/** Add a binding this holds for */
- public void addVariant(DimensionBinding binding) {
+ @SuppressWarnings("unchecked")
+ public void addVariant(DimensionBinding binding, VALUE newValue) {
variants.add(Binding.createFrom(binding));
+
+ // We're combining values for efficiency, so remove incorrect provenance info
+ if (value instanceof ValueWithSource) {
+ ValueWithSource v1 = (ValueWithSource)value;
+ ValueWithSource v2 = (ValueWithSource)newValue;
+
+ if (v1.source() != null && ! v1.source().equals(v2.source()))
+ v1 = v1.withSource(null);
+
+ // We could keep the more general variant here (when matching), but that situation is rare
+ if (v1.variant().isPresent() && ! v1.variant().equals(v2.variant()))
+ v1 = v1.withVariant(Optional.empty());
+
+ value = (VALUE)v1;
+ }
}
/** Remove variants that are specializations of other variants in this */
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java
index d2c4eaaec9b..53a29b74813 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java
@@ -64,6 +64,14 @@ public class ValueWithSource {
return new ValueWithSource(value, source, isUnoverridable, isQueryProfile, type, variant);
}
+ public ValueWithSource withSource(String source) {
+ return new ValueWithSource(value, source, isUnoverridable, isQueryProfile, type, variant);
+ }
+
+ public ValueWithSource withVariant(Optional<DimensionValues> variant) {
+ return new ValueWithSource(value, source, isUnoverridable, isQueryProfile, type, variant.orElse(null));
+ }
+
/** Returns the variant having this value, or empty if it's not in a variant */
public Optional<DimensionValues> variant() { return Optional.ofNullable(variant); }
@@ -87,10 +95,12 @@ public class ValueWithSource {
@Override
public String toString() {
- return value +
- " (from query profile '" + source + "'" +
+ if (source == null && variant == null) return value.toString();
+
+ return value + " (" +
+ ( source != null ? "from query profile '" + source + "'" : "") +
( variant != null ? " variant " + variant : "") +
- ")";
+ ")";
}
}