use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class SelectStream method read.
public Tuple read() throws IOException {
Tuple original = stream.read();
if (original.EOF) {
return original;
}
// create a copy with the limited set of fields
Tuple workingToReturn = new Tuple(new HashMap<>());
Tuple workingForEvaluators = new Tuple(new HashMap<>());
//Clear the TupleContext before running the evaluators.
//The TupleContext allows evaluators to cache values within the scope of a single tuple.
//For example a LocalDateTime could be parsed by one evaluator and used by other evaluators within the scope of the tuple.
//This avoids the need to create multiple LocalDateTime instances for the same tuple to satisfy a select expression.
streamContext.getTupleContext().clear();
for (Object fieldName : original.fields.keySet()) {
workingForEvaluators.put(fieldName, original.get(fieldName));
if (selectedFields.containsKey(fieldName)) {
workingToReturn.put(selectedFields.get(fieldName), original.get(fieldName));
}
}
// apply all operations
for (StreamOperation operation : operations) {
operation.operate(workingToReturn);
operation.operate(workingForEvaluators);
}
// Apply all evaluators
for (Map.Entry<StreamEvaluator, String> selectedEvaluator : selectedEvaluators.entrySet()) {
workingToReturn.put(selectedEvaluator.getValue(), selectedEvaluator.getKey().evaluate(workingForEvaluators));
}
return workingToReturn;
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class LetStream method open.
public void open() throws IOException {
Map<String, Object> lets = streamContext.getLets();
Set<Map.Entry<String, Object>> entries = letParams.entrySet();
//Load up the StreamContext with the data created by the letParams.
for (Map.Entry<String, Object> entry : entries) {
String name = entry.getKey();
Object o = entry.getValue();
if (o instanceof TupleStream) {
List<Tuple> tuples = new ArrayList();
TupleStream tStream = (TupleStream) o;
tStream.setStreamContext(streamContext);
try {
tStream.open();
TUPLES: while (true) {
Tuple tuple = tStream.read();
if (tuple.EOF) {
break TUPLES;
} else {
tuples.add(tuple);
}
}
lets.put(name, tuples);
} finally {
tStream.close();
}
} else {
//Add the data from the StreamContext to a tuple.
//Let the evaluator work from this tuple.
//This will allow columns to be created from tuples already in the StreamContext.
Tuple eTuple = new Tuple(lets);
StreamEvaluator evaluator = (StreamEvaluator) o;
Object eo = evaluator.evaluate(eTuple);
lets.put(name, eo);
}
}
stream.open();
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class GreaterThanEqualToEvaluatorTest method gteDifferentTypes1.
@Test(expected = IOException.class)
public void gteDifferentTypes1() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("gte(a,b)");
values.clear();
values.put("a", true);
values.put("b", 1);
evaluator.evaluate(new Tuple(values));
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class GreaterThanEvaluatorTest method gtTwoIntegers.
@Test
public void gtTwoIntegers() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("gt(a,b)");
Object result;
values.clear();
values.put("a", 1);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 1);
values.put("b", 1.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 1.0);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 1);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", -1);
values.put("b", -1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 1);
values.put("b", 2.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 1.0);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 2);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 2);
values.put("b", 1.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 2.0);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 3);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", -1);
values.put("b", -2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 3);
values.put("b", 2.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 3.0);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class GreaterThanEvaluatorTest method gtTwoBooleans.
@Test(expected = IOException.class)
public void gtTwoBooleans() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("gt(a,b)");
values.clear();
values.put("a", true);
values.put("b", true);
evaluator.evaluate(new Tuple(values));
}
Aggregations