Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bigquery/api/snippets/browse_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 4 || count($argv) > 5) {
return print("Usage: php snippets/browse_table.php PROJECT_ID DATASET_ID TABLE_ID [NUM_RESULTS]\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [NUM_RESULTS]\n", __FILE__);
}
list($_, $projectId, $datasetId, $tableId) = $argv;
$maxResults = isset($argv[4]) ? $argv[4] : 10;
Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/copy_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 5) {
return print("Usage: php snippets/copy_table.php PROJECT_ID DATASET_ID SOURCE_TABLE_ID DESTINATION_TABLE_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID SOURCE_TABLE_ID DESTINATION_TABLE_ID\n", __FILE__);
}
list($_, $projectId, $datasetId, $sourceTableId, $destinationTableId) = $argv;

Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/create_dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
return print("Usage: php snippets/create_dataset.php PROJECT_ID DATASET_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}
list($_, $projectId, $datasetId) = $argv;

Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/create_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 4 || count($argv) > 5) {
return print("Usage: php snippets/create_table.php PROJECT_ID DATASET_ID TABLE_ID [FIELDS]\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [FIELDS]\n", __FILE__);
}
list($_, $projectId, $datasetId, $tableId) = $argv;
$fields = isset($argv[4]) ? json_decode($argv[4]) : [['name' => 'field1', 'type' => 'string']];
Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/delete_dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) > 3) {
return print("Usage: php snippets/delete_dataset.php PROJECT_ID DATASET_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}
list($_, $projectId, $datasetId) = $argv;

Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/delete_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
return print("Usage: php snippets/delete_table.php PROJECT_ID DATASET_ID TABLE_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
}
list($_, $projectId, $datasetId, $tableId) = $argv;

Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/extract_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 6 || count($argv) > 7) {
return print("Usage: php snippets/extract_table.php PROJECT_ID DATASET_ID TABLE_ID BUCKET_NAME OBJECT_NAME [FORMAT]\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID BUCKET_NAME OBJECT_NAME [FORMAT]\n", __FILE__);
}

list($_, $projectId, $datasetId, $tableId, $bucketName, $objectName) = $argv;
Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/import_from_local_csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 5) {
return print("Usage: php snippets/import_from_local_csv.php PROJECT_ID DATASET_ID TABLE_ID SOURCE\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID SOURCE\n", __FILE__);
}

list($_, $projectId, $datasetId, $tableId, $source) = $argv;
Expand Down
2 changes: 1 addition & 1 deletion bigquery/api/snippets/import_from_storage_csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 3) {
return print("Usage: php snippets/import_from_storage.php PROJECT_ID DATASET_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}

list($_, $projectId, $datasetId) = $argv;
Expand Down
66 changes: 66 additions & 0 deletions bigquery/api/snippets/import_from_storage_csv_autodetect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright 2018 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 3) {
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}

list($_, $projectId, $datasetId) = $argv;
# [START bigquery_load_table_gcs_csv_autodetect]
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\Core\ExponentialBackoff;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $datasetId = 'The BigQuery dataset ID';

// instantiate the bigquery table service
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$dataset = $bigQuery->dataset($datasetId);
$table = $dataset->table('us_states');

// create the import job
$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
$loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->skipLeadingRows(1);
$job = $table->runJob($loadConfig);
// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
// check if the job has errors
if (isset($job->info()['status']['errorResult'])) {
$error = $job->info()['status']['errorResult']['message'];
printf('Error running job: %s' . PHP_EOL, $error);
} else {
print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_csv_autodetect]
68 changes: 68 additions & 0 deletions bigquery/api/snippets/import_from_storage_csv_truncate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright 2018 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 4) {
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
}

list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_csv_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\Core\ExponentialBackoff;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $datasetId = 'The BigQuery dataset ID';
// $tableId = 'The BigQuery table ID';

// instantiate the bigquery table service
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$table = $bigQuery->dataset($datasetId)->table($tableId);

// create the import job
$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.csv';
$loadConfig = $table->loadFromStorage($gcsUri)->skipLeadingRows(1)->writeDisposition('WRITE_TRUNCATE');
$job = $table->runJob($loadConfig);

// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});

// check if the job has errors
if (isset($job->info()['status']['errorResult'])) {
$error = $job->info()['status']['errorResult']['message'];
printf('Error running job: %s' . PHP_EOL, $error);
} else {
print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_csv_truncate]
2 changes: 1 addition & 1 deletion bigquery/api/snippets/import_from_storage_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 3) {
return print("Usage: php snippets/import_from_storage.php PROJECT_ID DATASET_ID\n");
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}

list($_, $projectId, $datasetId) = $argv;
Expand Down
66 changes: 66 additions & 0 deletions bigquery/api/snippets/import_from_storage_json_autodetect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright 2018 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 3) {
return printf("Usage: php %s PROJECT_ID DATASET_ID\n", __FILE__);
}

list($_, $projectId, $datasetId) = $argv;
# [START bigquery_load_table_gcs_json_autodetect]
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\Core\ExponentialBackoff;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $datasetId = 'The BigQuery dataset ID';

// instantiate the bigquery table service
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$dataset = $bigQuery->dataset($datasetId);
$table = $dataset->table('us_states');

// create the import job
$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
$loadConfig = $table->loadFromStorage($gcsUri)->autodetect(true)->sourceFormat('NEWLINE_DELIMITED_JSON');
$job = $table->runJob($loadConfig);
// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
// check if the job has errors
if (isset($job->info()['status']['errorResult'])) {
$error = $job->info()['status']['errorResult']['message'];
printf('Error running job: %s' . PHP_EOL, $error);
} else {
print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_json_autodetect]
68 changes: 68 additions & 0 deletions bigquery/api/snippets/import_from_storage_json_truncate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright 2018 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigquery/api/README.md
*/

// Include Google Cloud dependendencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';
if (count($argv) != 4) {
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID\n", __FILE__);
}

list($_, $projectId, $datasetId, $tableId) = $argv;
# [START bigquery_load_table_gcs_json_truncate]
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\Core\ExponentialBackoff;

/** Uncomment and populate these variables in your code */
// $projectId = 'The Google project ID';
// $datasetId = 'The BigQuery dataset ID';
// $tableID = 'The BigQuery table ID';

// instantiate the bigquery table service
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$table = $bigQuery->dataset($datasetId)->table($tableId);

// create the import job
$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('NEWLINE_DELIMITED_JSON')->writeDisposition('WRITE_TRUNCATE');
$job = $table->runJob($loadConfig);

// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});

// check if the job has errors
if (isset($job->info()['status']['errorResult'])) {
$error = $job->info()['status']['errorResult']['message'];
printf('Error running job: %s' . PHP_EOL, $error);
} else {
print('Data imported successfully' . PHP_EOL);
}
# [END bigquery_load_table_gcs_json_truncate]
Loading