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