use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class ModuloEvaluatorTest method modByZero.
@Test(expected = IOException.class)
public void modByZero() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
values.clear();
values.put("a", 1);
values.put("b", 0);
evaluator.evaluate(new Tuple(values));
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class TupStream method read.
public Tuple read() throws IOException {
if (finished) {
Map<String, Object> m = new HashMap<>();
m.put("EOF", true);
return new Tuple(m);
} else {
finished = true;
Map<String, Object> values = new HashMap<>();
// these could come from the context, or they will just be treated as straight strings
for (Entry<String, String> param : stringParams.entrySet()) {
if (streamContext.getLets().containsKey(param.getValue())) {
values.put(param.getKey(), streamContext.getLets().get(param.getValue()));
} else {
values.put(param.getKey(), param.getValue());
}
}
// add all evaluators
for (Entry<String, StreamEvaluator> param : evaluatorParams.entrySet()) {
values.put(param.getKey(), param.getValue().evaluateOverContext());
}
// Add all streams
for (Entry<String, TupleStream> param : streamParams.entrySet()) {
try {
List<Tuple> streamTuples = new ArrayList<Tuple>();
// open the stream, closed in finally block
param.getValue().open();
// read all values from stream (memory expensive)
Tuple streamTuple = param.getValue().read();
while (!streamTuple.EOF) {
streamTuples.add(streamTuple);
streamTuple = param.getValue().read();
}
values.put(param.getKey(), streamTuples);
} finally {
// safely close the stream
param.getValue().close();
}
}
Tuple tup = new Tuple(values);
tup.fieldNames = fieldNames;
tup.fieldLabels = fieldLabels;
return tup;
}
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class AddEvaluatorTest method addManyFieldsWithManySubAddsWithNegative.
@Test
public void addManyFieldsWithManySubAddsWithNegative() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("add(add(a,b),add(c,d),add(c,a))");
Object result;
values.clear();
values.put("a", -1);
values.put("b", 2);
values.put("c", 3);
values.put("d", 4);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(10L, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2);
values.put("c", -3);
values.put("d", 4);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(2.2D, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
values.put("c", -3.1);
values.put("d", 4.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(2.2D, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
values.put("c", -3.1);
values.put("d", 5.223456789123456);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(3.323456789123456, result);
values.clear();
values.put("a", 123456789123456789L);
values.put("b", -123456789123456789L);
values.put("c", 123456789123456789L);
values.put("d", 123456789123456789L);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(4 * 123456789123456789L, result);
values.clear();
values.put("a", -4.123456789123456);
values.put("b", -4.123456789123456);
values.put("c", -4.123456789123456);
values.put("d", -4.123456789123456);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(6 * -4.123456789123456, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class ArcCosineEvaluatorTest method noValue.
@Test
public void noValue() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("acos(a)");
values.clear();
Object result = evaluator.evaluate(new Tuple(values));
assertNull(result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class AddEvaluatorTest method addManyFieldsWithManySubAdds.
@Test
public void addManyFieldsWithManySubAdds() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("add(add(a,b),add(c,d),add(c,a))");
Object result;
values.clear();
values.put("a", 1);
values.put("b", 2);
values.put("c", 3);
values.put("d", 4);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(14L, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2);
values.put("c", 3);
values.put("d", 4);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(14.2D, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
values.put("c", 3.1);
values.put("d", 4.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(14.6D, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
values.put("c", 3.1);
values.put("d", 4.123456789123456);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(14.623456789123456, result);
values.clear();
values.put("a", 123456789123456789L);
values.put("b", 123456789123456789L);
values.put("c", 123456789123456789L);
values.put("d", 123456789123456789L);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(6 * 123456789123456789L, result);
values.clear();
values.put("a", 4.123456789123456);
values.put("b", 4.123456789123456);
values.put("c", 4.123456789123456);
values.put("d", 4.123456789123456);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(6 * 4.123456789123456, result);
}
Aggregations