You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/05/19 21:00:59 UTC
[GitHub] [incubator-pinot] amrishlal commented on a change in pull request #6942: Detect invalid column names from SQL query in BrokerRequestHandler
amrishlal commented on a change in pull request #6942:
URL: https://github.com/apache/incubator-pinot/pull/6942#discussion_r635581806
##########
File path: pinot-broker/src/test/java/org/apache/pinot/broker/requesthandler/QueryValidationTest.java
##########
@@ -131,10 +136,68 @@ private void testUnsupportedPQLQuery(String query, String errorMessage) {
private void testUnsupportedSQLQuery(String query, String errorMessage) {
try {
PinotQuery pinotQuery = CalciteSqlParser.compileToPinotQuery(query);
- BaseBrokerRequestHandler.validateRequest(pinotQuery, 1000);
+ BaseBrokerRequestHandler.validateRequest(pinotQuery, 1000, "testTable", null, null);
Assert.fail("Query should have failed");
} catch (Exception e) {
Assert.assertEquals(errorMessage, e.getMessage());
}
}
+
+ @Test
+ public void testInvalidColumnNames() {
+ BrokerMetrics brokerMetrics = new BrokerMetrics(PinotMetricUtils.getPinotMetricsRegistry());
+ Set<String> columnNamesFromSchema = Sets.newHashSet("column1", "column2", "column3");
+
+ String sql = "SELECT * FROM testTable LIMIT 100";
+ Assert.assertEquals(getInvalidColumnNamesCount(sql, columnNamesFromSchema, brokerMetrics), 0L);
+
+ sql = "SELECT column1 FROM testTable LIMIT 100";
+ Assert.assertEquals(getInvalidColumnNamesCount(sql, columnNamesFromSchema, brokerMetrics), 0L);
+
+ sql = "SELECT column1 FROM testTable WHERE column2 = '1' LIMIT 100";
Review comment:
Can you also add a few test cases using AS. `For example: SELECT x AS column1, y AS column2 FROM testTable`.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org