Skip to content
Permalink
Browse files
feat(bigquery): explicitly ask for dense responses from HTTP backend (#…
…739)

This change alters HTTP response behavior by eliding unnecessary
whitespace from JSON responses.
  • Loading branch information
shollyman committed Sep 17, 2020
1 parent 2a0d86d commit 8c92c9919b278bdb128be963391fc1870e69e343
Showing with 47 additions and 5 deletions.
  1. +47 −5 google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java
@@ -120,6 +120,7 @@ public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> opt
.datasets()
.get(projectId, datasetId)
.setFields(Option.FIELDS.getString(options))
.setPrettyPrint(false)
.execute();
} catch (IOException ex) {
BigQueryException serviceException = translate(ex);
@@ -137,6 +138,7 @@ public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Optio
bigquery
.datasets()
.list(projectId)
.setPrettyPrint(false)
.setAll(Option.ALL_DATASETS.getBoolean(options))
.setFilter(Option.LABEL_FILTER.getString(options))
.setMaxResults(Option.MAX_RESULTS.getLong(options))
@@ -160,6 +162,7 @@ public Dataset create(Dataset dataset, Map<Option, ?> options) {
return bigquery
.datasets()
.insert(dataset.getDatasetReference().getProjectId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -176,6 +179,7 @@ public Table create(Table table, Map<Option, ?> options) {
return bigquery
.tables()
.insert(reference.getProjectId(), reference.getDatasetId(), table)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -190,6 +194,7 @@ public Routine create(Routine routine, Map<Option, ?> options) {
return bigquery
.routines()
.insert(reference.getProjectId(), reference.getDatasetId(), routine)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -207,6 +212,7 @@ public Job create(Job job, Map<Option, ?> options) {
return bigquery
.jobs()
.insert(projectId, job)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -220,6 +226,7 @@ public boolean deleteDataset(String projectId, String datasetId, Map<Option, ?>
bigquery
.datasets()
.delete(projectId, datasetId)
.setPrettyPrint(false)
.setDeleteContents(Option.DELETE_CONTENTS.getBoolean(options))
.execute();
return true;
@@ -239,6 +246,7 @@ public Dataset patch(Dataset dataset, Map<Option, ?> options) {
return bigquery
.datasets()
.patch(reference.getProjectId(), reference.getDatasetId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -255,6 +263,7 @@ public Table patch(Table table, Map<Option, ?> options) {
return bigquery
.tables()
.patch(reference.getProjectId(), reference.getDatasetId(), reference.getTableId(), table)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -269,6 +278,7 @@ public Table getTable(
return bigquery
.tables()
.get(projectId, datasetId, tableId)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -288,6 +298,7 @@ public Tuple<String, Iterable<Table>> listTables(
bigquery
.tables()
.list(projectId, datasetId)
.setPrettyPrint(false)
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
@@ -337,6 +348,7 @@ public Model patch(Model model, Map<Option, ?> options) {
return bigquery
.models()
.patch(reference.getProjectId(), reference.getDatasetId(), reference.getModelId(), model)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -351,6 +363,7 @@ public Model getModel(
return bigquery
.models()
.get(projectId, datasetId, modelId)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -370,6 +383,7 @@ public Tuple<String, Iterable<Model>> listModels(
bigquery
.models()
.list(projectId, datasetId)
.setPrettyPrint(false)
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
@@ -402,6 +416,7 @@ public Routine update(Routine routine, Map<Option, ?> options) {
.routines()
.update(
reference.getProjectId(), reference.getDatasetId(), reference.getRoutineId(), routine)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -416,6 +431,7 @@ public Routine getRoutine(
return bigquery
.routines()
.get(projectId, datasetId, routineId)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
} catch (IOException ex) {
@@ -435,6 +451,7 @@ public Tuple<String, Iterable<Routine>> listRoutines(
bigquery
.routines()
.list(projectId, datasetId)
.setPrettyPrint(false)
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
@@ -463,7 +480,11 @@ public boolean deleteRoutine(String projectId, String datasetId, String routineI
public TableDataInsertAllResponse insertAll(
String projectId, String datasetId, String tableId, TableDataInsertAllRequest request) {
try {
return bigquery.tabledata().insertAll(projectId, datasetId, tableId, request).execute();
return bigquery
.tabledata()
.insertAll(projectId, datasetId, tableId, request)
.setPrettyPrint(false)
.execute();
} catch (IOException ex) {
throw translate(ex);
}
@@ -476,6 +497,7 @@ public TableDataList listTableData(
return bigquery
.tabledata()
.list(projectId, datasetId, tableId)
.setPrettyPrint(false)
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.setStartIndex(
@@ -494,6 +516,7 @@ public Job getJob(String projectId, String jobId, String location, Map<Option, ?
return bigquery
.jobs()
.get(projectId, jobId)
.setPrettyPrint(false)
.setLocation(location)
.setFields(Option.FIELDS.getString(options))
.execute();
@@ -513,6 +536,7 @@ public Tuple<String, Iterable<Job>> listJobs(String projectId, Map<Option, ?> op
bigquery
.jobs()
.list(projectId)
.setPrettyPrint(false)
.setAllUsers(Option.ALL_USERS.getBoolean(options))
.setFields(Option.FIELDS.getString(options))
.setStateFilter(Option.STATE_FILTER.<List<String>>get(options))
@@ -562,7 +586,12 @@ public Job apply(JobList.Jobs jobPb) {
@Override
public boolean cancel(String projectId, String jobId, String location) {
try {
bigquery.jobs().cancel(projectId, jobId).setLocation(location).execute();
bigquery
.jobs()
.cancel(projectId, jobId)
.setLocation(location)
.setPrettyPrint(false)
.execute();
return true;
} catch (IOException ex) {
BigQueryException serviceException = translate(ex);
@@ -580,6 +609,7 @@ public GetQueryResultsResponse getQueryResults(
return bigquery
.jobs()
.getQueryResults(projectId, jobId)
.setPrettyPrint(false)
.setLocation(location)
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
@@ -676,7 +706,11 @@ public Policy getIamPolicy(String resourceId, Map<Option, ?> options) {
.setRequestedPolicyVersion(
Option.REQUESTED_POLICY_VERSION.getLong(options).intValue()));
}
return bigquery.tables().getIamPolicy(resourceId, policyRequest).execute();
return bigquery
.tables()
.getIamPolicy(resourceId, policyRequest)
.setPrettyPrint(false)
.execute();
} catch (IOException ex) {
throw translate(ex);
}
@@ -686,7 +720,11 @@ public Policy getIamPolicy(String resourceId, Map<Option, ?> options) {
public Policy setIamPolicy(String resourceId, Policy policy, Map<Option, ?> options) {
try {
SetIamPolicyRequest policyRequest = new SetIamPolicyRequest().setPolicy(policy);
return bigquery.tables().setIamPolicy(resourceId, policyRequest).execute();
return bigquery
.tables()
.setIamPolicy(resourceId, policyRequest)
.setPrettyPrint(false)
.execute();
} catch (IOException ex) {
throw translate(ex);
}
@@ -698,7 +736,11 @@ public TestIamPermissionsResponse testIamPermissions(
try {
TestIamPermissionsRequest permissionsRequest =
new TestIamPermissionsRequest().setPermissions(permissions);
return bigquery.tables().testIamPermissions(resourceId, permissionsRequest).execute();
return bigquery
.tables()
.testIamPermissions(resourceId, permissionsRequest)
.setPrettyPrint(false)
.execute();
} catch (IOException ex) {
throw translate(ex);
}

0 comments on commit 8c92c99

Please sign in to comment.