Search in sources :

Example 11 with Tuple

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

the class EvalStream method open.

public void open() throws IOException {
    try {
        stream.open();
        Tuple tuple = stream.read();
        String expr = tuple.getString("expr_s");
        if (expr == null) {
            throw new IOException("expr_s cannot be empty for the EvalStream");
        }
        evalStream = streamFactory.constructStream(expr);
        evalStream.setStreamContext(streamContext);
        evalStream.open();
    } finally {
        stream.close();
    }
}
Also used : IOException(java.io.IOException) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 12 with Tuple

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

the class HashJoinStream method read.

public Tuple read() throws IOException {
    findNextWorkingFullTuple: while (null == workingFullTuple) {
        Tuple fullTuple = fullStream.read();
        // We're at the end of the line
        if (fullTuple.EOF) {
            return fullTuple;
        }
        // If fullTuple doesn't have a valid hash or if there is no doc to 
        // join with then retry loop - keep going until we find one
        Integer fullHash = calculateHash(fullTuple, leftHashOn);
        if (null == fullHash || !hashedTuples.containsKey(fullHash)) {
            continue findNextWorkingFullTuple;
        }
        workingFullTuple = fullTuple;
        workingFullHash = fullHash;
        workngHashSetIdx = 0;
    }
    // At this point we know we have at least one doc to match on
    // Due to the check at the end, before returning, we know we have at least one to match with left
    List<Tuple> matches = hashedTuples.get(workingFullHash);
    Tuple returnTuple = workingFullTuple.clone();
    returnTuple.merge(matches.get(workngHashSetIdx));
    // Increment this so the next time we hit the next matching tuple
    workngHashSetIdx++;
    if (workngHashSetIdx >= matches.size()) {
        // well, now we've reached all the matches, clear it all out
        workingFullTuple = null;
        workingFullHash = null;
        workngHashSetIdx = 0;
    }
    return returnTuple;
}
Also used : Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 13 with Tuple

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

the class CartesianProductStream method read.

public Tuple read() throws IOException {
    if (generatedTuples.isEmpty()) {
        Tuple tuple = stream.read();
        if (tuple.EOF) {
            return tuple;
        }
        // returns tuples in desired sorted order
        generatedTuples = generateTupleList(tuple);
    }
    return generatedTuples.pop();
}
Also used : Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 14 with Tuple

use of org.apache.solr.client.solrj.io.Tuple 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));
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 15 with Tuple

use of org.apache.solr.client.solrj.io.Tuple 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);
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Aggregations

Tuple (org.apache.solr.client.solrj.io.Tuple)382 Test (org.junit.Test)259 StreamEvaluator (org.apache.solr.client.solrj.io.eval.StreamEvaluator)135 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)114 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)92 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)88 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)64 HashMap (java.util.HashMap)54 ArrayList (java.util.ArrayList)47 SolrParams (org.apache.solr.common.params.SolrParams)43 Map (java.util.Map)41 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)36 IOException (java.io.IOException)34 List (java.util.List)28 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)23 StreamOperation (org.apache.solr.client.solrj.io.ops.StreamOperation)16 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)15 SolrStream (org.apache.solr.client.solrj.io.stream.SolrStream)15 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)15 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)14