use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.
the class ExploreExecutorHttpHandler method updateDataset.
/**
* Enable ad-hoc exploration of a dataset instance.
*/
@POST
@Path("datasets/{dataset}/update")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateDataset(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) throws BadRequestException {
final DatasetId datasetId = new DatasetId(namespace, datasetName);
try {
UpdateExploreParameters params = readUpdateParameters(request);
final DatasetSpecification oldSpec = params.getOldSpec();
final DatasetSpecification datasetSpec = params.getNewSpec();
QueryHandle handle;
if (oldSpec.equals(datasetSpec)) {
handle = QueryHandle.NO_OP;
} else {
handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {
@Override
public QueryHandle call() throws Exception {
return exploreTableManager.updateDataset(datasetId, datasetSpec, oldSpec);
}
});
}
JsonObject json = new JsonObject();
json.addProperty("handle", handle.getHandle());
responder.sendJson(HttpResponseStatus.OK, json.toString());
} catch (IllegalArgumentException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (ExploreException e) {
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error updating explore on dataset " + datasetId);
} catch (SQLException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to update explore on dataset " + datasetId);
} catch (UnsupportedTypeException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "Schema for dataset " + datasetId + " is not supported for exploration: " + e.getMessage());
} catch (Throwable e) {
LOG.error("Got exception:", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.
the class ExploreExecutorHttpHandler method dropPartition.
// this should really be a DELETE request. However, the partition key must be passed in the body
// of the request, and that does not work with many HTTP clients, including Java's URLConnection.
@POST
@Path("datasets/{dataset}/deletePartition")
public void dropPartition(final FullHttpRequest request, final HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName, @HeaderParam(Constants.Security.Headers.PROGRAM_ID) String programId) throws Exception {
final DatasetId datasetId = new DatasetId(namespace, datasetName);
propagateUserId(request);
impersonator.doAs(getEntityToImpersonate(datasetId, programId), new Callable<Void>() {
@Override
public Void call() throws Exception {
doPartitionOperation(request, responder, datasetId, new PartitionOperation() {
@Override
public QueryHandle submitOperation(PartitionKey partitionKey, Map<String, String> properties) throws ExploreException, SQLException {
return exploreTableManager.dropPartition(datasetId, properties, partitionKey);
}
});
return null;
}
});
}
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));
}
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);
}
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));
}
Aggregations