Search in sources :

Example 11 with SqlQuery

use of org.apache.druid.sql.http.SqlQuery in project druid by apache.

the class AsyncQueryForwardingServlet method sendProxyRequest.

@Override
protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest) {
    proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
    proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
    byte[] avaticaQuery = (byte[]) clientRequest.getAttribute(AVATICA_QUERY_ATTRIBUTE);
    if (avaticaQuery != null) {
        proxyRequest.content(new BytesContentProvider(avaticaQuery));
    }
    final Query query = (Query) clientRequest.getAttribute(QUERY_ATTRIBUTE);
    final SqlQuery sqlQuery = (SqlQuery) clientRequest.getAttribute(SQL_QUERY_ATTRIBUTE);
    if (query != null) {
        setProxyRequestContent(proxyRequest, clientRequest, query);
    } else if (sqlQuery != null) {
        setProxyRequestContent(proxyRequest, clientRequest, sqlQuery);
    }
    // Since we can't see the request object on the remote side, we can't check whether the remote side actually
    // performed an authorization check here, so always set this to true for the proxy servlet.
    // If the remote node failed to perform an authorization check, PreResponseAuthorizationCheckFilter
    // will log that on the remote node.
    clientRequest.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
    // Check if there is an authentication result and use it to decorate the proxy request if needed.
    AuthenticationResult authenticationResult = (AuthenticationResult) clientRequest.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT);
    if (authenticationResult != null && authenticationResult.getAuthenticatedBy() != null) {
        Authenticator authenticator = authenticatorMapper.getAuthenticatorMap().get(authenticationResult.getAuthenticatedBy());
        if (authenticator != null) {
            authenticator.decorateProxyRequest(clientRequest, proxyResponse, proxyRequest);
        } else {
            LOG.error("Can not find Authenticator with Name [%s]", authenticationResult.getAuthenticatedBy());
        }
    }
    super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
}
Also used : SqlQuery(org.apache.druid.sql.http.SqlQuery) Query(org.apache.druid.query.Query) SqlQuery(org.apache.druid.sql.http.SqlQuery) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) Authenticator(org.apache.druid.server.security.Authenticator) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

Example 12 with SqlQuery

use of org.apache.druid.sql.http.SqlQuery in project druid by apache.

the class SqlQueryTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper jsonMapper = TestHelper.makeJsonMapper();
    final SqlQuery query = new SqlQuery("SELECT ?", ResultFormat.ARRAY, true, true, true, ImmutableMap.of("useCache", false), ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1)));
    Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), SqlQuery.class));
}
Also used : SqlQuery(org.apache.druid.sql.http.SqlQuery) SqlParameter(org.apache.druid.sql.http.SqlParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

SqlQuery (org.apache.druid.sql.http.SqlQuery)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ISE (org.apache.druid.java.util.common.ISE)4 RE (org.apache.druid.java.util.common.RE)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 Query (org.apache.druid.query.Query)4 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)4 Test (org.junit.Test)4 Test (org.testng.annotations.Test)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Future (java.util.concurrent.Future)2 ServletException (javax.servlet.ServletException)2 Service (org.apache.calcite.avatica.remote.Service)2 Server (org.apache.druid.client.selector.Server)2 QueryException (org.apache.druid.query.QueryException)2