Skip to content

Commit 558fc5e

Browse files
committed
Disallow sorting on tensors
1 parent fa34403 commit 558fc5e

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

config-model/src/main/java/com/yahoo/schema/document/Attribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public enum Type {
109109
private final String exportAttributeTypeName;
110110

111111
Type(String name, String exportAttributeTypeName) {
112-
this.myName=name;
112+
this.myName = name;
113113
this.exportAttributeTypeName = exportAttributeTypeName;
114114
}
115115

container-search/src/main/java/com/yahoo/prelude/searcher/ValidateSortingSearcher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ private ErrorMessage validate(Query query) {
124124
f.setSorter(new Sorting.LowerCaseSorter(name));
125125
}
126126
}
127+
else if (attrConfig.datatype() == AttributesConfig.Attribute.Datatype.TENSOR) {
128+
throw new IllegalArgumentException("Cannot sort on field '" + attrConfig.name() +
129+
"' because it is a tensor");
130+
}
131+
127132
}
128133
if (f.getSorter() instanceof Sorting.UcaSorter sorter) {
129134
String locale = sorter.getLocale();

container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ void testBasicValidation() {
4747
assertEquals("[ASCENDING:[rank]]", quoteAndTransform("+[relevance]"));
4848
}
4949

50+
@Test
51+
void testDisallowSortingOnTensors() {
52+
try {
53+
quoteAndTransform("aTensor");
54+
fail("Expected exception");
55+
}
56+
catch (IllegalArgumentException e) {
57+
assertEquals("Cannot sort on field 'aTensor' because it is a tensor", e.getMessage());
58+
}
59+
}
60+
5061
@Test
5162
void testInvalidSpec() {
5263
assertNull(quoteAndTransform("+a -e +c"));

container-search/src/test/java/com/yahoo/prelude/searcher/test/validate_sorting.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
attribute[4]
1+
attribute[5]
22
attribute[0].name title
33
attribute[0].datatype STRING
44
attribute[0].collectiontype SINGLE
@@ -15,3 +15,6 @@ attribute[2].collectiontype SINGLE
1515
attribute[3].name c
1616
attribute[3].datatype STRING
1717
attribute[3].collectiontype SINGLE
18+
attribute[4].name aTensor
19+
attribute[4].datatype TENSOR
20+
attribute[4].collectiontype SINGLE

0 commit comments

Comments
 (0)