blob: 9c681f62578ecaf0ce2fb81147300edbef0ef820 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
import com.yahoo.document.DataType;
import com.yahoo.document.Field;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.vespa.indexinglanguage.ValueTransformProvider;
import com.yahoo.vespa.indexinglanguage.expressions.*;
/**
* @author Simon Thoresen Hult
*/
public abstract class TypedTransformProvider extends ValueTransformProvider {
private final Search search;
private DataType fieldType;
TypedTransformProvider(Class<? extends Expression> transformClass, Search search) {
super(transformClass);
this.search = search;
}
@Override
protected final boolean requiresTransform(Expression exp) {
if (exp instanceof OutputExpression) {
String fieldName = ((OutputExpression)exp).getFieldName();
if (exp instanceof AttributeExpression) {
Attribute attribute = search.getAttribute(fieldName);
if (attribute == null)
throw new IllegalArgumentException("Attribute '" + fieldName + "' not found.");
fieldType = attribute.getDataType();
}
else if (exp instanceof IndexExpression) {
Field field = search.getConcreteField(fieldName);
if (field == null)
throw new IllegalArgumentException("Index field '" + fieldName + "' not found.");
fieldType = field.getDataType();
}
else if (exp instanceof SummaryExpression) {
Field field = search.getSummaryField(fieldName);
if (field == null)
throw new IllegalArgumentException("Summary field '" + fieldName + "' not found.");
fieldType = field.getDataType();
}
else {
throw new UnsupportedOperationException();
}
}
return requiresTransform(exp, fieldType);
}
@Override
protected final Expression newTransform() {
return newTransform(fieldType);
}
protected abstract boolean requiresTransform(Expression exp, DataType fieldType);
protected abstract Expression newTransform(DataType fieldType);
}
|