blob: 267fb6fc51bb576abc5e2202be9b26dce238fa42 (
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
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;
import com.yahoo.document.DataType;
import com.yahoo.vespa.objects.ObjectOperation;
import com.yahoo.vespa.objects.ObjectPredicate;
import java.util.ArrayList;
import java.util.List;
/**
* @author Simon Thoresen Hult
*/
public abstract class OutputExpression extends Expression {
private final String image;
private final String fieldName;
public OutputExpression(String image, String fieldName) {
super(UnresolvedDataType.INSTANCE);
this.image = image;
this.fieldName = fieldName;
}
public String getFieldName() {
return fieldName;
}
@Override
protected void doExecute(ExecutionContext context) {
context.setOutputValue(this, fieldName, context.getValue());
}
@Override
protected void doVerify(VerificationContext context) {
context.tryOutputType(this, fieldName, context.getValueType());
}
@Override
public DataType createdOutputType() {
return null;
}
@Override
public String toString() {
return image + (fieldName != null ? " " + fieldName : "");
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OutputExpression)) {
return false;
}
OutputExpression rhs = (OutputExpression)obj;
if (!equals(fieldName, rhs.fieldName)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return getClass().hashCode() + (fieldName != null ? fieldName.hashCode() : 0);
}
public static class OutputFieldNameExtractor implements ObjectOperation, ObjectPredicate {
private final List<String> outputFieldNames = new ArrayList<>(1);
public List<String> getOutputFieldNames() { return outputFieldNames; }
@Override
public void execute(Object obj) {
outputFieldNames.add(((OutputExpression) obj).getFieldName());
}
@Override
public boolean check(Object obj) {
return obj instanceof OutputExpression;
}
}
}
|