Search in sources :

Example 1 with QueryException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) ForbiddenException(org.apache.druid.server.security.ForbiddenException) QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) QueryException(org.apache.druid.query.QueryException) QueryCapacityExceededException(org.apache.druid.query.QueryCapacityExceededException) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) IOException(java.io.IOException) RelConversionException(org.apache.calcite.tools.RelConversionException) ResourceLimitExceededException(org.apache.druid.query.ResourceLimitExceededException) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException)

Example 2 with QueryException

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());
}
Also used : UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) Test(org.junit.Test)

Example 3 with QueryException

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());
}
Also used : UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) Test(org.junit.Test)

Example 4 with QueryException

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());
}
Also used : UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) Test(org.junit.Test)

Example 5 with QueryException

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());
}
Also used : UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) ResourceLimitExceededException(org.apache.druid.query.ResourceLimitExceededException) Test(org.junit.Test)

Aggregations

QueryException (org.apache.druid.query.QueryException)25 Test (org.junit.Test)22 UnsupportedSQLQueryException (org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException)13 IOException (java.io.IOException)9 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)9 ServerConfig (org.apache.druid.server.initialization.ServerConfig)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 Response (javax.ws.rs.core.Response)7 AllowedRegexErrorResponseTransformStrategy (org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Properties (java.util.Properties)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 DefaultGenericQueryMetricsFactory (org.apache.druid.query.DefaultGenericQueryMetricsFactory)6 MapQueryToolChestWarehouse (org.apache.druid.query.MapQueryToolChestWarehouse)6 QueryUnsupportedException (org.apache.druid.query.QueryUnsupportedException)6 BaseJettyTest (org.apache.druid.server.initialization.BaseJettyTest)6 NoopRequestLogger (org.apache.druid.server.log.NoopRequestLogger)6 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)6 AuthenticatorMapper (org.apache.druid.server.security.AuthenticatorMapper)6