summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-06 15:59:14 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-06 15:59:14 +0100
commitcb18a346ddb89b604251564f59968d4d62b065a3 (patch)
treef16c80cfd2903c9520bb26c0e60d2513e59d712e
parent063b679c7cac060c44121a2ee7ce5a5d4b81849b (diff)
Cleanup
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java3
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java64
2 files changed, 63 insertions, 4 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
index 494d8d56161..a7a5ad58430 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
@@ -39,8 +39,6 @@ public class RankingExpressionTypeValidator extends Processor {
/** Throws an IllegalArgumentException if the given rank profile does not produce valid type */
private void validate(RankProfile profile) {
profile.parseExpressions();
- System.out.println("Type checking " + profile + ":");
- System.out.println(" First-phase: " + profile.getFirstPhaseRanking());
TypeContext context = profile.typeContext(queryProfiles);
for (RankProfile.Macro macro : profile.getMacros().values())
ensureValid(macro.getRankingExpression(), "macro '" + macro.getName() + "'", context);
@@ -58,7 +56,6 @@ public class RankingExpressionTypeValidator extends Processor {
catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The " + expressionDescription + " is invalid", e);
}
- System.out.println(" Type of " + expressionDescription + " " + expression.getRoot() + ": " + type);
if (type == null) // Not expected to happen
throw new IllegalStateException("Could not determine the type produced by " + expressionDescription);
return type;
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java
index 5c654f09c51..db3b12db1bf 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java
@@ -12,7 +12,7 @@ import static org.junit.Assert.fail;
public class RankingExpressionTypeValidatorTestCase {
@Test
- public void tensorTypeValidation() throws Exception {
+ public void tensorFirstPhaseMustProduceDouble() throws Exception {
try {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
@@ -39,4 +39,66 @@ public class RankingExpressionTypeValidatorTestCase {
}
}
+ @Test
+ public void tensorSecondPhaseMustProduceDouble() throws Exception {
+ try {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { ",
+ " field a type tensor(x[],y[]) {",
+ " indexing: attribute",
+ " }",
+ " }",
+ " rank-profile my_rank_profile {",
+ " first-phase {",
+ " expression: sum(attribute(a))",
+ " }",
+ " second-phase {",
+ " expression: attribute(a)",
+ " }",
+ " }",
+ "}"
+ ));
+ searchBuilder.build();
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("In search definition 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[],y[])",
+ Exceptions.toMessageString(expected));
+ }
+ }
+
+ @Test
+ public void tensorConditionsMustHaveTypeCompatibleBranches() throws Exception {
+ try {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry);
+ searchBuilder.importString(joinLines(
+ "search test {",
+ " document test { ",
+ " field a type tensor(x[],y[]) {",
+ " indexing: attribute",
+ " }",
+ " field b type tensor(z[10]) {",
+ " indexing: attribute",
+ " }",
+ " }",
+ " rank-profile my_rank_profile {",
+ " first-phase {",
+ " expression: sum(if(1>0, attribute(a), attribute(b)))",
+ " }",
+ " }",
+ "}"
+ ));
+ searchBuilder.build();
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[],y[]) while the 'false' type is tensor(z[10])",
+ Exceptions.toMessageString(expected));
+ }
+ }
+
}