Search in sources :

Example 1 with StreamOperation

use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.

the class ConcatOperationTest method concatMultipleFieldsWithIgnoredFieldsExpression.

@Test
public void concatMultipleFieldsWithIgnoredFieldsExpression() 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");
    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(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"));
}
Also used : ConcatOperation(org.apache.solr.client.solrj.io.ops.ConcatOperation) StreamOperation(org.apache.solr.client.solrj.io.ops.StreamOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 2 with StreamOperation

use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.

the class OperationsTest method replaceFieldNullWithString.

@Test
public void replaceFieldNullWithString() throws Exception {
    Tuple tuple;
    StreamOperation operation;
    operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withField=fieldB)"), 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("bar", 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"));
}
Also used : ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) StreamOperation(org.apache.solr.client.solrj.io.ops.StreamOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 3 with StreamOperation

use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.

the class OperationsTest method replaceValueNullWithInt.

@Test
public void replaceValueNullWithInt() throws Exception {
    Tuple tuple;
    StreamOperation operation;
    operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withValue=123)"), factory);
    // replace
    values.clear();
    values.put("fieldB", "bar");
    values.put("fieldC", (long) 123);
    tuple = new Tuple(values);
    operation.operate(tuple);
    Assert.assertNotNull(tuple.get("fieldA"));
    Assert.assertEquals((long) 123, 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"));
}
Also used : ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) StreamOperation(org.apache.solr.client.solrj.io.ops.StreamOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 4 with StreamOperation

use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.

the class OperationsTest method replaceValueNullWithDouble.

@Test
public void replaceValueNullWithDouble() throws Exception {
    Tuple tuple;
    StreamOperation operation;
    operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withValue=123.45678912345)"), 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.45678912345, 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"));
}
Also used : ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) StreamOperation(org.apache.solr.client.solrj.io.ops.StreamOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 5 with StreamOperation

use of org.apache.solr.client.solrj.io.ops.StreamOperation in project lucene-solr by apache.

the class OperationsTest method replaceFieldNullWithInt.

@Test
public void replaceFieldNullWithInt() throws Exception {
    Tuple tuple;
    StreamOperation operation;
    operation = new ReplaceOperation("fieldA", StreamExpressionParser.parse("replace(null, withField=fieldC)"), 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, 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"));
}
Also used : ReplaceOperation(org.apache.solr.client.solrj.io.ops.ReplaceOperation) StreamOperation(org.apache.solr.client.solrj.io.ops.StreamOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Aggregations

Tuple (org.apache.solr.client.solrj.io.Tuple)16 StreamOperation (org.apache.solr.client.solrj.io.ops.StreamOperation)16 Test (org.junit.Test)15 ConcatOperation (org.apache.solr.client.solrj.io.ops.ConcatOperation)8 ReplaceOperation (org.apache.solr.client.solrj.io.ops.ReplaceOperation)7 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StreamEvaluator (org.apache.solr.client.solrj.io.eval.StreamEvaluator)1