@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); }
@Override public QueryHandle getTables(@Nullable String catalog, @Nullable String schemaPattern, String tableNamePattern, @Nullable List<String> tableTypes) throws ExploreException, SQLException { String body = GSON.toJson(new TablesArgs(catalog, schemaPattern, tableNamePattern, tableTypes)); String resource = String.format("namespaces/%s/data/explore/jdbc/tables", 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 tables. Reason: " + response); }
@Override public QueryHandle getTables(@Nullable String catalog, @Nullable String schemaPattern, String tableNamePattern, @Nullable List<String> tableTypes) throws ExploreException, SQLException { String body = GSON.toJson(new TablesArgs(catalog, schemaPattern, tableNamePattern, tableTypes)); String resource = String.format("namespaces/%s/data/explore/jdbc/tables", 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 tables. Reason: " + response); }
@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); }
@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); }
@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); }
@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); }
@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); }
@Override public QueryHandle createNamespace(NamespaceMeta namespace) throws ExploreException, SQLException { HttpResponse response = doPut(String.format("data/explore/namespaces/%s", namespace.getName()), GSON.toJson(namespace), null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot add a namespace. Reason: " + response); }
@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); }
@Override public QueryHandle createNamespace(NamespaceMeta namespace) throws ExploreException, SQLException { HttpResponse response = doPut(String.format("data/explore/namespaces/%s", namespace.getName()), GSON.toJson(namespace), null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot add a namespace. Reason: " + response); }
protected QueryHandle doEnableExploreStream(StreamId stream, String tableName, FormatSpecification format) throws ExploreException { HttpResponse response = doPost(String.format( "namespaces/%s/data/explore/streams/%s/tables/%s/enable", stream.getNamespace(), stream.getEntityName(), tableName), format == null ? null : GSON.toJson(format), null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException(String.format("Cannot enable explore on stream %s with table %s. Reason: %s", stream.getEntityName(), tableName, response)); }
@Override public QueryHandle deleteNamespace(NamespaceId namespace) throws ExploreException, SQLException { HttpResponse response = doDelete(String.format("data/explore/namespaces/%s", namespace.getEntityName())); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot remove a namespace. Reason: " + response); }
@Override public QueryHandle deleteNamespace(NamespaceId namespace) throws ExploreException, SQLException { HttpResponse response = doDelete(String.format("data/explore/namespaces/%s", namespace.getEntityName())); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot remove a namespace. Reason: " + response); }
protected QueryHandle doDisableExploreDataset(DatasetId datasetInstance, DatasetSpecification spec) throws ExploreException { String body = spec == null ? null : GSON.toJson(new DisableExploreParameters(spec)); String endpoint = spec == null ? "disable" : "disable-internal"; HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetInstance.getNamespace(), datasetInstance.getEntityName(), endpoint), body, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException(String.format("Cannot disable explore on dataset %s. Reason: %s", datasetInstance.toString(), response)); }
@Override public QueryHandle getTypeInfo() throws ExploreException, SQLException { HttpResponse response = doPost("data/explore/jdbc/types", null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot get the tables. Reason: " + response); }
@Override public QueryHandle getTableTypes() throws ExploreException, SQLException { HttpResponse response = doPost("data/explore/jdbc/tableTypes", null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot get the tables. Reason: " + response); }
@Override public QueryHandle getTypeInfo() throws ExploreException, SQLException { HttpResponse response = doPost("data/explore/jdbc/types", null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot get the tables. Reason: " + response); }
@Override public QueryHandle getTableTypes() throws ExploreException, SQLException { HttpResponse response = doPost("data/explore/jdbc/tableTypes", null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot get the tables. Reason: " + response); }
@Override public QueryHandle getCatalogs() throws ExploreException, SQLException { HttpResponse response = doPost("data/explore/jdbc/catalogs", null, null); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return QueryHandle.fromId(parseResponseAsMap(response, "handle")); } throw new ExploreException("Cannot get the catalogs. Reason: " + response); }