use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.
the class OperationsTest method replaceValueNullWithString.
@Test
public void replaceValueNullWithString() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withValue=foo)"), factory);
// replace
values.clear();
values.put("fieldB", "bar");
values.put("fieldC", 123);
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("foo", tuple.get("fieldA"));
// don't replace
values.clear();
values.put("fieldA", "exists");
values.put("fieldB", "bar");
values.put("fieldC", 123);
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("exists", tuple.get("fieldA"));
}
use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.
the class ConcatOperationTest method concatMultipleFields.
@Test
public void concatMultipleFields() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(new String[] { "fieldA", "fieldB" }, "fieldABConcat", "-");
values.clear();
values.put("fieldA", "bar");
values.put("fieldB", "baz");
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("bar", tuple.get("fieldA"));
Assert.assertNotNull(tuple.get("fieldB"));
Assert.assertEquals("baz", tuple.get("fieldB"));
Assert.assertNotNull(tuple.get("fieldABConcat"));
Assert.assertEquals("bar-baz", tuple.get("fieldABConcat"));
// do the same in oposite order
operation = new ConcatOperation(new String[] { "fieldB", "fieldA" }, "fieldABConcat", "-");
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("bar", tuple.get("fieldA"));
Assert.assertNotNull(tuple.get("fieldB"));
Assert.assertEquals("baz", tuple.get("fieldB"));
Assert.assertNotNull(tuple.get("fieldABConcat"));
Assert.assertEquals("baz-bar", tuple.get("fieldABConcat"));
}
use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.
the class ConcatOperationTest method concatSingleFieldExpression.
///////////////////////////
@Test
public void concatSingleFieldExpression() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(StreamExpressionParser.parse("concat(fields=\"fieldA\", as=\"fieldAConcat\", delim=\"-\")"), factory);
values.clear();
values.put("fieldA", "bar");
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("bar", tuple.get("fieldA"));
Assert.assertNotNull(tuple.get("fieldAConcat"));
Assert.assertEquals("bar", tuple.get("fieldAConcat"));
}
use of org.apache.solr.client.solrj.io.ops.StreamOperation 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.ops.StreamOperation in project lucene-solr by apache.
the class ConcatOperationTest method concatWithNullValues.
@Test
public void concatWithNullValues() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(new String[] { "fieldA", "fieldB" }, "fieldABConcat", "-");
values.clear();
values.put("fieldA", "bar");
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNotNull(tuple.get("fieldA"));
Assert.assertEquals("bar", tuple.get("fieldA"));
Assert.assertNull(tuple.get("fieldB"));
Assert.assertNotNull(tuple.get("fieldABConcat"));
Assert.assertEquals("bar-null", tuple.get("fieldABConcat"));
}
Aggregations