1<?php
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18namespace Google\Service\Bigquery\Resource;
19
20use Google\Service\Bigquery\GetQueryResultsResponse;
21use Google\Service\Bigquery\Job;
22use Google\Service\Bigquery\JobCancelResponse;
23use Google\Service\Bigquery\JobList;
24use Google\Service\Bigquery\QueryRequest;
25use Google\Service\Bigquery\QueryResponse;
26
27/**
28 * The "jobs" collection of methods.
29 * Typical usage is:
30 *  <code>
31 *   $bigqueryService = new Google\Service\Bigquery(...);
32 *   $jobs = $bigqueryService->jobs;
33 *  </code>
34 */
35class Jobs extends \Google\Service\Resource
36{
37  /**
38   * Requests that a job be cancelled. This call will return immediately, and the
39   * client will need to poll for the job status to see if the cancel completed
40   * successfully. Cancelled jobs may still incur costs. (jobs.cancel)
41   *
42   * @param string $projectId [Required] Project ID of the job to cancel
43   * @param string $jobId [Required] Job ID of the job to cancel
44   * @param array $optParams Optional parameters.
45   *
46   * @opt_param string location The geographic location of the job. Required
47   * except for US and EU. See details at
48   * https://cloud.google.com/bigquery/docs/locations#specifying_your_location.
49   * @return JobCancelResponse
50   */
51  public function cancel($projectId, $jobId, $optParams = [])
52  {
53    $params = ['projectId' => $projectId, 'jobId' => $jobId];
54    $params = array_merge($params, $optParams);
55    return $this->call('cancel', [$params], JobCancelResponse::class);
56  }
57  /**
58   * Requests the deletion of the metadata of a job. This call returns when the
59   * job's metadata is deleted. (jobs.delete)
60   *
61   * @param string $projectId Required. Project ID of the job for which metadata
62   * is to be deleted.
63   * @param string $jobId Required. Job ID of the job for which metadata is to be
64   * deleted. If this is a parent job which has child jobs, the metadata from all
65   * child jobs will be deleted as well. Direct deletion of the metadata of child
66   * jobs is not allowed.
67   * @param array $optParams Optional parameters.
68   *
69   * @opt_param string location The geographic location of the job. Required. See
70   * details at:
71   * https://cloud.google.com/bigquery/docs/locations#specifying_your_location.
72   */
73  public function delete($projectId, $jobId, $optParams = [])
74  {
75    $params = ['projectId' => $projectId, 'jobId' => $jobId];
76    $params = array_merge($params, $optParams);
77    return $this->call('delete', [$params]);
78  }
79  /**
80   * Returns information about a specific job. Job information is available for a
81   * six month period after creation. Requires that you're the person who ran the
82   * job, or have the Is Owner project role. (jobs.get)
83   *
84   * @param string $projectId [Required] Project ID of the requested job
85   * @param string $jobId [Required] Job ID of the requested job
86   * @param array $optParams Optional parameters.
87   *
88   * @opt_param string location The geographic location of the job. Required
89   * except for US and EU. See details at
90   * https://cloud.google.com/bigquery/docs/locations#specifying_your_location.
91   * @return Job
92   */
93  public function get($projectId, $jobId, $optParams = [])
94  {
95    $params = ['projectId' => $projectId, 'jobId' => $jobId];
96    $params = array_merge($params, $optParams);
97    return $this->call('get', [$params], Job::class);
98  }
99  /**
100   * Retrieves the results of a query job. (jobs.getQueryResults)
101   *
102   * @param string $projectId [Required] Project ID of the query job
103   * @param string $jobId [Required] Job ID of the query job
104   * @param array $optParams Optional parameters.
105   *
106   * @opt_param string location The geographic location where the job should run.
107   * Required except for US and EU. See details at
108   * https://cloud.google.com/bigquery/docs/locations#specifying_your_location.
109   * @opt_param string maxResults Maximum number of results to read
110   * @opt_param string pageToken Page token, returned by a previous call, to
111   * request the next page of results
112   * @opt_param string startIndex Zero-based index of the starting row
113   * @opt_param string timeoutMs How long to wait for the query to complete, in
114   * milliseconds, before returning. Default is 10 seconds. If the timeout passes
115   * before the job completes, the 'jobComplete' field in the response will be
116   * false
117   * @return GetQueryResultsResponse
118   */
119  public function getQueryResults($projectId, $jobId, $optParams = [])
120  {
121    $params = ['projectId' => $projectId, 'jobId' => $jobId];
122    $params = array_merge($params, $optParams);
123    return $this->call('getQueryResults', [$params], GetQueryResultsResponse::class);
124  }
125  /**
126   * Starts a new asynchronous job. Requires the Can View project role.
127   * (jobs.insert)
128   *
129   * @param string $projectId Project ID of the project that will be billed for
130   * the job
131   * @param Job $postBody
132   * @param array $optParams Optional parameters.
133   * @return Job
134   */
135  public function insert($projectId, Job $postBody, $optParams = [])
136  {
137    $params = ['projectId' => $projectId, 'postBody' => $postBody];
138    $params = array_merge($params, $optParams);
139    return $this->call('insert', [$params], Job::class);
140  }
141  /**
142   * Lists all jobs that you started in the specified project. Job information is
143   * available for a six month period after creation. The job list is sorted in
144   * reverse chronological order, by job creation time. Requires the Can View
145   * project role, or the Is Owner project role if you set the allUsers property.
146   * (jobs.listJobs)
147   *
148   * @param string $projectId Project ID of the jobs to list
149   * @param array $optParams Optional parameters.
150   *
151   * @opt_param bool allUsers Whether to display jobs owned by all users in the
152   * project. Default false
153   * @opt_param string maxCreationTime Max value for job creation time, in
154   * milliseconds since the POSIX epoch. If set, only jobs created before or at
155   * this timestamp are returned
156   * @opt_param string maxResults Maximum number of results to return
157   * @opt_param string minCreationTime Min value for job creation time, in
158   * milliseconds since the POSIX epoch. If set, only jobs created after or at
159   * this timestamp are returned
160   * @opt_param string pageToken Page token, returned by a previous call, to
161   * request the next page of results
162   * @opt_param string parentJobId If set, retrieves only jobs whose parent is
163   * this job. Otherwise, retrieves only jobs which have no parent
164   * @opt_param string projection Restrict information returned to a set of
165   * selected fields
166   * @opt_param string stateFilter Filter for job state
167   * @return JobList
168   */
169  public function listJobs($projectId, $optParams = [])
170  {
171    $params = ['projectId' => $projectId];
172    $params = array_merge($params, $optParams);
173    return $this->call('list', [$params], JobList::class);
174  }
175  /**
176   * Runs a BigQuery SQL query synchronously and returns query results if the
177   * query completes within a specified timeout. (jobs.query)
178   *
179   * @param string $projectId Project ID of the project billed for the query
180   * @param QueryRequest $postBody
181   * @param array $optParams Optional parameters.
182   * @return QueryResponse
183   */
184  public function query($projectId, QueryRequest $postBody, $optParams = [])
185  {
186    $params = ['projectId' => $projectId, 'postBody' => $postBody];
187    $params = array_merge($params, $optParams);
188    return $this->call('query', [$params], QueryResponse::class);
189  }
190}
191
192// Adding a class alias for backwards compatibility with the previous class name.
193class_alias(Jobs::class, 'Google_Service_Bigquery_Resource_Jobs');
194