summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java3
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java7
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/AttributesImplicitWord.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/MutableAttributes.java28
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java1
-rw-r--r--config-model/src/main/javacc/SDParser.jj16
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java59
7 files changed, 108 insertions, 8 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
index 81e44850e71..bdd027f4687 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
@@ -52,6 +52,7 @@ public final class Attribute implements Cloneable, Serializable {
private boolean fastSearch = false;
private boolean fastAccess = false;
private boolean huge = false;
+ private boolean mutable = false;
private int arity = BooleanIndexDefinition.DEFAULT_ARITY;
private long lowerBound = BooleanIndexDefinition.DEFAULT_LOWER_BOUND;
private long upperBound = BooleanIndexDefinition.DEFAULT_UPPER_BOUND;
@@ -181,6 +182,7 @@ public final class Attribute implements Cloneable, Serializable {
public boolean isFastAccess() { return fastAccess; }
public boolean isHuge() { return huge; }
public boolean isPosition() { return isPosition; }
+ public boolean isMutable() { return mutable; }
public int arity() { return arity; }
public long lowerBound() { return lowerBound; }
@@ -205,6 +207,7 @@ public final class Attribute implements Cloneable, Serializable {
public void setHuge(boolean huge) { this.huge = huge; }
public void setFastAccess(boolean fastAccess) { this.fastAccess = fastAccess; }
public void setPosition(boolean position) { this.isPosition = position; }
+ public void setMutable(boolean mutable) { this.mutable = mutable; }
public void setArity(int arity) { this.arity = arity; }
public void setLowerBound(long lowerBound) { this.lowerBound = lowerBound; }
public void setUpperBound(long upperBound) { this.upperBound = upperBound; }
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java
index 46ac3cc1691..4df3660a967 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java
@@ -16,6 +16,7 @@ public class AttributeOperation implements FieldOperation, FieldOperationContain
private Boolean huge;
private Boolean fastSearch;
private Boolean fastAccess;
+ private Boolean mutable;
private Boolean prefetch;
private Boolean enableBitVectors;
private Boolean enableOnlyBitVector;
@@ -68,6 +69,9 @@ public class AttributeOperation implements FieldOperation, FieldOperationContain
public void setFastAccess(Boolean fastAccess) {
this.fastAccess = fastAccess;
}
+ public void setMutable(Boolean mutable) {
+ this.mutable = mutable;
+ }
public Boolean getPrefetch() {
return prefetch;
@@ -143,6 +147,9 @@ public class AttributeOperation implements FieldOperation, FieldOperationContain
if (fastAccess != null) {
attribute.setFastAccess(fastAccess);
}
+ if (mutable != null) {
+ attribute.setMutable(mutable);
+ }
if (prefetch != null) {
attribute.setPrefetch(prefetch);
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/AttributesImplicitWord.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/AttributesImplicitWord.java
index 34903abb288..a95f4264dc6 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/AttributesImplicitWord.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/AttributesImplicitWord.java
@@ -38,7 +38,7 @@ public class AttributesImplicitWord extends Processor {
return false;
}
return (field.getIndexToCount() == 0
- && field.getAttributes().size() > 0
+ && !field.getAttributes().isEmpty()
&& field.getIndices().isEmpty()
&& !field.getMatching().isTypeUserSet());
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/MutableAttributes.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/MutableAttributes.java
new file mode 100644
index 00000000000..e35da451bff
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/MutableAttributes.java
@@ -0,0 +1,28 @@
+package com.yahoo.searchdefinition.processing;
+
+import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.searchdefinition.RankProfileRegistry;
+import com.yahoo.searchdefinition.Search;
+import com.yahoo.searchdefinition.document.SDField;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+public class MutableAttributes extends Processor {
+
+ public MutableAttributes(Search search, DeployLogger deployLogger,
+ RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles)
+ {
+ super(search, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process(boolean validate) {
+ for (SDField field : search.allConcreteFields()) {
+ if (!field.isExtraField() && field.getAttributes().containsKey(field.getName())) {
+ if (field.getAttributes().get(field.getName()).isMutable()) {
+ throw new IllegalArgumentException("Field " + field + " in '" + search.getDocument().getName() +
+ "' can not be marked mutable as it inside the document.");
+ }
+ }
+ }
+ }
+}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
index cedbebe3b4e..19025d37f8c 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
@@ -37,6 +37,7 @@ public class Processing {
OptimizeIlscript::new,
ValidateFieldWithIndexSettingsCreatesIndex::new,
AttributesImplicitWord::new,
+ MutableAttributes::new,
CreatePositionZCurve::new,
WordMatch::new,
DeprecateAttributePrefetch::new,
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 2c4c9a47fec..63d3926afad 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -281,6 +281,7 @@ TOKEN :
| < ENABLEBITVECTORS: "enable-bit-vectors" >
| < ENABLEONLYBITVECTOR: "enable-only-bit-vector" >
| < FASTACCESS: "fast-access" >
+| < MUTABLE: "mutable" >
| < FASTSEARCH: "fast-search" >
| < HUGE: "huge" >
| < PREFETCH: "prefetch" >
@@ -1190,16 +1191,18 @@ Object attributeSetting(FieldOperationContainer field, AttributeOperation attrib
}
{
(
- <HUGE> { attribute.setHuge(true); }
- | <FASTSEARCH> { attribute.setFastSearch(true); }
- | <FASTACCESS> { attribute.setFastAccess(true); }
- | <ENABLEBITVECTORS> { attribute.setEnableBitVectors(true); }
+ <HUGE> { attribute.setHuge(true); }
+ | <FASTSEARCH> { attribute.setFastSearch(true); }
+ | <FASTACCESS> { attribute.setFastAccess(true); }
+ | <MUTABLE> { attribute.setMutable(true); }
+ | <ENABLEBITVECTORS> { attribute.setEnableBitVectors(true); }
| <ENABLEONLYBITVECTOR> { attribute.setEnableOnlyBitVector(true); }
- | <NOPREFETCH> {
+
+ | <NOPREFETCH> {
deployLogger.log(Level.WARNING, field + ": 'attribute : no-prefetch' is deprecated and has no effect.");
attribute.setPrefetch(false);
}
- | <PREFETCH> {
+ | <PREFETCH> {
deployLogger.log(Level.WARNING, field + ": 'attribute : prefetch' is deprecated and has no effect.");
attribute.setPrefetch(true);
}
@@ -2515,6 +2518,7 @@ String identifier() : { }
| <MAXFILTERCOVERAGE>
| <MAXHITS>
| <MTOKEN>
+ | <MUTABLE>
| <NEVER>
| <NONE>
| <NOPREFETCH>
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java
index 4ee33abfc08..1b58db0322b 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java
@@ -4,10 +4,11 @@ package com.yahoo.searchdefinition;
import com.yahoo.document.StructDataType;
import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.searchdefinition.document.SDField;
-import com.yahoo.searchdefinition.document.Sorting;
import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.tensor.TensorType;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.io.IOException;
import java.util.Optional;
@@ -22,6 +23,9 @@ import static org.junit.Assert.*;
*/
public class AttributeSettingsTestCase extends SearchDefinitionTestCase {
+ @Rule
+ public final ExpectedException exceptionRule = ExpectedException.none();
+
@Test
public void testAttributeSettings() throws IOException, ParseException {
Search search = SearchBuilder.buildFromFile("src/test/examples/attributesettings.sd");
@@ -92,6 +96,59 @@ public class AttributeSettingsTestCase extends SearchDefinitionTestCase {
assertTrue(attr.isFastAccess());
}
+ private Attribute getAttributeF(String sd) throws ParseException {
+ SearchBuilder builder = new SearchBuilder();
+ builder.importString(sd);
+ builder.build();
+ Search search = builder.getSearch();
+ SDField field = (SDField) search.getDocument().getField("f");
+ return field.getAttributes().get(field.getName());
+ }
+ @Test
+ public void requireThatMutableIsDefaultOff() throws ParseException {
+ Attribute attr = getAttributeF(
+ "search test {\n" +
+ " document test { \n" +
+ " field f type int { \n" +
+ " indexing: attribute \n" +
+ " }\n" +
+ " }\n" +
+ "}\n");
+ assertFalse(attr.isMutable());
+ }
+
+ @Test
+ public void requireThatMutableCanNotbeSetInDocument() throws ParseException {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("Field field 'f' in 'test' can not be marked mutable as it inside the document.");
+ Attribute attr = getAttributeF(
+ "search test {\n" +
+ " document test {\n" +
+ " field f type int {\n" +
+ " indexing: attribute\n" +
+ " attribute: mutable\n" +
+ " }\n" +
+ " }\n" +
+ "}\n");
+ }
+
+ @Test
+ public void requireThatMutableExtraFieldCanBeSet() throws IOException, ParseException {
+ Attribute attr = getAttributeF(
+ "search test {\n" +
+ " document test { \n" +
+ " field a type int { \n" +
+ " indexing: attribute \n" +
+ " }\n" +
+ " }\n" +
+ " field f type long {\n" +
+ " indexing: 0 | to_long | attribute\n" +
+ " attribute: mutable\n" +
+ " }\n" +
+ "}\n");
+ assertTrue(attr.isMutable());
+ }
+
@Test
public void attribute_convert_to_array_copies_internal_state() {
StructDataType refType = new StructDataType("my_struct");