Search in sources :

Example 41 with ExploreException

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

the class ExploreHttpClient method doDisableExploreDataset.

protected QueryHandle doDisableExploreDataset(DatasetId datasetInstance, DatasetSpecification spec) throws ExploreException {
    String body = spec == null ? null : GSON.toJson(new DisableExploreParameters(spec));
    String endpoint = spec == null ? "disable" : "disable-internal";
    HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetInstance.getNamespace(), datasetInstance.getEntityName(), endpoint), body, null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException(String.format("Cannot disable explore on dataset %s. Reason: %s", datasetInstance.toString(), response));
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 42 with ExploreException

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

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 43 with ExploreException

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

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)

Example 44 with ExploreException

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

the class ExploreHttpClient method doPartitionOperation.

private QueryHandle doPartitionOperation(DatasetId datasetId, DatasetSpecification spec, PartitionKey key, String endpoint, String operationName, Map<String, String> additionalArguments) throws ExploreException {
    Map<String, String> args = new HashMap<>(additionalArguments);
    PartitionedFileSetArguments.setOutputPartitionKey(args, key);
    String tableName = ExploreProperties.getExploreTableName(spec.getProperties());
    String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties());
    if (tableName != null) {
        args.put(ExploreProperties.PROPERTY_EXPLORE_TABLE_NAME, tableName);
    }
    if (databaseName != null) {
        args.put(ExploreProperties.PROPERTY_EXPLORE_DATABASE_NAME, databaseName);
    }
    HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetId.getNamespace(), datasetId.getEntityName(), endpoint), GSON.toJson(args), null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException(String.format("Cannot %s partition with key %s in dataset %s. Reason: %s", operationName, key, datasetId.toString(), response));
}
Also used : HashMap(java.util.HashMap) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 45 with ExploreException

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

the class ExploreResultSet method getMetaData.

@Override
public ResultSetMetaData getMetaData() throws SQLException {
    if (isClosed()) {
        throw new SQLException("Resultset is closed");
    }
    if (metaData == null) {
        try {
            List<ColumnDesc> columnDescs = executionResult.getResultSchema();
            metaData = new ExploreResultSetMetaData(columnDescs);
        } catch (ExploreException e) {
            LOG.error("Caught exception", e);
            throw new SQLException(e);
        }
    }
    return metaData;
}
Also used : SQLException(java.sql.SQLException) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) 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