use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class AbsoluteValueEvaluatorTest method absoluteValueFromContext.
@Test
public void absoluteValueFromContext() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("abs(a)");
StreamContext context = new StreamContext();
evaluator.setStreamContext(context);
Object result;
context.getLets().put("a", 1);
result = evaluator.evaluate(new Tuple());
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(1L, result);
context.getLets().put("a", 1.1);
result = evaluator.evaluate(new Tuple());
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(1.1D, result);
context.getLets().put("a", -1.1);
result = evaluator.evaluate(new Tuple());
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(1.1D, result);
context.getLets().put("a", factory.constructEvaluator("add(4,-6,34,-56)"));
result = evaluator.evaluate(new Tuple());
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(24L, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class AddEvaluatorTest method addTwoFieldsWithNull.
@Test
public void addTwoFieldsWithNull() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("add(a,b)");
Object result;
values.clear();
values.put("a", 1);
values.put("b", null);
result = evaluator.evaluate(new Tuple(values));
Assert.assertNull(result);
values.clear();
values.put("a", 1.1);
values.put("b", null);
result = evaluator.evaluate(new Tuple(values));
Assert.assertNull(result);
values.clear();
values.put("a", null);
values.put("b", 1.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertNull(result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class TangentEvaluatorTest method noValue.
@Test
public void noValue() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("tan(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 TemporalEvaluatorsTest method testInvalidValues.
@Test
public void testInvalidValues() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("year(a)");
try {
values.clear();
values.put("a", 12);
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
Object result = evaluator.evaluate(new Tuple(values));
assertTrue(false);
} catch (IOException e) {
assertEquals("Invalid parameter 12 - The parameter must be a string formatted ISO_INSTANT or of type Long,Instant,Date,LocalDateTime or TemporalAccessor.", e.getMessage());
}
try {
values.clear();
values.put("a", "1995-12-31");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
Object result = evaluator.evaluate(new Tuple(values));
assertTrue(false);
} catch (IOException e) {
assertEquals("Invalid parameter 1995-12-31 - The String must be formatted in the ISO_INSTANT date format.", e.getMessage());
}
try {
values.clear();
values.put("a", "");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
Object result = evaluator.evaluate(new Tuple(values));
assertTrue(false);
} catch (IOException e) {
assertEquals("Invalid parameter - The parameter must be a string formatted ISO_INSTANT or of type Long,Instant,Date,LocalDateTime or TemporalAccessor.", e.getMessage());
}
values.clear();
values.put("a", null);
assertNull(evaluator.evaluate(new Tuple(values)));
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class TemporalEvaluatorsTest method testFunction.
public void testFunction(String expression, Object value, Number expected) throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator(expression);
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
values.clear();
values.put("a", value);
Object result = evaluator.evaluate(new Tuple(values));
assertTrue(result instanceof Number);
assertEquals(expected, result);
}
Aggregations