Skip to content

Commit 360f0e3

Browse files
authored
removes servicebuilder for most BigQuery samples, fixes test table deletion (#237)
1 parent 9b0983b commit 360f0e3

20 files changed

+40
-87
lines changed

bigquery/api/src/CopyTableCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\Component\Console\Input\InputArgument;
2323
use Symfony\Component\Console\Input\InputOption;
2424
use Symfony\Component\Console\Output\OutputInterface;
25-
use Google\Cloud\ServiceBuilder;
25+
use Google\Cloud\BigQuery\BigQueryClient;
2626
use InvalidArgumentException;
2727

2828
/**
@@ -80,10 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
}
8181
$datasetId = $input->getArgument('dataset');
8282
$sourceTableId = $input->getArgument('source-table');
83-
$builder = new ServiceBuilder([
83+
$bigQuery = new BigQueryClient([
8484
'projectId' => $projectId,
8585
]);
86-
$bigQuery = $builder->bigQuery();
8786
$dataset = $bigQuery->dataset($datasetId);
8887
$sourceTable = $dataset->table($sourceTableId);
8988
$destinationTableId = $input->getArgument('destination-table');

bigquery/api/src/ExportCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\Component\Console\Input\InputArgument;
2323
use Symfony\Component\Console\Input\InputOption;
2424
use Symfony\Component\Console\Output\OutputInterface;
25-
use Google\Cloud\ServiceBuilder;
25+
use Google\Cloud\BigQuery\BigQueryClient;
2626
use InvalidArgumentException;
2727

2828
/**
@@ -90,10 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9090
throw new InvalidArgumentException('Table must in the format "dataset.table"');
9191
}
9292
list($datasetId, $tableId) = explode('.', $fullTableName);
93-
$builder = new ServiceBuilder([
93+
$bigQuery = new BigQueryClient([
9494
'projectId' => $projectId,
9595
]);
96-
$bigQuery = $builder->bigQuery();
9796
$dataset = $bigQuery->dataset($datasetId);
9897
$table = $dataset->table($tableId);
9998
$destination = $input->getArgument('destination');

bigquery/api/src/ImportCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Symfony\Component\Console\Input\InputOption;
2424
use Symfony\Component\Console\Output\OutputInterface;
2525
use Symfony\Component\Console\Question\Question;
26-
use Google\Cloud\ServiceBuilder;
26+
use Google\Cloud\BigQuery\BigQueryClient;
2727
use InvalidArgumentException;
2828
use Exception;
2929

@@ -96,10 +96,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
throw new InvalidArgumentException('Table must in the format "dataset.table"');
9797
}
9898
list($datasetId, $tableId) = explode('.', $fullTableName);
99-
$builder = new ServiceBuilder([
99+
$bigQuery = new BigQueryClient([
100100
'projectId' => $projectId,
101101
]);
102-
$bigQuery = $builder->bigQuery();
103102
$dataset = $bigQuery->dataset($datasetId);
104103
$table = $dataset->table($tableId);
105104
$source = $input->getArgument('source');

bigquery/api/src/SchemaCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Symfony\Component\Console\Question\Question;
2626
use Symfony\Component\Console\Question\ConfirmationQuestion;
2727
use Symfony\Component\Console\Question\ChoiceQuestion;
28-
use Google\Cloud\ServiceBuilder;
28+
use Google\Cloud\BigQuery\BigQueryClient;
2929
use Google\Cloud\Exception\BadRequestException;
3030
use InvalidArgumentException;
3131
use LogicException;
@@ -106,10 +106,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
106106
throw new InvalidArgumentException('Table must in the format "dataset.table"');
107107
}
108108
list($datasetId, $tableId) = explode('.', $fullTableName);
109-
$builder = new ServiceBuilder([
109+
$bigQuery = new BigQueryClient([
110110
'projectId' => $projectId,
111111
]);
112-
$bigQuery = $builder->bigQuery();
113112
$dataset = $bigQuery->dataset($datasetId);
114113
$table = $dataset->table($tableId);
115114
if (!$dataset->exists()) {

bigquery/api/src/functions/bigquery_client.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
* ```
1313
*/
1414
# [START build_service]
15-
use Google\Cloud\ServiceBuilder;
15+
use Google\Cloud\BigQuery\BigQueryClient;
1616

17-
$builder = new ServiceBuilder([
17+
$bigQuery = new BigQueryClient([
1818
'projectId' => $projectId,
1919
]);
20-
$bigQuery = $builder->bigQuery();
2120
# [END build_service]
2221
return $bigQuery;

bigquery/api/src/functions/browse_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace Google\Cloud\Samples\BigQuery;
2525

2626
# [START browse_table]
27-
use Google\Cloud\ServiceBuilder;
27+
use Google\Cloud\BigQuery\BigQueryClient;
2828

2929
/**
3030
* Browse a bigquery table.
@@ -47,10 +47,9 @@ function browse_table($projectId, $datasetId, $tableId, $maxResults = 10, $start
4747
'maxResults' => $maxResults,
4848
'startIndex' => $startIndex
4949
];
50-
$builder = new ServiceBuilder([
50+
$bigQuery = new BigQueryClient([
5151
'projectId' => $projectId,
5252
]);
53-
$bigQuery = $builder->bigQuery();
5453
$dataset = $bigQuery->dataset($datasetId);
5554
$table = $dataset->table($tableId);
5655
$numRows = 0;

bigquery/api/src/functions/copy_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use Exception;
2727
# [START copy_table]
28-
use Google\Cloud\ServiceBuilder;
28+
use Google\Cloud\BigQuery\BigQueryClient;
2929
use Google\Cloud\ExponentialBackoff;
3030

3131
/**
@@ -36,10 +36,9 @@
3636
*/
3737
function copy_table($projectId, $datasetId, $sourceTableId, $destinationTableId)
3838
{
39-
$builder = new ServiceBuilder([
39+
$bigQuery = new BigQueryClient([
4040
'projectId' => $projectId,
4141
]);
42-
$bigQuery = $builder->bigQuery();
4342
$dataset = $bigQuery->dataset($datasetId);
4443
$sourceTable = $dataset->table($sourceTableId);
4544
$destinationTable = $dataset->table($destinationTableId);

bigquery/api/src/functions/create_dataset.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
namespace Google\Cloud\Samples\BigQuery;
2525

2626
# [START create_dataset]
27-
use Google\Cloud\ServiceBuilder;
27+
use Google\Cloud\BigQuery\BigQueryClient;
2828

2929
/**
3030
* @param string $projectId The Google project ID.
3131
* @param string $dataset The BigQuery dataset ID.
3232
*/
3333
function create_dataset($projectId, $datasetId)
3434
{
35-
$builder = new ServiceBuilder([
35+
$bigQuery = new BigQueryClient([
3636
'projectId' => $projectId,
3737
]);
38-
$bigQuery = $builder->bigQuery();
3938
$dataset = $bigQuery->createDataset($datasetId);
4039
return $dataset;
4140
}

bigquery/api/src/functions/create_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace Google\Cloud\Samples\BigQuery;
2525

2626
# [START create_table]
27-
use Google\Cloud\ServiceBuilder;
27+
use Google\Cloud\BigQuery\BigQueryClient;
2828

2929
/**
3030
* Example:
@@ -50,10 +50,9 @@
5050
*/
5151
function create_table($projectId, $datasetId, $tableId, $schema)
5252
{
53-
$builder = new ServiceBuilder([
53+
$bigQuery = new BigQueryClient([
5454
'projectId' => $projectId,
5555
]);
56-
$bigQuery = $builder->bigQuery();
5756
$dataset = $bigQuery->dataset($datasetId);
5857
$options = ['schema' => $schema];
5958
$table = $dataset->createTable($tableId, $options);

bigquery/api/src/functions/delete_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace Google\Cloud\Samples\BigQuery;
2525

2626
# [START delete_table]
27-
use Google\Cloud\ServiceBuilder;
27+
use Google\Cloud\BigQuery\BigQueryClient;
2828

2929
/**
3030
* @param string $projectId The Google project ID.
@@ -33,11 +33,10 @@
3333
*/
3434
function delete_table($projectId, $datasetId, $tableId)
3535
{
36-
$builder = new ServiceBuilder([
36+
$bigQuery = new BigQueryClient([
3737
'projectId' => $projectId,
3838
]);
3939
# [START get_table]
40-
$bigQuery = $builder->bigQuery();
4140
$dataset = $bigQuery->dataset($datasetId);
4241
$table = $dataset->table($tableId);
4342
# [END get_table]

0 commit comments

Comments
 (0)