siddharthteotia commented on code in PR #10054:
URL: https://github.com/apache/pinot/pull/10054#discussion_r1065443385


##########
pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java:
##########
@@ -1783,13 +1783,111 @@ public void testDistinctCountRewrite() {
   }
 
   @Test
-  public void testInvalidDistinctCountRewrite() {
+  public void testDistinctSumRewrite() {
     String query = "SELECT sum(distinct bar) FROM foo";
+    PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
+    Assert.assertEquals(pinotQuery.getSelectList().size(), 1);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "distinctsum");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "bar");
+
+    query = "SELECT sum(distinct bar) FROM foo GROUP BY city";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
+    Assert.assertEquals(pinotQuery.getSelectList().size(), 1);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "distinctsum");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "bar");
+
+    query = "SELECT sum(distinct bar), distinctSum(bar) FROM foo GROUP BY 
city";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
+    Assert.assertEquals(pinotQuery.getSelectList().size(), 2);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "distinctsum");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "bar");
+
+    
Assert.assertEquals(pinotQuery.getSelectList().get(1).getFunctionCall().getOperator(),
 "distinctsum");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(1).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "bar");
+
+    query = "SELECT sum(distinct bar), count(*), sum(a),min(a),max(b) FROM foo 
GROUP BY city";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
+    Assert.assertEquals(pinotQuery.getSelectList().size(), 5);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getFunctionCall().getOperator(),
 "distinctsum");
+    Assert.assertEquals(
+        
pinotQuery.getSelectList().get(0).getFunctionCall().getOperands().get(0).getIdentifier().getName(),
 "bar");
+
+    query = "SELECT sum(distinct bar) AS distinct_bar, count(*), 
sum(a),min(a),max(b) FROM foo GROUP BY city";

Review Comment:
   Consider adding another example where this new function is also used in 
ORDER BY 



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to