diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-06-06 13:02:19 +0200 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2018-06-06 15:26:01 +0200 |
commit | 613bbb29cc6f683d0116e967c939c65f404b7128 (patch) | |
tree | ba2b8a862540cd4f3a22f905de49469486339793 /indexinglanguage | |
parent | 389801098797ab37c7bc4ac5a3888ef4d92214e7 (diff) |
Pass field path updates verbatim through indexing scripts
Avoids having to do a (potentially lossy) round-trip of
update -> document -> update again during processing.
Diffstat (limited to 'indexinglanguage')
2 files changed, 69 insertions, 6 deletions
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/IdentityFieldPathUpdateAdapter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/IdentityFieldPathUpdateAdapter.java new file mode 100644 index 00000000000..42c9bd8c10c --- /dev/null +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/IdentityFieldPathUpdateAdapter.java @@ -0,0 +1,68 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.indexinglanguage; + +import com.yahoo.document.DataType; +import com.yahoo.document.Document; +import com.yahoo.document.DocumentUpdate; +import com.yahoo.document.FieldPath; +import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.document.fieldpathupdate.FieldPathUpdate; +import com.yahoo.vespa.indexinglanguage.expressions.Expression; +import com.yahoo.vespa.indexinglanguage.expressions.FieldValueAdapter; + +/** + * No-op update adapter which simply passes through the input update unchanged. + * I.e. getOutput() will return a DocumentUpdate containing only the FieldPathUpdate + * the IdentityFieldPathUpdateAdapter was created with. All other applicable calls are + * forwarded to the provided DocumentAdapter instance. + * + * This removes the need for a potentially lossy round-trip of update -> synthetic document -> update. + */ +public class IdentityFieldPathUpdateAdapter implements UpdateAdapter { + + private final FieldPathUpdate update; + private final DocumentAdapter fwdAdapter; + + public IdentityFieldPathUpdateAdapter(FieldPathUpdate update, DocumentAdapter fwdAdapter) { + this.update = update; + this.fwdAdapter = fwdAdapter; + } + + @Override + public DocumentUpdate getOutput() { + Document doc = fwdAdapter.getFullOutput(); + DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); + upd.addFieldPathUpdate(update); + return upd; + } + + @Override + public Expression getExpression(Expression expression) { + return expression; + } + + @Override + public FieldValue getInputValue(String fieldName) { + return fwdAdapter.getInputValue(fieldName); + } + + @Override + public FieldValue getInputValue(FieldPath fieldPath) { + return fwdAdapter.getInputValue(fieldPath); + } + + @Override + public FieldValueAdapter setOutputValue(Expression exp, String fieldName, FieldValue fieldValue) { + return fwdAdapter.setOutputValue(exp, fieldName, fieldValue); + } + + @Override + public DataType getInputType(Expression exp, String fieldName) { + return fwdAdapter.getInputType(exp, fieldName); + } + + @Override + public void tryOutputType(Expression exp, String fieldName, DataType valueType) { + fwdAdapter.tryOutputType(exp, fieldName, valueType); + } +} diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java index 2ad09dfbdc4..038e91b7481 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java @@ -48,12 +48,7 @@ public class SimpleAdapterFactory implements AdapterFactory { DocumentId docId = upd.getId(); Document complete = new Document(docType, upd.getId()); for (FieldPathUpdate fieldUpd : upd) { - if (FieldPathUpdateHelper.isComplete(fieldUpd)) { - FieldPathUpdateHelper.applyUpdate(fieldUpd, complete); - } else { - Document partial = FieldPathUpdateHelper.newPartialDocument(docId, fieldUpd); - ret.add(new FieldPathUpdateAdapter(newDocumentAdapter(partial, true), fieldUpd)); - } + ret.add(new IdentityFieldPathUpdateAdapter(fieldUpd, newDocumentAdapter(complete, true))); } for (FieldUpdate fieldUpd : upd.getFieldUpdates()) { Field field = fieldUpd.getField(); |