From 8c92c9919b278bdb128be963391fc1870e69e343 Mon Sep 17 00:00:00 2001 From: shollyman Date: Thu, 17 Sep 2020 05:45:11 -0700 Subject: [PATCH] feat(bigquery): explicitly ask for dense responses from HTTP backend (#739) This change alters HTTP response behavior by eliding unnecessary whitespace from JSON responses. --- .../bigquery/spi/v2/HttpBigQueryRpc.java | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java index 9aaef6db5..7d920e6fe 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java +++ b/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 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> listDatasets(String projectId, Map 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 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 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 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 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 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 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> 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 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> 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 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> 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> listJobs(String projectId, Map op bigquery .jobs() .list(projectId) + .setPrettyPrint(false) .setAllUsers(Option.ALL_USERS.getBoolean(options)) .setFields(Option.FIELDS.getString(options)) .setStateFilter(Option.STATE_FILTER.>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 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 options) { public Policy setIamPolicy(String resourceId, Policy policy, Map 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); }