epugh commented on code in PR #3119:
URL: https://github.com/apache/solr/pull/3119#discussion_r3823108508
##########
solr/modules/sql/src/test/org/apache/solr/handler/sql/TestSQLHandler.java:
##########
@@ -3463,4 +3463,152 @@ public void testCustomUDFArrayContains() throws
Exception {
expectResults(
"select id, stringxmv from $ALIAS WHERE array_contains_any(stringxmv,
('a', 'e'))", 3);
}
+
+ /**
+ * Calcite 1.42+ constant-folds a WHERE predicate on the exact
grouped/aggregated column into a
+ * literal in the output project. These tests verify that the grouped column
value is returned
+ * correctly (not null) when the WHERE filters on the same column as GROUP
BY or DISTINCT.
+ */
+ @Test
+ public void testGroupByWhereOnGroupedColumn() throws Exception {
+ new UpdateRequest()
+ .add("id", "1", "str_s", "a", "field_i", "7")
+ .add("id", "2", "str_s", "b", "field_i", "8")
+ .add("id", "3", "str_s", "a", "field_i", "20")
+ .add("id", "4", "str_s", "b", "field_i", "11")
+ .add("id", "5", "str_s", "c", "field_i", "30")
+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+ String baseUrl =
+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" +
COLLECTIONORALIAS;
+
+ // WHERE on the exact grouped column (equality) — Calcite 1.42 may
constant-fold str_s to 'a'
+ SolrParams sParams =
+ params(
+ CommonParams.QT,
+ "/sql",
+ "aggregationMode",
+ "facet",
+ "stmt",
+ "select str_s, count(*), sum(field_i) from collection1"
+ + " where str_s = 'a' group by str_s order by str_s asc");
+
+ List<Tuple> tuples = getTuples(sParams, baseUrl);
+ assertEquals(1, tuples.size());
+ Tuple tuple = tuples.get(0);
+ assertEquals(
+ "str_s must not be null-folded by Calcite constant folding", "a",
tuple.get("str_s"));
+ assertEquals(2, tuple.getDouble("EXPR$1"), 0.0); // count(*)
+ assertEquals(27, tuple.getDouble("EXPR$2"), 0.0); // sum(field_i)
+
+ // Same query in map_reduce mode
+ sParams =
+ params(
+ CommonParams.QT,
Review Comment:
@gerlowskija you will hate me when I merge this ;-). I thought about not
doing it this way, but I think you have added some plumbing to make it easier
to deal with removing QT, so I'll leave it for now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]