summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-02-29 11:22:47 +0100
committerGitHub <noreply@github.com>2024-02-29 11:22:47 +0100
commit5cb965432c724f08ccb149f6b8901f695b907c8f (patch)
tree4e6e5114f9c2f89ed2e26485bcafac8ead682727 /config-model
parent83096e38fcfdf9fa8af28cd0de7dd8183ddf13e9 (diff)
parent84d51ea72e5684c715c7cec89215ce7ada1ab363 (diff)
Merge pull request #30405 from vespa-engine/arnej/rewrite-zcurve-streaming
drop conversion to zcurve attribute for streaming
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/derived/IndexingScript.java38
-rw-r--r--config-model/src/test/java/com/yahoo/schema/derived/IndexingScriptTestCase.java19
2 files changed, 57 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/derived/IndexingScript.java b/config-model/src/main/java/com/yahoo/schema/derived/IndexingScript.java
index c35445cfa58..9f41f4d3542 100644
--- a/config-model/src/main/java/com/yahoo/schema/derived/IndexingScript.java
+++ b/config-model/src/main/java/com/yahoo/schema/derived/IndexingScript.java
@@ -8,6 +8,7 @@ import com.yahoo.vespa.configdefinition.IlscriptsConfig;
import com.yahoo.vespa.configdefinition.IlscriptsConfig.Ilscript.Builder;
import com.yahoo.vespa.indexinglanguage.ExpressionConverter;
import com.yahoo.vespa.indexinglanguage.ExpressionVisitor;
+import com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression;
import com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
import com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression;
@@ -113,12 +114,49 @@ public final class IndexingScript extends Derived implements IlscriptsConfig.Pro
}
}
+ // for streaming, drop zcurve conversion to attribute with suffix
+ private static class DropZcurve extends ExpressionConverter {
+ private static final String zSuffix = "_zcurve";
+ private static final int zSuffixLen = zSuffix.length();
+ private boolean seenZcurve = false;
+
+ @Override
+ protected boolean shouldConvert(Expression exp) {
+ if (exp instanceof ZCurveExpression) {
+ seenZcurve = true;
+ return true;
+ }
+ if (seenZcurve && exp instanceof AttributeExpression attrExp) {
+ return attrExp.getFieldName().endsWith(zSuffix);
+ }
+ return false;
+ }
+
+ @Override
+ protected Expression doConvert(Expression exp) {
+ if (exp instanceof ZCurveExpression) {
+ return null;
+ }
+ if (exp instanceof AttributeExpression attrExp) {
+ String orig = attrExp.getFieldName();
+ int len = orig.length();
+ if (len > zSuffixLen && orig.endsWith(zSuffix)) {
+ String fieldName = orig.substring(0, len - zSuffixLen);
+ var result = new AttributeExpression(fieldName);
+ return result;
+ }
+ }
+ return exp;
+ }
+ }
+
private void addContentInOrder(IlscriptsConfig.Ilscript.Builder ilscriptBuilder) {
ArrayList<Expression> later = new ArrayList<>();
Set<String> touchedFields = new HashSet<>();
for (Expression expression : expressions) {
if (isStreaming) {
expression = expression.convertChildren(new DropTokenize());
+ expression = expression.convertChildren(new DropZcurve());
}
if (modifiesSelf(expression) && ! setsLanguage(expression)) {
later.add(expression);
diff --git a/config-model/src/test/java/com/yahoo/schema/derived/IndexingScriptTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/IndexingScriptTestCase.java
index 6bfb67b3011..a35dda28e16 100644
--- a/config-model/src/test/java/com/yahoo/schema/derived/IndexingScriptTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/derived/IndexingScriptTestCase.java
@@ -40,4 +40,23 @@ public class IndexingScriptTestCase {
verifyIndexingScript(false);
verifyIndexingScript(true);
}
+
+ private void verifyZcurveScript(boolean isStreaming) {
+ VespaModel model = IndexInfoTestCase.createModel(TEST,
+ """
+ field f type position { indexing: attribute }
+ """);
+ Schema schema = model.getSearchClusters().get(0).schemas().get(TEST).fullSchema();
+ IlscriptsConfig cfg = ilscriptsConfig(schema, isStreaming);
+ assertEquals(1, cfg.ilscript().size());
+ assertEquals(1, cfg.ilscript(0).content().size());
+ String exp_f = isStreaming ? "attribute f" : "zcurve | attribute f_zcurve";
+ assertEquals("clear_state | guard { input f | " + exp_f + "; }", cfg.ilscript(0).content(0));
+ }
+
+ @Test
+ void testThatZcurveIsRewrittenFromStreaming() {
+ verifyZcurveScript(false);
+ verifyZcurveScript(true);
+ }
}