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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations