Skip to content

Commit

Permalink
SOLR-15974: Remove Calcite's ENUMERABLE_AGGREGATE_RULE as Solr only s…
Browse files Browse the repository at this point in the history
…upports push-down for LogicalAggregate (#626) (#627)
  • Loading branch information
thelabdude committed Feb 12, 2022
1 parent 00cb1e5 commit 5de92fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Expand Up @@ -621,6 +621,8 @@ Bug Fixes
* SOLR-14569: Configuring a shardHandlerFactory on the /select requestHandler results in HTTP 401 when searching on alias
in secured Solr. (Isabelle Giguere, Jason Gerlowski, Anshum Gupta, Mark Mark Miller)

* SOLR-15974: Remove Calcite's ENUMERABLE_AGGREGATE_RULE as Solr only supports push-down for LogicalAggregate (Timothy Potter, Kiran Chitturi)

================== 8.11.1 ==================

Bug Fixes
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.solr.handler.sql;

import org.apache.calcite.adapter.enumerable.EnumerableRules;
import org.apache.calcite.plan.*;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.TableScan;
Expand Down Expand Up @@ -74,6 +75,8 @@ public void register(RelOptPlanner planner) {
planner.addRule(rule);
}

// Solr's impl only supports LogicalAggregate, so don't let Calcite convert LogicalAggregate's to Enumerable (SOLR-15974)
planner.removeRule(EnumerableRules.ENUMERABLE_AGGREGATE_RULE);
planner.removeRule(CoreRules.FILTER_REDUCE_EXPRESSIONS); // prevent AND NOT from being reduced away, see SOLR-15461
}

Expand Down
26 changes: 26 additions & 0 deletions solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
Expand Up @@ -1494,6 +1494,14 @@ public void testAggregatesWithoutGrouping() throws Exception {
assertTrue(maxf == null);
assertTrue(avgf == null);

// test bunch of where predicates
sParams = mapParams(CommonParams.QT, "/sql",
"stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " +
"min(a_f), max(a_f), avg(a_f) from collection1 where id = 2 AND a_s='hello0' AND a_i=2 AND a_f=2");


tuples = getTuples(sParams, baseUrl);
assert (tuples.size() == 1);
}

@Test
Expand Down Expand Up @@ -2492,4 +2500,22 @@ public void testNotAndOrLogic() throws Exception {
// just a bunch of OR's that end up matching all docs
expectResults("SELECT id FROM $ALIAS WHERE a_s <> 'hello-1' OR a_i <> 2 OR d_s <> 'x' ORDER BY id ASC LIMIT 10", 4);
}

@Test
public void testCountWithManyFilters() throws Exception {
new UpdateRequest()
.add("id", "1", "a_s", "hello-1", "b_s", "foo", "c_s", "bar", "d_s", "x")
.add("id", "2", "a_s", "world-2", "b_s", "foo", "a_i", "2", "d_s", "a")
.add("id", "3", "a_s", "hello-3", "b_s", "foo", "c_s", "bar", "d_s", "x")
.add("id", "4", "a_s", "world-4", "b_s", "foo", "a_i", "3", "d_s", "b")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);

expectResults("SELECT COUNT(*) as QUERY_COUNT FROM $ALIAS WHERE (id='1')", 1);
expectResults("SELECT COUNT(*) as QUERY_COUNT FROM $ALIAS WHERE (d_s='x') AND (id='1')", 1);
expectResults("SELECT COUNT(*) as QUERY_COUNT FROM $ALIAS WHERE (d_s='x') AND (id='1') AND (b_s='foo')", 1);
expectResults("SELECT COUNT(1) as QUERY_COUNT FROM $ALIAS WHERE (d_s='x') AND (id='1') AND (b_s='foo')", 1);
expectResults("SELECT COUNT(1) as QUERY_COUNT FROM $ALIAS WHERE (d_s='x') AND (id='1') AND (b_s='foo') AND (a_s='hello-1')", 1);
expectResults("SELECT COUNT(*) as QUERY_COUNT, max(id) as max_id FROM $ALIAS WHERE (d_s='x') AND (id='1') AND (b_s='foo')", 1);
expectResults("SELECT COUNT(*) as QUERY_COUNT FROM $ALIAS WHERE (d_s='x') AND (id='1') AND (b_s='foo') HAVING COUNT(*) > 0", 1);
}
}

0 comments on commit 5de92fc

Please sign in to comment.