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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;
import com.yahoo.config.model.application.provider.BaseDeployLogger;
import com.yahoo.schema.parser.ParseException;
import org.junit.Test;
import java.util.Optional;
import static com.yahoo.config.model.test.TestUtil.joinLines;
import static com.yahoo.schema.ApplicationBuilder.createFromString;
import static com.yahoo.schema.ApplicationBuilder.createFromStrings;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class PagedAttributeValidatorTestCase {
@Test
public void dense_tensor_attribute_supports_paged_setting() throws ParseException {
assertPagedSupported("tensor(x[2],y[2])");
}
@Test
public void primitive_attribute_types_support_paged_setting() throws ParseException {
assertPagedSupported("int");
assertPagedSupported("array<int>");
assertPagedSupported("weightedset<int>");
assertPagedSupported("string");
assertPagedSupported("array<string>");
assertPagedSupported("weightedset<string>");
}
@Test
public void struct_field_attributes_support_paged_setting() throws ParseException {
var sd = joinLines("schema test {",
" document test {",
" struct elem {",
" field first type int {}",
" field second type string {}",
" }",
" field foo type array<elem> {",
" indexing: summary",
" struct-field first {",
" indexing: attribute",
" attribute: paged",
" }",
" struct-field second {",
" indexing: attribute",
" attribute: paged",
" }",
" }",
" }",
"}");
var appBuilder = createFromString(sd);
var field = appBuilder.getSchema().getField("foo");
assertTrue(field.getStructField("first").getAttribute().isPaged());
assertTrue(field.getStructField("second").getAttribute().isPaged());
}
private void assertPagedSupported(String fieldType) throws ParseException {
var appBuilder = createFromString(getSd(fieldType));
var attribute = appBuilder.getSchema().getAttribute("foo");
assertTrue(attribute.isPaged());
}
@Test
public void non_dense_tensor_attribute_does_not_support_paged_setting() throws ParseException {
assertPagedSettingNotSupported("tensor(x{},y[2])");
}
@Test
public void predicate_attribute_does_not_support_paged_setting() throws ParseException {
assertPagedSettingNotSupported("predicate");
}
@Test
public void reference_attribute_does_not_support_paged_setting() throws ParseException {
assertPagedSettingNotSupported("reference<parent>", Optional.of(getSd("parent", "int")));
}
private void assertPagedSettingNotSupported(String fieldType) throws ParseException {
assertPagedSettingNotSupported(fieldType, Optional.empty());
}
private void assertPagedSettingNotSupported(String fieldType, Optional<String> parentSd) throws ParseException {
try {
if (parentSd.isPresent()) {
createFromStrings(new BaseDeployLogger(), parentSd.get(), getSd(fieldType));
} else {
createFromString(getSd(fieldType));
}
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("For schema 'test', field 'foo': The 'paged' attribute setting is not supported for non-dense tensor, predicate and reference types",
e.getMessage());
}
}
private String getSd(String fieldType) {
return getSd("test", fieldType);
}
private String getSd(String docType, String fieldType) {
return joinLines(
"schema " + docType + " {",
" document " + docType + " {",
" field foo type " + fieldType + "{",
" indexing: attribute",
" attribute: paged",
" }",
" }",
"}");
}
}
|