mirror of https://github.com/apache/lucene.git
SOLR-8530: Add support for single quoted aggregate HAVING comparisons
This commit is contained in:
parent
db7d2ff162
commit
ccdbb6ac0e
|
@ -54,7 +54,7 @@ public class EqualsOperation extends LeafOperation {
|
|||
|
||||
public StreamExpression toExpression(StreamFactory factory) throws IOException {
|
||||
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||
expression.addParameter(field);
|
||||
expression.addParameter(quote(field));
|
||||
expression.addParameter(Double.toString(val));
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GreaterThanEqualToOperation extends LeafOperation {
|
|||
|
||||
public StreamExpression toExpression(StreamFactory factory) throws IOException {
|
||||
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||
expression.addParameter(field);
|
||||
expression.addParameter(quote(field));
|
||||
expression.addParameter(Double.toString(val));
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GreaterThanOperation extends LeafOperation {
|
|||
|
||||
public StreamExpression toExpression(StreamFactory factory) throws IOException {
|
||||
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||
expression.addParameter(field);
|
||||
expression.addParameter(quote(field));
|
||||
expression.addParameter(Double.toString(val));
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public abstract class LeafOperation implements BooleanOperation {
|
|||
|
||||
public LeafOperation(StreamExpression expression, StreamFactory factory) throws IOException {
|
||||
this.field = factory.getValueOperand(expression, 0);
|
||||
this.field = this.field.replace("'","");
|
||||
this.val = Double.parseDouble(factory.getValueOperand(expression, 1));
|
||||
}
|
||||
|
||||
|
@ -56,4 +57,12 @@ public abstract class LeafOperation implements BooleanOperation {
|
|||
.withImplementingClass(getClass().getName())
|
||||
.withExpression(toExpression(factory).toString());
|
||||
}
|
||||
|
||||
protected String quote(String s) {
|
||||
if(s.contains("(")) {
|
||||
return "'"+s+"'";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class LessThanEqualToOperation extends LeafOperation {
|
|||
|
||||
public StreamExpression toExpression(StreamFactory factory) throws IOException {
|
||||
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||
expression.addParameter(field);
|
||||
expression.addParameter(quote(field));
|
||||
expression.addParameter(Double.toString(val));
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class LessThanOperation extends LeafOperation {
|
|||
|
||||
public StreamExpression toExpression(StreamFactory factory) throws IOException {
|
||||
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||
expression.addParameter(field);
|
||||
expression.addParameter(quote(field));
|
||||
expression.addParameter(Double.toString(val));
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -837,6 +837,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
.withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
|
||||
.withFunctionName("search", CloudSolrStream.class)
|
||||
.withFunctionName("having", HavingStream.class)
|
||||
.withFunctionName("rollup", RollupStream.class)
|
||||
.withFunctionName("sum", SumMetric.class)
|
||||
.withFunctionName("and", AndOperation.class)
|
||||
.withFunctionName("or", OrOperation.class)
|
||||
.withFunctionName("not", NotOperation.class)
|
||||
|
@ -895,7 +897,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
stream.setStreamContext(context);
|
||||
tuples = getTuples(stream);
|
||||
|
||||
System.out.println("####Tuples:"+tuples.size());
|
||||
assert(tuples.size() == 2);
|
||||
|
||||
t = tuples.get(0);
|
||||
|
@ -904,6 +905,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
t = tuples.get(1);
|
||||
assertTrue(t.getString("id").equals("9"));
|
||||
|
||||
|
||||
stream = factory.constructStream("having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\")), eq('sum(a_i)', 9))");
|
||||
context = new StreamContext();
|
||||
context.setSolrClientCache(solrClientCache);
|
||||
stream.setStreamContext(context);
|
||||
tuples = getTuples(stream);
|
||||
|
||||
assert(tuples.size() == 1);
|
||||
|
||||
t = tuples.get(0);
|
||||
assertTrue(t.getDouble("a_f") == 10.0D);
|
||||
|
||||
solrClientCache.close();
|
||||
}
|
||||
|
||||
|
@ -933,6 +946,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
.withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
|
||||
.withFunctionName("search", CloudSolrStream.class)
|
||||
.withFunctionName("having", HavingStream.class)
|
||||
.withFunctionName("rollup", RollupStream.class)
|
||||
.withFunctionName("sum", SumMetric.class)
|
||||
.withFunctionName("and", AndOperation.class)
|
||||
.withFunctionName("or", OrOperation.class)
|
||||
.withFunctionName("not", NotOperation.class)
|
||||
|
@ -992,7 +1007,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
stream.setStreamContext(context);
|
||||
tuples = getTuples(stream);
|
||||
|
||||
System.out.println("####Tuples:"+tuples.size());
|
||||
assert(tuples.size() == 2);
|
||||
|
||||
t = tuples.get(0);
|
||||
|
@ -1001,6 +1015,19 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
t = tuples.get(1);
|
||||
assertTrue(t.getString("id").equals("9"));
|
||||
|
||||
stream = factory.constructStream("parallel("+COLLECTIONORALIAS+", workers=2, sort=\"a_f asc\", having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=a_f)), eq('sum(a_i)', 9)))");
|
||||
context = new StreamContext();
|
||||
context.setSolrClientCache(solrClientCache);
|
||||
stream.setStreamContext(context);
|
||||
tuples = getTuples(stream);
|
||||
|
||||
assert(tuples.size() == 1);
|
||||
|
||||
t = tuples.get(0);
|
||||
assertTrue(t.getDouble("a_f") == 10.0D);
|
||||
|
||||
|
||||
|
||||
solrClientCache.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue