yashmayya commented on code in PR #16626:
URL: https://github.com/apache/pinot/pull/16626#discussion_r2306776583
##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java:
##########
@@ -1736,6 +1737,243 @@ public void testValidateQueryApiError()
assertFalse(result.get("errorMessage").isNull());
}
+ @Test
+ public void testValidateQueryApiSuccessfulQueries() throws Exception {
+ JsonNode tableConfigsNode = JsonUtils.stringToJsonNode(
+ sendGetRequest(getControllerBaseApiUrl() + "/tables/mytable"));
+ JsonNode schemaNode = JsonUtils.stringToJsonNode(
+ sendGetRequest(getControllerBaseApiUrl() + "/schemas/mytable"));
+
+ String[] successfulQueries = {
+ "SELECT COUNT(*) FROM mytable",
+ "SELECT DivAirportSeqIDs, COUNT(*) FROM mytable GROUP BY
DivAirportSeqIDs",
+ "SELECT DivAirportSeqIDs FROM mytable WHERE
arrayToMV(DivAirportSeqIDs) > 0 LIMIT 10",
+ "SELECT DivAirportSeqIDs, AirlineID FROM mytable ORDER BY
DivAirportSeqIDs LIMIT 5",
+ "SELECT SUM(arrayToMV(DivAirportSeqIDs)) AS total FROM mytable",
+ "SELECT AVG(arrayToMV(DivAirportSeqIDs)) FROM mytable WHERE AirlineID
IS NOT NULL"
+ };
+
+ List<TableConfig> tableConfigs = new ArrayList<>();
+ JsonNode offlineConfig = tableConfigsNode.get("OFFLINE");
+ if (offlineConfig != null && !offlineConfig.isMissingNode() &&
!offlineConfig.isEmpty()) {
+ tableConfigs.add(JsonUtils.jsonNodeToObject(offlineConfig,
TableConfig.class));
+ }
+ JsonNode realtimeConfig = tableConfigsNode.get("REALTIME");
+ if (realtimeConfig != null && !realtimeConfig.isMissingNode() &&
!realtimeConfig.isEmpty()) {
+ tableConfigs.add(JsonUtils.jsonNodeToObject(realtimeConfig,
TableConfig.class));
+ }
+
+ Schema schema = JsonUtils.jsonNodeToObject(schemaNode, Schema.class);
+ List<Schema> schemas = Collections.singletonList(schema);
+
+ for (String query : successfulQueries) {
+ MultiStageQueryValidationRequest request = new
MultiStageQueryValidationRequest(
+ query, tableConfigs, schemas, null, false);
+
+ String requestJson = JsonUtils.objectToString(request);
+ JsonNode result = JsonUtils.stringToJsonNode(
+ sendPostRequest(getControllerBaseApiUrl() +
"/validateMultiStageQuery", requestJson, null));
+
+ assertTrue(result.get("compiledSuccessfully").asBoolean(),
+ "Query should compile successfully: " + query);
+ assertTrue(result.get("errorCode").isNull());
+ assertTrue(result.get("errorMessage").isNull());
+ }
+ }
+
+ @Test
+ public void testValidateQueryApiUnsuccessfulQueries() throws Exception {
+ JsonNode tableConfigsNode =
+ JsonUtils.stringToJsonNode(sendGetRequest(getControllerBaseApiUrl() +
"/tables/mytable"));
+ JsonNode schemaNode =
+ JsonUtils.stringToJsonNode(sendGetRequest(getControllerBaseApiUrl() +
"/schemas/mytable"));
+
+ List<TableConfig> tableConfigs = new ArrayList<>();
+ JsonNode offlineConfig = tableConfigsNode.get("OFFLINE");
+ if (offlineConfig != null && !offlineConfig.isMissingNode() &&
!offlineConfig.isEmpty()) {
+ tableConfigs.add(JsonUtils.jsonNodeToObject(offlineConfig,
TableConfig.class));
+ }
+ JsonNode realtimeConfig = tableConfigsNode.get("REALTIME");
+ if (realtimeConfig != null && !realtimeConfig.isMissingNode() &&
!realtimeConfig.isEmpty()) {
+ tableConfigs.add(JsonUtils.jsonNodeToObject(realtimeConfig,
TableConfig.class));
+ }
+
+ Schema schema = JsonUtils.jsonNodeToObject(schemaNode, Schema.class);
+ List<Schema> schemas = Collections.singletonList(schema);
+
+ // Invalid column in the query
+ MultiStageQueryValidationRequest request = new
MultiStageQueryValidationRequest(
+ "SELECT nonExistentColumn FROM mytable", tableConfigs, schemas, null,
true);
+
+ String requestJson = JsonUtils.objectToString(request);
+ JsonNode result = JsonUtils.stringToJsonNode(
+ sendPostRequest(getControllerBaseApiUrl() +
"/validateMultiStageQuery", requestJson, null));
+ assertFalse(result.get("compiledSuccessfully").asBoolean());
+ assertEquals(result.get("errorCode").asText(),
QueryErrorCode.QUERY_VALIDATION.name());
+
+ // Cannot apply '>' to arguments of type '<INTEGER> to <ARRAY>
+ String query = "SELECT DivAirportSeqIDs FROM mytable WHERE
DivAirportSeqIDs > 0 LIMIT 10";
+ request = new MultiStageQueryValidationRequest(query, tableConfigs,
schemas, null, false);
+
+ requestJson = JsonUtils.objectToString(request);
+ result = JsonUtils.stringToJsonNode(
+ sendPostRequest(getControllerBaseApiUrl() +
"/validateMultiStageQuery", requestJson, null));
+
+ assertFalse(result.get("compiledSuccessfully").asBoolean(), "Query should
not compile successfully: " + query);
+ assertEquals(result.get("errorCode").asText(),
QueryErrorCode.QUERY_VALIDATION.name());
+ assertFalse(result.get("errorMessage").isNull(), "Error message should not
be null for: " + query);
+
+ // Non-existent table
+ query = "SELECT count(*) FROM nonExistentTable";
+ request = new MultiStageQueryValidationRequest(query, tableConfigs,
schemas, null, false);
+
+ requestJson = JsonUtils.objectToString(request);
+ result = JsonUtils.stringToJsonNode(
+ sendPostRequest(getControllerBaseApiUrl() +
"/validateMultiStageQuery", requestJson, null));
+
+ assertFalse(result.get("compiledSuccessfully").asBoolean(), "Query should
not compile successfully: " + query);
+ assertEquals(result.get("errorCode").asText(),
QueryErrorCode.TABLE_DOES_NOT_EXIST.name());
+ assertFalse(result.get("errorMessage").isNull(), "Error message should not
be null for: " + query);
+ }
+
+ @Test
+ public void testValidateQueryApiWithStaticTable()
+ throws Exception {
+ String schemasStr =
+ "{\n" + " \"schemaName\": \"staticTableTest\",\n" + "
\"enableColumnBasedNullHandling\": false,\n"
+ + " \"dimensionFieldSpecs\": [\n" + " {\n" + " \"name\":
\"event_id\",\n"
+ + " \"dataType\": \"STRING\",\n" + " \"fieldType\":
\"DIMENSION\"\n" + " },\n" + " {\n"
+ + " \"name\": \"dummy_realtime\",\n" + " \"dataType\":
\"STRING\",\n"
+ + " \"fieldType\": \"DIMENSION\"\n" + " }\n" + " ],\n" +
" \"dateTimeFieldSpecs\": [\n"
+ + " {\n" + " \"name\": \"mtime\",\n" + "
\"dataType\": \"LONG\",\n"
+ + " \"fieldType\": \"DATE_TIME\",\n" + " \"format\":
\"1:MILLISECONDS:EPOCH\",\n"
+ + " \"granularity\": \"1:MILLISECONDS\"\n" + " }\n" + "
],\n" + " \"primaryKeyColumns\": [\n"
+ + " \"event_id\"\n" + " ]\n" + "}";
+
+ String tableConfigsStr =
Review Comment:
This makes things very unreadable, can't we use `TableConfigBuilder` and
`SchemaBuilder` instead?
--
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]