use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class BaseHiveExploreService method deleteNamespace.
@Override
public QueryHandle deleteNamespace(NamespaceId namespace) throws ExploreException, SQLException {
startAndWait();
String customHiveDatabase;
try {
customHiveDatabase = namespaceQueryAdmin.get(namespace).getConfig().getHiveDatabase();
} catch (Exception e) {
throw new ExploreException(String.format("Failed to get namespace meta for the namespace %s", namespace));
}
if (Strings.isNullOrEmpty(customHiveDatabase)) {
// no custom hive database was given for this namespace so we need to delete it
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession();
String database = getHiveDatabase(namespace.getNamespace());
try {
sessionHandle = openHiveSession(sessionConf);
String statement = String.format("DROP DATABASE IF EXISTS %s", database);
operationHandle = executeAsync(sessionHandle, statement);
QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, statement, database);
LOG.info("Deleting database {} with handle {}", database, handle);
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
throw e;
}
} catch (HiveSQLException e) {
throw getSqlException(e);
} catch (Throwable e) {
throw new ExploreException(e);
}
} else {
// a custom hive database was provided for this namespace do we don't need to delete it.
LOG.debug("Custom hive database {}. Skipping delete.", customHiveDatabase, namespace);
return QueryHandle.NO_OP;
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class BaseHiveExploreService method getColumns.
@Override
public QueryHandle getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws ExploreException, SQLException {
startAndWait();
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession();
String database = getHiveDatabase(schemaPattern);
try {
sessionHandle = openHiveSession(sessionConf);
operationHandle = cliService.getColumns(sessionHandle, catalog, database, tableNamePattern, columnNamePattern);
QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", database);
LOG.trace("Retrieving columns: catalog {}, schemaPattern {}, tableNamePattern {}, columnNamePattern {}", catalog, database, tableNamePattern, columnNamePattern);
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
throw e;
}
} catch (HiveSQLException e) {
throw getSqlException(e);
} catch (Throwable e) {
throw new ExploreException(e);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class BaseHiveExploreService method getFunctions.
@Override
public QueryHandle getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws ExploreException, SQLException {
startAndWait();
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession();
String database = getHiveDatabase(schemaPattern);
try {
sessionHandle = openHiveSession(sessionConf);
operationHandle = cliService.getFunctions(sessionHandle, catalog, database, functionNamePattern);
QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", database);
LOG.trace("Retrieving functions: catalog {}, schema {}, function {}", catalog, database, functionNamePattern);
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
throw e;
}
} catch (HiveSQLException e) {
throw getSqlException(e);
} catch (Throwable e) {
throw new ExploreException(e);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class ExploreExecutorHttpHandler method disableDataset.
private void disableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification spec) {
try {
QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {
@Override
public QueryHandle call() throws Exception {
return exploreTableManager.disableDataset(datasetId, spec);
}
});
JsonObject json = new JsonObject();
json.addProperty("handle", handle.getHandle());
responder.sendJson(HttpResponseStatus.OK, json.toString());
} catch (Throwable e) {
LOG.error("Got exception while trying to disable explore on dataset {}", datasetId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class ExploreQueryExecutorHttpHandler method getQueryNextResults.
@POST
@Path("data/explore/queries/{id}/next")
public void getQueryNextResults(FullHttpRequest request, HttpResponder responder, @PathParam("id") String id) throws IOException, ExploreException {
// NOTE: this call is a POST because it is not idempotent: cursor of results is moved
try {
final QueryHandle handle = QueryHandle.fromId(id);
List<QueryResult> results;
if (handle.equals(QueryHandle.NO_OP)) {
results = Lists.newArrayList();
} else {
Map<String, String> args = decodeArguments(request);
final int size = args.containsKey("size") ? Integer.valueOf(args.get("size")) : 100;
results = doAs(handle, new Callable<List<QueryResult>>() {
@Override
public List<QueryResult> call() throws Exception {
return exploreService.nextResults(handle, size);
}
});
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(results));
} catch (IllegalArgumentException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (SQLException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
} catch (HandleNotFoundException e) {
responder.sendStatus(HttpResponseStatus.NOT_FOUND);
}
}
Aggregations