Search in sources :

Example 1 with StreamExpressionValue

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue in project lucene-solr by apache.

the class RawValueEvaluator method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(getClass()));
    expression.addParameter(new StreamExpressionValue(value.toString()));
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionValue(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue)

Example 2 with StreamExpressionValue

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue in project lucene-solr by apache.

the class UpdateStream method extractBatchSize.

private int extractBatchSize(StreamExpression expression, StreamFactory factory) throws IOException {
    StreamExpressionNamedParameter batchSizeParam = factory.getNamedOperand(expression, "batchSize");
    if (null == batchSizeParam || null == batchSizeParam.getParameter() || !(batchSizeParam.getParameter() instanceof StreamExpressionValue)) {
        throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - expecting a 'batchSize' parameter of type positive integer but didn't find one", expression));
    }
    String batchSizeStr = ((StreamExpressionValue) batchSizeParam.getParameter()).getValue();
    return parseBatchSize(batchSizeStr, expression);
}
Also used : StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) StreamExpressionValue(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue) IOException(java.io.IOException)

Example 3 with StreamExpressionValue

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue in project lucene-solr by apache.

the class StreamExpressionParserTest method testParsing.

@Test
public void testParsing() throws Exception {
    StreamExpression actual, expected;
    actual = StreamExpressionParser.parse("aliases(a_i=alias.a_i)");
    expected = new StreamExpression("aliases").withParameter(new StreamExpressionNamedParameter("a_i", "alias.a_i"));
    assertEquals(expected, actual);
    actual = StreamExpressionParser.parse("search(a,b)");
    expected = new StreamExpression("search").withParameter("a").withParameter("b");
    assertEquals(expected, actual);
    actual = StreamExpressionParser.parse("search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\")");
    expected = new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc"));
    assertEquals(expected, actual);
    actual = StreamExpressionParser.parse("unique(search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\"))");
    expected = new StreamExpression("unique").withParameter(new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc")));
    assertEquals(expected, actual);
    actual = StreamExpressionParser.parse("unique(search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\"), alt=search(collection1, foo=bar))");
    expected = new StreamExpression("unique").withParameter(new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc"))).withParameter(new StreamExpressionNamedParameter("alt").withParameter(new StreamExpression("search").withParameter("collection1").withParameter(new StreamExpressionNamedParameter("foo").withParameter("bar"))));
    assertEquals(expected, actual);
    actual = StreamExpressionParser.parse("innerJoin(" + "left=search(collection1, q=*:*, fl=\"fieldA,fieldB,fieldC\", sort=\"fieldA asc, fieldB asc\")," + "right=search(collection2, q=*:*, fl=\"fieldA,fieldD\", sort=fieldA asc)," + "on(equals(fieldA), notEquals(fieldC,fieldD))" + ")");
    expected = new StreamExpression("innerJoin").withParameter(new StreamExpressionNamedParameter("left").withParameter(new StreamExpression("search").withParameter("collection1").withParameter(new StreamExpressionNamedParameter("q", "*:*")).withParameter(new StreamExpressionNamedParameter("fl", "fieldA,fieldB,fieldC")).withParameter(new StreamExpressionNamedParameter("sort", "fieldA asc, fieldB asc")))).withParameter(new StreamExpressionNamedParameter("right").withParameter(new StreamExpression("search").withParameter("collection2").withParameter(new StreamExpressionNamedParameter("q", "*:*")).withParameter(new StreamExpressionNamedParameter("fl", "fieldA,fieldD")).withParameter(new StreamExpressionNamedParameter("sort", "fieldA asc")))).withParameter(new StreamExpression("on").withParameter(new StreamExpression("equals").withParameter("fieldA")).withParameter(new StreamExpression("notEquals").withParameter("fieldC").withParameter("fieldD")));
    assertEquals(expected, actual);
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) StreamExpressionValue(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue) Test(org.junit.Test)

Aggregations

StreamExpressionValue (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue)3 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)2 StreamExpressionNamedParameter (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)2 IOException (java.io.IOException)1 Test (org.junit.Test)1