richardstartin commented on a change in pull request #7861:
URL: https://github.com/apache/pinot/pull/7861#discussion_r761917798



##########
File path: 
pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java
##########
@@ -2387,4 +2387,48 @@ private void testSupportedDistinctQuery(String query) {
     PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
     Assert.assertNotNull(pinotQuery);
   }
+
+  @Test
+  public void testQueryWithSemicolon() {
+    String sql;
+    PinotQuery pinotQuery;
+    sql = "SELECT col1, col2 FROM foo;";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    Assert.assertEquals(pinotQuery.getSelectListSize(), 2);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getIdentifier().getName(),
 "col1");
+    
Assert.assertEquals(pinotQuery.getSelectList().get(1).getIdentifier().getName(),
 "col2");
+
+    // Query having extra white spaces before the semicolon
+    sql = "SELECT col1, col2 FROM foo                 ;";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    Assert.assertEquals(pinotQuery.getSelectListSize(), 2);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getIdentifier().getName(),
 "col1");
+    
Assert.assertEquals(pinotQuery.getSelectList().get(1).getIdentifier().getName(),
 "col2");
+
+    sql = "SELECT col1, count(*) FROM foo group by col1;";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    Assert.assertEquals(pinotQuery.getSelectListSize(), 2);
+    
Assert.assertEquals(pinotQuery.getSelectList().get(0).getIdentifier().getName(),
 "col1");
+    Assert.assertEquals(pinotQuery.getGroupByListSize(), 1);
+    
Assert.assertEquals(pinotQuery.getGroupByList().get(0).getIdentifier().getName(),
 "col1");
+    
Assert.assertEquals(pinotQuery.getGroupByList().get(0).getIdentifier().getName(),
 "col1");
+
+    // Check for Option SQL Query
+    sql = "SELECT col1, count(*) FROM foo group by col1 
option(skipUpsert=true);";
+    pinotQuery = CalciteSqlParser.compileToPinotQuery(sql);
+    Assert.assertEquals(pinotQuery.getQueryOptionsSize(), 1);
+    Assert.assertTrue(pinotQuery.getQueryOptions().containsKey("skipUpsert"));
+  }
+
+  @Test
+  public void testInvalidQueryWithSemicolon() {
+    Assert.expectThrows(SqlCompilationException.class,
+            () -> CalciteSqlParser.compileToPinotQuery(";"));
+
+    Assert.expectThrows(SqlCompilationException.class,
+            () -> CalciteSqlParser.compileToPinotQuery(";;;;"));
+
+    Assert.expectThrows(SqlCompilationException.class,
+            () -> CalciteSqlParser.compileToPinotQuery("SELECT col1, count(*) 
FROM foo GROUP BY ; col1"));
+  }

Review comment:
       I really appreciate seeing good test cases along with this contribution 
👍🏻 
   
   One test case which I think should fail because only one of the submitted 
queries will be executed, but won't, is this one:
   
   ```
   SELECT col1, count(*) FROM foo GROUP BY col1; 
   SELECT col2, count(*) FROM foo GROUP BY col2 ;
   ```




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