use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.
the class ConcatOperationTest method concatWithNullValuesExpression.
@Test
public void concatWithNullValuesExpression() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(StreamExpressionParser.parse("concat(fields=\"fieldA,fieldB\", as=\"fieldABConcat\", 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.assertNull(tuple.get("fieldB"));
Assert.assertNotNull(tuple.get("fieldABConcat"));
Assert.assertEquals("bar-null", tuple.get("fieldABConcat"));
}
use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.
the class OperationsTest method replaceValueNullWithFloat.
@Test
public void replaceValueNullWithFloat() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withValue=123.45678)"), 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(123.45678, 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 OperationsTest method replaceFieldNullWithNonExistantField.
@Test
public void replaceFieldNullWithNonExistantField() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withField=fieldD)"), factory);
// replace
values.clear();
values.put("fieldB", "bar");
values.put("fieldC", 123);
tuple = new Tuple(values);
operation.operate(tuple);
Assert.assertNull(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 concatMultipleFieldsExpression.
@Test
public void concatMultipleFieldsExpression() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(StreamExpressionParser.parse("concat(fields=\"fieldA,fieldB\", as=\"fieldABConcat\", delim=\"-\")"), factory);
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(StreamExpressionParser.parse("concat(fields=\"fieldB,fieldA\", as=\"fieldABConcat\", delim=\"-\")"), factory);
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 concatMultipleFieldsWithIgnoredFields.
@Test
public void concatMultipleFieldsWithIgnoredFields() throws Exception {
Tuple tuple;
StreamOperation operation;
operation = new ConcatOperation(new String[] { "fieldA", "fieldB" }, "fieldABConcat", "-");
values.clear();
values.put("fieldA", "bar");
values.put("fieldB", "baz");
values.put("fieldC", "bab");
values.put("fieldD", "bat");
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("fieldC"));
Assert.assertEquals("bab", tuple.get("fieldC"));
Assert.assertNotNull(tuple.get("fieldD"));
Assert.assertEquals("bat", tuple.get("fieldD"));
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"));
}
Aggregations