diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-03-31 14:31:37 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2023-03-31 14:31:37 +0100 |
commit | 1a360b51809d892d6b348f78db7ebd1590d77335 (patch) | |
tree | 0867de0b7804c22d1ea566882d01546154c696b9 | |
parent | d65d548169183b47b931b3c5e39ad5a8fae06ce5 (diff) |
More understandable errors, and implement inner convert
5 files changed, 43 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/parser/ConvertSchemaCollection.java b/config-model/src/main/java/com/yahoo/schema/parser/ConvertSchemaCollection.java index 5509d11885c..b414d3757e2 100644 --- a/config-model/src/main/java/com/yahoo/schema/parser/ConvertSchemaCollection.java +++ b/config-model/src/main/java/com/yahoo/schema/parser/ConvertSchemaCollection.java @@ -20,7 +20,7 @@ import java.util.List; * Class converting a collection of schemas from the intermediate format. * * @author arnej27959 - **/ + */ public class ConvertSchemaCollection { private final IntermediateCollection input; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ExpressionConverter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ExpressionConverter.java index 45d8637aa3e..ccad9d6d08b 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ExpressionConverter.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ExpressionConverter.java @@ -55,6 +55,11 @@ public abstract class ExpressionConverter implements Cloneable { return new CatExpression(lst); } + public Expression innerConvert(ChoiceExpression exp) { + var convertedInnerExpressions = exp.asList().stream().map(inner -> convert(inner)).toList(); + return new ChoiceExpression(convertedInnerExpressions); + } + public Expression innerConvert(ForEachExpression exp) { return new ForEachExpression(convert(exp.getInnerExpression())); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java index 30c824d410d..bba1b09cda2 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java @@ -21,7 +21,9 @@ public final class InputExpression extends Expression { public InputExpression(String fieldName) { super(null); - this.fieldName = Objects.requireNonNull(fieldName); + if (fieldName == null) + throw new IllegalArgumentException("'input' must be given a field name as argument"); + this.fieldName = fieldName; } public String getFieldName() { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java index 351c925ed56..7ece841e9b7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java @@ -4,7 +4,13 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; import com.yahoo.document.Field; import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.language.Linguistics; +import com.yahoo.language.process.Embedder; +import com.yahoo.language.simple.SimpleLinguistics; +import com.yahoo.vespa.indexinglanguage.ExpressionSearcher; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; +import com.yahoo.vespa.indexinglanguage.parser.ParseException; +import com.yahoo.yolean.Exceptions; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -44,4 +50,24 @@ public class ChoiceTestCase { } } + @Test + public void testIllegalChoiceExpression() throws ParseException { + try { + parse("input (foo || 99999999) | attribute"); + } + catch (IllegalArgumentException e) { + assertEquals("'input' must be given a field name as argument", Exceptions.toMessageString(e)); + } + } + + @Test + public void testInnerConvert() throws ParseException { + var expression = parse("(input foo || 99999999) | attribute"); + new ExpressionSearcher<>(AttributeExpression.class).searchIn(expression); // trigger innerConvert + } + + private static Expression parse(String s) throws ParseException { + return Expression.fromString(s, new SimpleLinguistics(), Embedder.throwsOnUse.asMap()); + } + } diff --git a/vdslib/src/main/java/com/yahoo/vdslib/VisitorStatistics.java b/vdslib/src/main/java/com/yahoo/vdslib/VisitorStatistics.java index fda456ace05..14b44ede12a 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/VisitorStatistics.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/VisitorStatistics.java @@ -2,6 +2,7 @@ package com.yahoo.vdslib; public class VisitorStatistics { + int bucketsVisited = 0; long documentsVisited = 0; long bytesVisited = 0; @@ -20,8 +21,8 @@ public class VisitorStatistics { public void setBucketsVisited(int bucketsVisited) { this.bucketsVisited = bucketsVisited; } /** - * @return the number of documents matching the document selection in the backend and that - * has been passed to the client-specified visitor instance (dumpvisitor, searchvisitor etc). + * Returns the number of documents matching the document selection in the backend that + * has been passed to the client-specified visitor instance (dumpvisitor, searchvisitor etc). */ public long getDocumentsVisited() { return documentsVisited; } public void setDocumentsVisited(long documentsVisited) { this.documentsVisited = documentsVisited; } @@ -30,9 +31,9 @@ public class VisitorStatistics { public void setBytesVisited(long bytesVisited) { this.bytesVisited = bytesVisited; } /** - * @return Number of documents returned to the visitor client by the backend. This number may - * be lower than that returned by getDocumentsVisited() since the client-specified visitor - * instance may further have filtered the set of documents returned by the backend. + * Returns the number of documents returned to the visitor client by the backend. This number may + * be lower than that returned by getDocumentsVisited() since the client-specified visitor + * instance may further have filtered the set of documents returned by the backend. */ public long getDocumentsReturned() { return documentsReturned; } public void setDocumentsReturned(long documentsReturned) { this.documentsReturned = documentsReturned; } @@ -40,15 +41,14 @@ public class VisitorStatistics { public long getBytesReturned() { return bytesReturned; } public void setBytesReturned(long bytesReturned) { this.bytesReturned = bytesReturned; } + @Override public String toString() { - String out = + return "Buckets visited: " + bucketsVisited + "\n" + "Documents visited: " + documentsVisited + "\n" + "Bytes visited: " + bytesVisited + "\n" + "Documents returned: " + documentsReturned + "\n" + "Bytes returned: " + bytesReturned + "\n"; - - return out; } } |