Search in sources :

Example 16 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method getActiveQueryCount.

@Override
public int getActiveQueryCount(NamespaceId namespace) throws ExploreException {
    String resource = String.format("namespaces/%s/data/explore/queries/count", namespace.getEntityName());
    HttpResponse response = doGet(resource);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        Map<String, String> mapResponse = parseJson(response, new TypeToken<Map<String, String>>() {
        }.getType());
        return Integer.parseInt(mapResponse.get("count"));
    }
    throw new ExploreException("Cannot get list of queries. Reason: " + response);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 17 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method execute.

@Override
public QueryHandle execute(NamespaceId namespace, String statement, @Nullable Map<String, String> additionalSessionConf) throws ExploreException {
    Map<String, String> bodyMap = additionalSessionConf == null ? ImmutableMap.of("query", statement) : ImmutableMap.<String, String>builder().put("query", statement).putAll(additionalSessionConf).build();
    HttpResponse response = doPost(String.format("namespaces/%s/data/explore/queries", namespace.getEntityName()), GSON.toJson(bodyMap), null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException("Cannot execute query. Reason: " + response);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 18 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method getFunctions.

@Override
public QueryHandle getFunctions(@Nullable String catalog, @Nullable String schemaPattern, String functionNamePattern) throws ExploreException, SQLException {
    String body = GSON.toJson(new FunctionsArgs(catalog, schemaPattern, functionNamePattern));
    String resource = String.format("namespaces/%s/data/explore/jdbc/functions", schemaPattern);
    HttpResponse response = doPost(resource, body, null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException("Cannot get the functions. Reason: " + response);
}
Also used : FunctionsArgs(io.cdap.cdap.explore.utils.FunctionsArgs) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 19 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method getColumns.

@Override
public QueryHandle getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws ExploreException, SQLException {
    String body = GSON.toJson(new ColumnsArgs(catalog, schemaPattern, tableNamePattern, columnNamePattern));
    String resource = String.format("namespaces/%s/data/explore/jdbc/columns", schemaPattern);
    HttpResponse response = doPost(resource, body, null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException("Cannot get the columns. Reason: " + response);
}
Also used : ColumnsArgs(io.cdap.cdap.explore.utils.ColumnsArgs) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 20 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method getTableInfo.

@Override
public TableInfo getTableInfo(String namespace, @Nullable String databaseName, String table) throws ExploreException, TableNotFoundException {
    String url = String.format("namespaces/%s/data/explore/tables/%s/info", namespace, table);
    if (databaseName != null) {
        url += "?database=" + databaseName;
    }
    HttpResponse response = doGet(url);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return parseJson(response, TableInfo.class);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new TableNotFoundException(String.format("Namespace %s, table %s not found.", namespace, table));
    }
    throw new ExploreException(String.format("Cannot get the schema of namespace %s, table %s. Reason: %s", namespace, table, response));
}
Also used : TableNotFoundException(io.cdap.cdap.explore.service.TableNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Aggregations

ExploreException (io.cdap.cdap.explore.service.ExploreException)86 QueryHandle (io.cdap.cdap.proto.QueryHandle)32 SQLException (java.sql.SQLException)28 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)28 IOException (java.io.IOException)24 OperationHandle (org.apache.hive.service.cli.OperationHandle)24 SessionHandle (org.apache.hive.service.cli.SessionHandle)24 HttpResponse (io.cdap.common.http.HttpResponse)22 Path (javax.ws.rs.Path)14 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)12 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)10 POST (javax.ws.rs.POST)10 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)8 BadRequestException (io.cdap.cdap.common.BadRequestException)8 TableNotFoundException (io.cdap.cdap.explore.service.TableNotFoundException)8 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)8 TException (org.apache.thrift.TException)8 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)6