Search in sources :

Example 1 with ExploreException

use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.

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(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 2 with ExploreException

use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.

the class ExploreHttpClient method getSchemas.

@Override
public QueryHandle getSchemas(@Nullable String catalog, @Nullable String schemaPattern) throws ExploreException, SQLException {
    String body = GSON.toJson(new SchemasArgs(catalog, schemaPattern));
    String resource = String.format("namespaces/%s/data/explore/jdbc/schemas", 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 schemas. Reason: " + response);
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) SchemasArgs(co.cask.cdap.explore.utils.SchemasArgs) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 3 with ExploreException

use of co.cask.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(co.cask.cdap.explore.utils.ColumnsArgs) HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 4 with ExploreException

use of co.cask.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(co.cask.cdap.explore.service.TableNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 5 with ExploreException

use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.

the class BaseHiveExploreService method getTypeInfo.

@Override
public QueryHandle getTypeInfo() throws ExploreException, SQLException {
    startAndWait();
    try {
        SessionHandle sessionHandle = null;
        OperationHandle operationHandle = null;
        Map<String, String> sessionConf = startSession();
        try {
            sessionHandle = openHiveSession(sessionConf);
            operationHandle = cliService.getTypeInfo(sessionHandle);
            QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", "");
            LOG.trace("Retrieving type info");
            return handle;
        } catch (Throwable e) {
            closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", ""));
            throw e;
        }
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    } catch (Throwable e) {
        throw new ExploreException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(co.cask.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

ExploreException (co.cask.cdap.explore.service.ExploreException)46 QueryHandle (co.cask.cdap.proto.QueryHandle)17 SQLException (java.sql.SQLException)15 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)14 HttpResponse (co.cask.common.http.HttpResponse)13 IOException (java.io.IOException)12 OperationHandle (org.apache.hive.service.cli.OperationHandle)12 SessionHandle (org.apache.hive.service.cli.SessionHandle)12 Path (javax.ws.rs.Path)8 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)6 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)6 POST (javax.ws.rs.POST)6 DatasetId (co.cask.cdap.proto.id.DatasetId)5 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)4 BadRequestException (co.cask.cdap.common.BadRequestException)4 TableNotFoundException (co.cask.cdap.explore.service.TableNotFoundException)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)3 QueryStatus (co.cask.cdap.proto.QueryStatus)3 JsonObject (com.google.gson.JsonObject)3