@Override public Dataset create(Dataset dataset, Map<Option, ?> options) { try { return bigquery .datasets() .insert(dataset.getDatasetReference().getProjectId(), dataset) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table patch(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .patch(reference.getProjectId(), reference.getDatasetId(), reference.getTableId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table create(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .insert(reference.getProjectId(), reference.getDatasetId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Job create(Job job, Map<Option, ?> options) { try { String projectId = job.getJobReference() != null ? job.getJobReference().getProjectId() : this.options.getProjectId(); return bigquery .jobs() .insert(projectId, job) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
JobList jobsList = bigquery .jobs() .list(projectId) .setAllUsers(Option.ALL_USERS.getBoolean(options)) .setFields(Option.FIELDS.getString(options)) .setStateFilter(Option.STATE_FILTER.<List<String>>get(options)) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setProjection(DEFAULT_PROJECTION) .execute(); Iterable<JobList.Jobs> jobs = jobsList.getJobs(); return Tuple.of( jobsList.getNextPageToken(), Iterables.transform( jobs != null ? jobs : ImmutableList.<JobList.Jobs>of(),
TableList tableList = bigquery .tables() .list(projectId, datasetId) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .execute(); Iterable<TableList.Tables> tables = tableList.getTables(); return Tuple.of( tableList.getNextPageToken(), Iterables.transform( tables != null ? tables : ImmutableList.<TableList.Tables>of(),
@Override public Dataset patch(Dataset dataset, Map<Option, ?> options) { try { DatasetReference reference = dataset.getDatasetReference(); return bigquery .datasets() .patch(reference.getProjectId(), reference.getDatasetId(), dataset) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Job getJob(String projectId, String jobId, String location, Map<Option, ?> options) { try { return bigquery .jobs() .get(projectId, jobId) .setLocation(location) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public GetQueryResultsResponse getQueryResults( String projectId, String jobId, String location, Map<Option, ?> options) { try { return bigquery .jobs() .getQueryResults(projectId, jobId) .setLocation(location) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setStartIndex( Option.START_INDEX.getLong(options) != null ? BigInteger.valueOf(Option.START_INDEX.getLong(options)) : null) .setTimeoutMs(Option.TIMEOUT.getLong(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Option, ?> options) { try { DatasetList datasetsList = bigquery .datasets() .list(projectId) .setAll(Option.ALL_DATASETS.getBoolean(options)) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .execute(); Iterable<DatasetList.Datasets> datasets = datasetsList.getDatasets(); return Tuple.of( datasetsList.getNextPageToken(), Iterables.transform( datasets != null ? datasets : ImmutableList.<DatasetList.Datasets>of(), LIST_TO_DATASET)); } catch (IOException ex) { throw translate(ex); } }
public HttpBigQueryRpc(BigQueryOptions options) { HttpTransportOptions transportOptions = (HttpTransportOptions) options.getTransportOptions(); HttpTransport transport = transportOptions.getHttpTransportFactory().create(); HttpRequestInitializer initializer = transportOptions.getHttpRequestInitializer(options); this.options = options; bigquery = new Bigquery.Builder(transport, new JacksonFactory(), initializer) .setRootUrl(options.getHost()) .setApplicationName(options.getApplicationName()) .build(); }
@Override public Table getTable( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tables() .get(projectId, datasetId, tableId) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public TableDataList listTableData( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tabledata() .list(projectId, datasetId, tableId) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setStartIndex( Option.START_INDEX.getLong(options) != null ? BigInteger.valueOf(Option.START_INDEX.getLong(options)) : null) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public boolean deleteTable(String projectId, String datasetId, String tableId) { try { bigquery.tables().delete(projectId, datasetId, tableId).execute(); return true; } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return false; } throw serviceException; } }
@Override public boolean deleteDataset(String projectId, String datasetId, Map<Option, ?> options) { try { bigquery .datasets() .delete(projectId, datasetId) .setDeleteContents(Option.DELETE_CONTENTS.getBoolean(options)) .execute(); return true; } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return false; } throw serviceException; } }
@Override public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> options) { try { return bigquery .datasets() .get(projectId, datasetId) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public boolean cancel(String projectId, String jobId, String location) { try { bigquery.jobs().cancel(projectId, jobId).setLocation(location).execute(); return true; } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return false; } throw serviceException; } }
@Override public String open(Job loadJob) { try { String builder = BASE_RESUMABLE_URI + options.getProjectId() + "/jobs"; GenericUrl url = new GenericUrl(builder); url.set("uploadType", "resumable"); JsonFactory jsonFactory = bigquery.getJsonFactory(); HttpRequestFactory requestFactory = bigquery.getRequestFactory(); HttpRequest httpRequest = requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, loadJob)); httpRequest.getHeaders().set("X-Upload-Content-Value", "application/octet-stream"); HttpResponse response = httpRequest.execute(); return response.getHeaders().getLocation(); } catch (IOException ex) { throw translate(ex); } }
HttpRequest httpRequest = bigquery .getRequestFactory() .buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length)); httpRequest.setParser(bigquery.getObjectParser()); long limit = destOffset + length; StringBuilder range = new StringBuilder("bytes ");