npawar commented on a change in pull request #5635:
URL: https://github.com/apache/incubator-pinot/pull/5635#discussion_r447155218



##########
File path: 
pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java
##########
@@ -750,6 +753,136 @@ public void testSelectionTransformFunction() {
         
pinotQuery.getFilterExpression().getFunctionCall().getOperands().get(1).getLiteral().getStringValue(),
 "v1");
   }
 
+  @Test
+  public void testOrderByQueryCompilation() {
+    PinotQuery2BrokerRequestConverter converter = new 
PinotQuery2BrokerRequestConverter();
+
+    // both group by and order by in selection
+    String sql = "SELECT foo, COUNT(*) FROM myTable GROUP BY foo ORDER BY foo";
+    PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    BrokerRequest brokerRequest = converter.convert(pinotQuery);
+    List<AggregationInfo> aggregationInfos = 
brokerRequest.getAggregationsInfo();
+    Assert.assertEquals(aggregationInfos.size(), 1);
+    Assert.assertEquals(aggregationInfos.get(0).getAggregationType(), 
AggregationFunctionType.COUNT.toString());
+    Assert.assertEquals(aggregationInfos.get(0).getExpressions().get(0), "*");
+    List<SelectionSort> orderBy = brokerRequest.getOrderBy();
+    Assert.assertEquals(orderBy.size(), 1);
+    Assert.assertEquals(orderBy.get(0).getColumn(), "foo");
+
+    sql = "SELECT foo, COUNT(*) FROM myTable GROUP BY foo ORDER BY COUNT(*)";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    brokerRequest = converter.convert(pinotQuery);
+    aggregationInfos = brokerRequest.getAggregationsInfo();
+    Assert.assertEquals(aggregationInfos.size(), 1);
+    Assert.assertEquals(aggregationInfos.get(0).getAggregationType(), 
AggregationFunctionType.COUNT.toString());
+    Assert.assertEquals(aggregationInfos.get(0).getExpressions().get(0), "*");
+    orderBy = brokerRequest.getOrderBy();
+    Assert.assertEquals(orderBy.size(), 1);
+    Assert.assertEquals(orderBy.get(0).getColumn(), "count(*)");
+
+    sql = "SELECT foo FROM myTable GROUP BY foo ORDER BY foo";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    brokerRequest = converter.convert(pinotQuery);
+    Assert.assertNull(brokerRequest.getAggregationsInfo());
+    orderBy = brokerRequest.getOrderBy();
+    Assert.assertEquals(orderBy.size(), 1);
+    Assert.assertEquals(orderBy.get(0).getColumn(), "foo");
+
+    // aggregation not provided in selection
+    sql = "SELECT foo FROM myTable GROUP BY foo ORDER BY COUNT(*)";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    brokerRequest = converter.convert(pinotQuery);
+    aggregationInfos = brokerRequest.getAggregationsInfo();
+    Assert.assertEquals(aggregationInfos.size(), 1);
+    Assert.assertEquals(aggregationInfos.get(0).getAggregationType(), 
AggregationFunctionType.COUNT.toString());
+    Assert.assertEquals(aggregationInfos.get(0).getExpressions().get(0), "*");
+    orderBy = brokerRequest.getOrderBy();
+    Assert.assertEquals(orderBy.size(), 1);
+    Assert.assertEquals(orderBy.get(0).getColumn(), "count(*)");
+
+    // group by not provided in selection
+    sql = "SELECT COUNT(*) FROM myTable GROUP BY foo ORDER BY foo";

Review comment:
       we didn't relax any restriction. the columns in the result will still be 
only what is specified in the select




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to