Skip to content

Commit

Permalink
feat(bigquery): explicitly ask for dense responses from HTTP backend (#…
Browse files Browse the repository at this point in the history
…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 8c92c99
Showing 1 changed file with 47 additions and 5 deletions.
Expand Up @@ -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);
Expand All @@ -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))
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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(
Expand All @@ -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();
Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand All @@ -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))
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 8c92c99

Please sign in to comment.