use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method doPostRaw.
// Returns either an error or a result.
private Pair<QueryException, String> doPostRaw(final SqlQuery query, final HttpServletRequest req) throws Exception {
final Response response = resource.doPost(query, req);
if (response.getStatus() == 200) {
final StreamingOutput output = (StreamingOutput) response.getEntity();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
output.write(baos);
} catch (Exception ignored) {
// Suppress errors and return the response so far. Similar to what the real web server would do, if it
// started writing a 200 OK and then threw an exception in the middle.
}
return Pair.of(null, new String(baos.toByteArray(), StandardCharsets.UTF_8));
} else {
return Pair.of(JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryException.class), null);
}
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testCannotConvert_UnsupportedSQLQueryException.
/**
* This test is for {@link UnsupportedSQLQueryException} exceptions that are thrown by druid rules during query
* planning. e.g. doing max aggregation on string type. The test checks that the API returns correct error messages
* for such planning errors.
*/
@Test
public void testCannotConvert_UnsupportedSQLQueryException() throws Exception {
// max(string) unsupported
final QueryException exception = doPost(createSimpleQueryWithId("id", "SELECT max(dim1) FROM druid.foo")).lhs;
Assert.assertNotNull(exception);
Assert.assertEquals(PlanningError.UNSUPPORTED_SQL_ERROR.getErrorCode(), exception.getErrorCode());
Assert.assertEquals(PlanningError.UNSUPPORTED_SQL_ERROR.getErrorClass(), exception.getErrorClass());
Assert.assertTrue(exception.getMessage().contains("Cannot build plan for query: SELECT max(dim1) FROM druid.foo. " + "Possible error: Max aggregation is not supported for 'STRING' type"));
checkSqlRequestLog(false);
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testCannotConvert.
@Test
public void testCannotConvert() throws Exception {
// SELECT + ORDER unsupported
final QueryException exception = doPost(createSimpleQueryWithId("id", "SELECT dim1 FROM druid.foo ORDER BY dim1")).lhs;
Assert.assertNotNull(exception);
Assert.assertEquals(PlanningError.UNSUPPORTED_SQL_ERROR.getErrorCode(), exception.getErrorCode());
Assert.assertEquals(PlanningError.UNSUPPORTED_SQL_ERROR.getErrorClass(), exception.getErrorClass());
Assert.assertTrue(exception.getMessage().contains("Cannot build plan for query: SELECT dim1 FROM druid.foo ORDER BY dim1. " + "Possible error: SQL query requires order by non-time column [dim1 ASC] that is not supported."));
checkSqlRequestLog(false);
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testCannotValidate.
@Test
public void testCannotValidate() throws Exception {
final QueryException exception = doPost(createSimpleQueryWithId("id", "SELECT dim4 FROM druid.foo")).lhs;
Assert.assertNotNull(exception);
Assert.assertEquals(PlanningError.VALIDATION_ERROR.getErrorCode(), exception.getErrorCode());
Assert.assertEquals(PlanningError.VALIDATION_ERROR.getErrorClass(), exception.getErrorClass());
Assert.assertTrue(exception.getMessage().contains("Column 'dim4' not found in any table"));
checkSqlRequestLog(false);
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testResourceLimitExceeded.
@Test
public void testResourceLimitExceeded() throws Exception {
final QueryException exception = doPost(new SqlQuery("SELECT DISTINCT dim1 FROM foo", ResultFormat.OBJECT, false, false, false, ImmutableMap.of("maxMergingDictionarySize", 1, BaseQuery.SQL_QUERY_ID, "id"), null)).lhs;
Assert.assertNotNull(exception);
Assert.assertEquals(exception.getErrorCode(), ResourceLimitExceededException.ERROR_CODE);
Assert.assertEquals(exception.getErrorClass(), ResourceLimitExceededException.class.getName());
checkSqlRequestLog(false);
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
Aggregations