blob: 7bef7244eb7efc67c114841b4f83862723abcf3a (
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
|
// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import java.util.stream.Collectors;
/**
* Validates the use of the fast-access property.
*
* @author bjorncs
*/
public class FastAccessValidator extends Processor {
public FastAccessValidator(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process() {
String invalidAttributes = search.allFields()
.flatMap(field -> field.getAttributes().values().stream())
.filter(FastAccessValidator::isIncompatibleAttribute)
.map(Attribute::getName)
.collect(Collectors.joining(", "));
if (!invalidAttributes.isEmpty()) {
throw new IllegalArgumentException(
String.format(
"For search '%s': The following attributes have a type that is incompatible with fast-access: %s. " +
"Predicate, tensor and reference attributes are incompatible with fast-access.",
search.getName(),
invalidAttributes));
}
}
private static boolean isIncompatibleAttribute(Attribute attribute) {
return attribute.isFastAccess() && isTypeIncompatibleWithFastAccess(attribute.getType());
}
private static boolean isTypeIncompatibleWithFastAccess(Attribute.Type type) {
switch (type) {
case PREDICATE:
case TENSOR:
case REFERENCE:
return true;
default:
return false;
}
}
}
|