aboutsummaryrefslogtreecommitdiffstats
path: root/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/IdentityFieldPathUpdateAdapter.java
blob: 6bca95e3f47a388029b093e2c5cad01fd68fd97d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Yahoo. 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.DocumentType;
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);
    }

    @Override
    public DocumentType getDocumentType() { return fwdAdapter.getDocumentType(); }

}