Skip to content

Apache Lucene open-source search software

SOLR-8593: Ensure the SolrSort is always pushed down

Joel Bernstein4ea97b08de1b
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
index 5f309265ff8..01d3346f333 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
@@ -129,7 +129,7 @@ class SolrFilter extends Filter implements SolrRel {
return "-"+translateComparison(((RexCall) node).getOperands().get(0));
case EQUALS:
String terms = binaryTranslated.getValue().getValue2().toString().trim();
- if(!terms.startsWith("(")){
+ if(!terms.startsWith("(") && !terms.startsWith("[") && !terms.startsWith("{")){
terms = "\""+terms+"\"";
}
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrSort.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrSort.java
index 751e841a72e..1c5274a2ca6 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrSort.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrSort.java
@@ -46,7 +46,7 @@ class SolrSort extends Sort implements SolrRel {
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
- return super.computeSelfCost(planner, mq).multiplyBy(0.05);
+ return planner.getCostFactory().makeZeroCost();
}
@Override
@@ -71,6 +71,7 @@ class SolrSort extends Sort implements SolrRel {
}
}
+
if(fetch != null) {
implementor.setLimit(((RexLiteral) fetch).getValue().toString());
}
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
index 14e69e63928..fff646887c7 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
@@ -106,6 +106,8 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
}
}
+ System.out.println("####### Limit:"+limit);
+
TupleStream tupleStream;
String zk = properties.getProperty("zk");
try {
@@ -456,13 +458,12 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
tupleStream = parallelStream;
}
- //TODO: This should be done on the workers, but it won't serialize because it relies on Presto classes.
- // Once we make this a Expressionable the problem will be solved.
-
+ //TODO: Currently we are not pushing down the having clause.
+ // We need to push down the having clause to ensure that LIMIT does not cut off records prior to the having filter.
if(orders != null && orders.size() > 0) {
- int lim = limit == null ? 100 : Integer.parseInt(limit);
if(!sortsEqual(buckets, sortDirection, orders)) {
+ int lim = (limit == null) ? 100 : Integer.parseInt(limit);
StreamComparator comp = getComp(orders);
//Rank the Tuples
//If parallel stream is used ALL the Rolled up tuples from the workers will be ranked
@@ -471,10 +472,15 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
} else {
// Sort is the same as the same as the underlying stream
// Only need to limit the result, not Rank the result
- if(lim > -1) {
- tupleStream = new LimitStream(tupleStream, lim);
+ if(limit != null) {
+ tupleStream = new LimitStream(tupleStream, Integer.parseInt(limit));
}
}
+ } else {
+ //No order by, check for limit
+ if(limit != null) {
+ tupleStream = new LimitStream(tupleStream, Integer.parseInt(limit));
+ }
}
return tupleStream;