2121use Google \Cloud \BigQuery \Connection \ConnectionInterface ;
2222use Google \Cloud \BigQuery \Connection \Rest ;
2323use Google \Cloud \BigQuery \Exception \JobException ;
24- use Google \Cloud \BigQuery \Job ;
2524use Google \Cloud \Core \ArrayTrait ;
2625use Google \Cloud \Core \ClientTrait ;
2726use Google \Cloud \Core \Int64 ;
@@ -152,8 +151,8 @@ public function __construct(array $config = [])
152151 * configuration can be built using fluent setters or by providing a full
153152 * set of options at once.
154153 *
155- * Unless otherwise specified, all configuration options will default based
156- * on the [Jobs configuration API documentation ](https://goo.gl/vSTbGp )
154+ * Unless otherwise specified, all configuration options will default based on the
155+ * [query job configuration ](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationquery )
157156 * except for `configuration.query.useLegacySql`, which defaults to `false`
158157 * in this client.
159158 *
@@ -194,9 +193,16 @@ public function __construct(array $config = [])
194193 * ```
195194 *
196195 * @param string $query A BigQuery SQL query.
197- * @param array $options [optional] Please see the
198- * [API documentation for Job configuration](https://goo.gl/vSTbGp)
199- * for the available options.
196+ * @param array $options [optional] {
197+ * Configuration options.
198+ *
199+ * @type array $configuration Job configuration. Please see the
200+ * [API documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfiguration)
201+ * for the available options.
202+ * @type array $configuration.query Query job configuration. Please see the
203+ * [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationquery)
204+ * for the available options.
205+ * }
200206 * @return QueryJobConfiguration
201207 */
202208 public function query ($ query , array $ options = [])
@@ -216,18 +222,25 @@ public function query($query, array $options = [])
216222 * configuration can be built using fluent setters or by providing a full
217223 * set of options at once.
218224 *
219- * Unless otherwise specified, all configuration options will default based
220- * on the [Jobs configuration API documentation ](https://goo.gl/vSTbGp )
225+ * Unless otherwise specified, all configuration options will default based on the
226+ * [query job configuration ](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationquery )
221227 * except for `configuration.query.useLegacySql`, which defaults to `false`
222228 * in this client.
223229 *
224230 * As this method is an alias, please see
225231 * {@see Google\Cloud\BigQuery\BigQueryClient::query()} for usage examples.
226232 *
227233 * @param string $query A BigQuery SQL query.
228- * @param array $options [optional] Please see the
229- * [API documentation for Job configuration](https://goo.gl/vSTbGp)
230- * for the available options.
234+ * @param array $options [optional] {
235+ * Configuration options.
236+ *
237+ * @type array $configuration Job configuration. Please see the
238+ * [API documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfiguration)
239+ * for the available options.
240+ * @type array $configuration.query Query job configuration. Please see the
241+ * [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationquery)
242+ * for the available options.
243+ * }
231244 * @return QueryJobConfiguration
232245 */
233246 public function queryConfig ($ query , array $ options = [])
@@ -305,7 +318,7 @@ public function queryConfig($query, array $options = [])
305318 * }
306319 * ```
307320 *
308- * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/query Query API documentation .
321+ * @see https://cloud.google.com/bigquery/docs/reference/rest/ v2/jobs/insert Jobs insert API Documentation .
309322 *
310323 * @param QueryJobConfiguration $query A BigQuery SQL query configuration.
311324 * @param array $options [optional] {
@@ -431,8 +444,7 @@ public function job($id, array $options = [])
431444 * echo $job->id() . PHP_EOL;
432445 * }
433446 * ```
434- *
435- * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/list Jobs list API documentation.
447+ * @see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/list Jobs list API documentation.
436448 *
437449 * @param array $options [optional] {
438450 * Configuration options.
@@ -485,20 +497,29 @@ function (array $job) {
485497 * point. To see the operations that can be performed on a dataset please
486498 * see {@see Google\Cloud\BigQuery\Dataset}.
487499 *
500+ * If the dataset is owned by a different project than the project used to authenticate the client,
501+ * provide the project ID as the second argument.
502+ *
488503 * Example:
489504 * ```
490505 * $dataset = $bigQuery->dataset('myDatasetId');
491506 * ```
492507 *
508+ * ```
509+ * // Reference a dataset from other project.
510+ * $dataset = $bigQuery->dataset('samples', 'bigquery-public-data');
511+ * ```
512+ *
493513 * @param string $id The id of the dataset to request.
514+ * @param string|null $projectId The id of the project. **Defaults to** current project id.
494515 * @return Dataset
495516 */
496- public function dataset ($ id )
517+ public function dataset ($ id, $ projectId = null )
497518 {
498519 return new Dataset (
499520 $ this ->connection ,
500521 $ id ,
501- $ this ->projectId ,
522+ $ projectId ?: $ this ->projectId ,
502523 $ this ->mapper ,
503524 [],
504525 $ this ->location
@@ -517,7 +538,7 @@ public function dataset($id)
517538 * }
518539 * ```
519540 *
520- * @see https://cloud.google.com/bigquery/docs/reference/v2/datasets/list Datasets list API documentation.
541+ * @see https://cloud.google.com/bigquery/docs/reference/rest/ v2/datasets/list Datasets list API documentation.
521542 *
522543 * @codingStandardsIgnoreStart
523544 * @param array $options [optional] {
@@ -534,7 +555,7 @@ public function dataset($id)
534555 * request by label. The syntax is "labels.<name>[:<value>]".
535556 * Multiple filters can be ANDed together by connecting with a
536557 * space. Example: "labels.department:receiving labels.active".
537- * See [Filtering datasets using labels](https://cloud.google.com/bigquery/docs/labeling-datasets #filtering_datasets_using_labels)
558+ * See [Filtering datasets using labels](https://cloud.google.com/bigquery/docs/filtering-labels #filtering_datasets_using_labels)
538559 * for details.
539560 * }
540561 * @codingStandardsIgnoreEnd
@@ -577,15 +598,15 @@ function (array $dataset) {
577598 * $dataset = $bigQuery->createDataset('aDataset');
578599 * ```
579600 *
580- * @see https://cloud.google.com/bigquery/docs/reference/v2/datasets/insert Datasets insert API documentation.
601+ * @see https://cloud.google.com/bigquery/docs/reference/rest/ v2/datasets/insert Datasets insert API documentation.
581602 *
582603 * @param string $id The id of the dataset to create.
583604 * @param array $options [optional] {
584605 * Configuration options.
585606 *
586607 * @type array $metadata The available options for metadata are outlined
587- * at the
588- * [Dataset Resource API docs]( https://cloud.google.com/bigquery/docs/reference/v2/datasets#resource )
608+ * at the [Dataset Resource API docs](
609+ * https://cloud.google.com/bigquery/docs/reference/rest/ v2/datasets)
589610 * }
590611 * @return Dataset
591612 */
@@ -630,7 +651,7 @@ public function createDataset($id, array $options = [])
630651 * echo $job->isComplete(); // true
631652 * ```
632653 *
633- * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs Jobs insert API Documentation.
654+ * @see https://cloud.google.com/bigquery/docs/reference/rest/ v2/jobs/insert Jobs insert API Documentation.
634655 *
635656 * @param JobConfigurationInterface $config The job configuration.
636657 * @param array $options [optional] {
@@ -659,7 +680,7 @@ public function runJob(JobConfigurationInterface $config, array $options = [])
659680 * $job = $bigQuery->startJob($jobConfig);
660681 * ```
661682 *
662- * @see https://cloud.google.com/bigquery/docs/reference/v2/jobs Jobs insert API Documentation.
683+ * @see https://cloud.google.com/bigquery/docs/reference/rest/ v2/jobs/insert Jobs insert API Documentation.
663684 *
664685 * @param JobConfigurationInterface $config The job configuration.
665686 * @param array $options [optional] Configuration options.
@@ -770,7 +791,7 @@ public function timestamp(\DateTimeInterface $value)
770791 * Create a Numeric object.
771792 *
772793 * Numeric represents a value with a data type of
773- * [Numeric](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric-type ).
794+ * [Numeric](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric_type ).
774795 *
775796 * It supports a fixed 38 decimal digits of precision and 9 decimal digits of scale, and values
776797 * are in the range of -99999999999999999999999999999.999999999 to
@@ -807,4 +828,115 @@ public function getServiceAccount(array $options = [])
807828 $ resp = $ this ->connection ->getServiceAccount ($ options + ['projectId ' => $ this ->projectId ]);
808829 return $ resp ['email ' ];
809830 }
831+
832+ /**
833+ * Returns a copy job configuration to be passed to either
834+ * {@see Google\Cloud\BigQuery\BigQueryClient::runJob()} or
835+ * {@see Google\Cloud\BigQuery\BigQueryClient::startJob()}. A
836+ * configuration can be built using fluent setters or by providing a full
837+ * set of options at once.
838+ *
839+ * Example:
840+ * ```
841+ * $copyJobConfig = $bigQuery->copy()
842+ * ->sourceTable($otherTable)
843+ * ->destinationTable($myTable);
844+ * ```
845+ *
846+ * @see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert Jobs insert API Documentation.
847+ *
848+ * @param array $options [optional] {
849+ * Configuration options.
850+ *
851+ * @type array $configuration Job configuration. Please see the
852+ * [API documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfiguration)
853+ * for the available options.
854+ * @type array $configuration.copy Copy job configuration. Please see the
855+ * [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationtablecopy)
856+ * for the available options.
857+ * }
858+ * @return CopyJobConfiguration
859+ */
860+ public function copy (array $ options = [])
861+ {
862+ return new CopyJobConfiguration (
863+ $ this ->projectId ,
864+ $ options ,
865+ $ this ->location
866+ );
867+ }
868+
869+ /**
870+ * Returns an extract job configuration to be passed to either
871+ * {@see Google\Cloud\BigQuery\BigQueryClient::runJob()} or
872+ * {@see Google\Cloud\BigQuery\BigQueryClient::startJob()}. A
873+ * configuration can be built using fluent setters or by providing a full
874+ * set of options at once.
875+ *
876+ * Example:
877+ * ```
878+ * $extractJobConfig = $bigQuery->extract()
879+ * ->sourceTable($table)
880+ * ->destinationUris(['gs://my-bucket/table.csv']);
881+ * ```
882+ *
883+ * @see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert Jobs insert API Documentation.
884+ *
885+ * @param array $options [optional] {
886+ * Configuration options.
887+ *
888+ * @type array $configuration Job configuration. Please see the
889+ * [API documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfiguration)
890+ * for the available options.
891+ * @type array $configuration.extract Extract job configuration. Please see the
892+ * [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationextract)
893+ * for the available options.
894+ * }
895+ * @return ExtractJobConfiguration
896+ */
897+ public function extract (array $ options = [])
898+ {
899+ return new ExtractJobConfiguration (
900+ $ this ->projectId ,
901+ $ options ,
902+ $ this ->location
903+ );
904+ }
905+
906+ /**
907+ * Returns a load job configuration to be passed to either
908+ * {@see Google\Cloud\BigQuery\BigQueryClient::runJob()} or
909+ * {@see Google\Cloud\BigQuery\BigQueryClient::startJob()}. A
910+ * configuration can be built using fluent setters or by providing a full
911+ * set of options at once.
912+ *
913+ * Example:
914+ * ```
915+ * $loadJobConfig = $bigQuery->load()
916+ * ->destinationTable($table)
917+ * ->sourceUris(['gs://my-bucket/table.csv']);
918+ * ```
919+ *
920+ * @see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert Jobs insert API Documentation.
921+ *
922+ * @param array $options [optional] {
923+ * Configuration options.
924+ *
925+ * @type array $configuration Job configuration. Please see the
926+ * [API documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfiguration)
927+ * for the available options.
928+ * @type array $configuration.load Load job configuration. Please see the
929+ * [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationload)
930+ * for the available options.
931+ * }
932+ * @return LoadJobConfiguration
933+ */
934+ public function load (array $ options = [])
935+ {
936+ return new LoadJobConfiguration (
937+ $ this ->projectId ,
938+ $ options ,
939+ $ this ->location
940+ );
941+ }
810942}
0 commit comments