SOLR-10805: Improve error handling for statistical Stream Evaluators

This commit is contained in:
Joel Bernstein 2017-06-02 12:13:34 -04:00
parent 2271e73e76
commit f275e3b254
12 changed files with 60 additions and 2 deletions

View File

@ -40,6 +40,11 @@ public class AnovaEvaluator extends ComplexEvaluator implements Expressible {
} }
public Tuple evaluate(Tuple tuple) throws IOException { public Tuple evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() < 2) {
throw new IOException("ANOVA evaluator expects atleast 2 parameters found: "+subEvaluators.size());
}
List<double[]> list = new ArrayList(); List<double[]> list = new ArrayList();
for(StreamEvaluator subEvaluator : subEvaluators) { for(StreamEvaluator subEvaluator : subEvaluators) {
List<Number> nums = (List<Number>)subEvaluator.evaluate(tuple); List<Number> nums = (List<Number>)subEvaluator.evaluate(tuple);

View File

@ -38,6 +38,12 @@ public class ConvolutionEvaluator extends ComplexEvaluator implements Expressibl
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Convolution evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
StreamEvaluator colEval2 = subEvaluators.get(1); StreamEvaluator colEval2 = subEvaluators.get(1);

View File

@ -37,6 +37,11 @@ public class CorrelationEvaluator extends ComplexEvaluator implements Expressibl
} }
public Number evaluate(Tuple tuple) throws IOException { public Number evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Correlation evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
StreamEvaluator colEval2 = subEvaluators.get(1); StreamEvaluator colEval2 = subEvaluators.get(1);

View File

@ -37,6 +37,11 @@ public class CovarianceEvaluator extends ComplexEvaluator implements Expressible
} }
public Number evaluate(Tuple tuple) throws IOException { public Number evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Covariance evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
StreamEvaluator colEval2 = subEvaluators.get(1); StreamEvaluator colEval2 = subEvaluators.get(1);

View File

@ -38,6 +38,11 @@ public class DistanceEvaluator extends ComplexEvaluator implements Expressible {
} }
public Number evaluate(Tuple tuple) throws IOException { public Number evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Distance evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
StreamEvaluator colEval2 = subEvaluators.get(1); StreamEvaluator colEval2 = subEvaluators.get(1);

View File

@ -38,6 +38,11 @@ public class FindDelayEvaluator extends ComplexEvaluator implements Expressible
} }
public Number evaluate(Tuple tuple) throws IOException { public Number evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Finddelay evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
StreamEvaluator colEval2 = subEvaluators.get(1); StreamEvaluator colEval2 = subEvaluators.get(1);

View File

@ -42,6 +42,10 @@ public class HistogramEvaluator extends ComplexEvaluator implements Expressible
public List<Map> evaluate(Tuple tuple) throws IOException { public List<Map> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Histogram evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
List<Number> numbers1 = (List<Number>)colEval1.evaluate(tuple); List<Number> numbers1 = (List<Number>)colEval1.evaluate(tuple);
@ -79,8 +83,6 @@ public class HistogramEvaluator extends ComplexEvaluator implements Expressible
return binList; return binList;
} }
@Override @Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException { public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
StreamExpression expression = new StreamExpression(factory.getFunctionName(getClass())); StreamExpression expression = new StreamExpression(factory.getFunctionName(getClass()));

View File

@ -38,6 +38,11 @@ public class MovingAverageEvaluator extends ComplexEvaluator implements Expressi
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Moving average evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval = subEvaluators.get(0); StreamEvaluator colEval = subEvaluators.get(0);
StreamEvaluator windowEval = subEvaluators.get(1); StreamEvaluator windowEval = subEvaluators.get(1);

View File

@ -38,6 +38,11 @@ public class RankEvaluator extends ComplexEvaluator implements Expressible {
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 1) {
throw new IOException("Rank evaluator expects 1 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval = subEvaluators.get(0); StreamEvaluator colEval = subEvaluators.get(0);
List<Number> numbers = (List<Number>)colEval.evaluate(tuple); List<Number> numbers = (List<Number>)colEval.evaluate(tuple);

View File

@ -37,6 +37,11 @@ public class ReverseEvaluator extends ComplexEvaluator implements Expressible {
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 1) {
throw new IOException("Reverse evaluator expects 1 parameters found: "+subEvaluators.size());
}
StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval1 = subEvaluators.get(0);
List<Number> numbers1 = (List<Number>)colEval1.evaluate(tuple); List<Number> numbers1 = (List<Number>)colEval1.evaluate(tuple);

View File

@ -38,6 +38,11 @@ public class ScaleEvaluator extends ComplexEvaluator implements Expressible {
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 2) {
throw new IOException("Scale evaluator expects 2 parameters found: "+subEvaluators.size());
}
StreamEvaluator numEval = subEvaluators.get(0); StreamEvaluator numEval = subEvaluators.get(0);
StreamEvaluator colEval1 = subEvaluators.get(1); StreamEvaluator colEval1 = subEvaluators.get(1);

View File

@ -38,6 +38,11 @@ public class SequenceEvaluator extends ComplexEvaluator implements Expressible {
} }
public List<Number> evaluate(Tuple tuple) throws IOException { public List<Number> evaluate(Tuple tuple) throws IOException {
if(subEvaluators.size() != 3) {
throw new IOException("Sequence evaluator expects 3 parameters found: "+subEvaluators.size());
}
StreamEvaluator sizeEval = subEvaluators.get(0); StreamEvaluator sizeEval = subEvaluators.get(0);
StreamEvaluator startEval = subEvaluators.get(1); StreamEvaluator startEval = subEvaluators.get(1);
StreamEvaluator strideEval = subEvaluators.get(2); StreamEvaluator strideEval = subEvaluators.get(2);