1 | /*!
|
2 | * Copyright 2019 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | import { ServiceObject } from '@google-cloud/common';
|
17 | import { BigQuery, Job, Dataset, ResourceCallback, RequestCallback, JobRequest } from '.';
|
18 | import { JobMetadata } from './job';
|
19 | import bigquery from './types';
|
20 | export interface File {
|
21 | bucket: any;
|
22 | kmsKeyName?: string;
|
23 | userProject?: string;
|
24 | name: string;
|
25 | generation?: number;
|
26 | }
|
27 | export type JobMetadataCallback = RequestCallback<JobMetadata>;
|
28 | export type JobMetadataResponse = [JobMetadata];
|
29 | export type JobResponse = [Job, bigquery.IJob];
|
30 | export type JobCallback = ResourceCallback<Job, bigquery.IJob>;
|
31 | export type CreateExtractJobOptions = JobRequest<bigquery.IJobConfigurationExtract> & {
|
32 | format?: 'ML_TF_SAVED_MODEL' | 'ML_XGBOOST_BOOSTER';
|
33 | };
|
34 | /**
|
35 | * Model objects are returned by methods such as {@link Dataset#model} and
|
36 | * {@link Dataset#getModels}.
|
37 | *
|
38 | * @class
|
39 | * @param {Dataset} dataset {@link Dataset} instance.
|
40 | * @param {string} id The ID of the model.
|
41 | *
|
42 | * @example
|
43 | * ```
|
44 | * const {BigQuery} = require('@google-cloud/bigquery');
|
45 | * const bigquery = new BigQuery();
|
46 | * const dataset = bigquery.dataset('my-dataset');
|
47 | *
|
48 | * const model = dataset.model('my-model');
|
49 | * ```
|
50 | */
|
51 | declare class Model extends ServiceObject {
|
52 | dataset: Dataset;
|
53 | bigQuery: BigQuery;
|
54 | constructor(dataset: Dataset, id: string);
|
55 | /**
|
56 | * @callback JobCallback
|
57 | * @param {?Error} err Request error, if any.
|
58 | * //cloud.google.com/bigquery/docs/reference/v2/Job} resource.
{object} Job The [Job]{ https: |
59 | * {object} apiResponse The full API response.
|
60 | */
|
61 | /**
|
62 | * @typedef {array} JobResponse
|
63 | * @property {object} 0 The [Job]{@link https://cloud.google.com/bigquery/docs/reference/v2/Job} resource.
|
64 | * @property {object} 1 The full API response.
|
65 | */
|
66 | /**
|
67 | * Export model to Cloud Storage.
|
68 | *
|
69 | * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert| Jobs: insert API Documentation}
|
70 | *
|
71 | * @param {string|File} destination Where the model should be exported
|
72 | * to. A string or {@link
|
73 | * https://googleapis.dev/nodejs/storage/latest/File.html File}
|
74 | * object.
|
75 | * @param {object} [options] The configuration object. For all extract job options, see [CreateExtractJobOptions]{@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract}.
|
76 | * @param {string} [options.format] The format to export the data in.
|
77 | * Allowed options are "ML_TF_SAVED_MODEL" or "ML_XGBOOST_BOOSTER".
|
78 | * Default: "ML_TF_SAVED_MODEL".
|
79 | * @param {string} [options.jobId] Custom job id.
|
80 | * @param {string} [options.jobPrefix] Prefix to apply to the job id.
|
81 | * @param {JobCallback} [callback] The callback function.
|
82 | * @param {?error} callback.err An error returned while making this request.
|
83 | * @param {Job} callback.job The job used to export the model.
|
84 | * @param {object} callback.apiResponse The full API response.
|
85 | * @returns {Promise<JobResponse>}
|
86 | *
|
87 | * @throws {Error} If a destination isn't a string or File object.
|
88 | *
|
89 | * @example
|
90 | * ```
|
91 | * const {BigQuery} = require('@google-cloud/bigquery');
|
92 | * const bigquery = new BigQuery();
|
93 | * const dataset = bigquery.dataset('my-dataset');
|
94 | * const model = dataset.model('my-model');
|
95 | *
|
96 | * const extractedModel = 'gs://my-bucket/extracted-model';
|
97 | *
|
98 | * function callback(err, job, apiResponse) {
|
99 | * // `job` is a Job object that can be used to check the status of the
|
100 | * // request.
|
101 | * }
|
102 | *
|
103 | * //-
|
104 | * // To use the default options, just pass a string or a {@link
|
105 | * https://googleapis.dev/nodejs/storage/latest/File.html File}
|
106 | * object.
|
107 | * //
|
108 | * // Note: The default format is 'ML_TF_SAVED_MODEL'.
|
109 | * //-
|
110 | * model.createExtractJob(extractedModel, callback);
|
111 | *
|
112 | * //-
|
113 | * // If you need more customization, pass an `options` object.
|
114 | * //-
|
115 | * const options = {
|
116 | * format: 'ML_TF_SAVED_MODEL',
|
117 | * jobId: '123abc'
|
118 | * };
|
119 | *
|
120 | * model.createExtractJob(extractedModel, options, callback);
|
121 | *
|
122 | * //-
|
123 | * // If the callback is omitted, we'll return a Promise.
|
124 | * //-
|
125 | * model.createExtractJob(extractedModel, options).then((data) => {
|
126 | * const job = data[0];
|
127 | * const apiResponse = data[1];
|
128 | * });
|
129 | * ```
|
130 | */
|
131 | createExtractJob(destination: string | File, options?: CreateExtractJobOptions): Promise<JobResponse>;
|
132 | createExtractJob(destination: string | File, options: CreateExtractJobOptions, callback: JobCallback): void;
|
133 | createExtractJob(destination: string | File, callback: JobCallback): void;
|
134 | /**
|
135 | * @callback JobMetadataCallback
|
136 | * @param {?Error} err Request error, if any.
|
137 | * @param {object} metadata The job metadata.
|
138 | * @param {object} apiResponse The full API response.
|
139 | */
|
140 | /**
|
141 | * @typedef {array} JobMetadataResponse
|
142 | * @property {object} 0 The job metadata.
|
143 | * @property {object} 1 The full API response.
|
144 | */
|
145 | /**
|
146 | * Export model to Cloud Storage.
|
147 | *
|
148 | * @param {string|File} destination Where the model should be exported
|
149 | * to. A string or {@link
|
150 | * https://googleapis.dev/nodejs/storage/latest/File.html File}
|
151 | * object.
|
152 | * @param {object} [options] The configuration object. For all extract job options, see [CreateExtractJobOptions]{@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract}.
|
153 | * @param {string} [options.format] The format to export
|
154 | * the data in. Allowed options are "ML_TF_SAVED_MODEL" or
|
155 | * "ML_XGBOOST_BOOSTER". Default: "ML_TF_SAVED_MODEL".
|
156 | * @param {string} [options.jobId] Custom id for the underlying job.
|
157 | * @param {string} [options.jobPrefix] Prefix to apply to the underlying job id.
|
158 | * @param {JobMetadataCallback} [callback] The callback function.
|
159 | * @param {?error} callback.err An error returned while making this request
|
160 | * @param {object} callback.apiResponse The full API response.
|
161 | * @returns {Promise<JobMetadataResponse>}
|
162 | *
|
163 | * @throws {Error} If destination isn't a string or File object.
|
164 | *
|
165 | * @example
|
166 | * ```
|
167 | * const {BigQuery} = require('@google-cloud/bigquery');
|
168 | * const bigquery = new BigQuery();
|
169 | * const dataset = bigquery.dataset('my-dataset');
|
170 | * const model = dataset.model('my-model');
|
171 | *
|
172 | * const extractedModel = 'gs://my-bucket/extracted-model';
|
173 | *
|
174 | *
|
175 | * //-
|
176 | * function callback(err, job, apiResponse) {
|
177 | * // `job` is a Job object that can be used to check the status of the
|
178 | * // request.
|
179 | * }
|
180 | *
|
181 | * //-
|
182 | * // To use the default options, just pass a string or a {@link
|
183 | * https://googleapis.dev/nodejs/storage/latest/File.html File}
|
184 | * object.
|
185 | * //
|
186 | * // Note: The default format is 'ML_TF_SAVED_MODEL'.
|
187 | * //-
|
188 | * model.createExtractJob(extractedModel, callback);
|
189 | *
|
190 | * //-
|
191 | * // If you need more customization, pass an `options` object.
|
192 | * //-
|
193 | * const options = {
|
194 | * format: 'ML_TF_SAVED_MODEL',
|
195 | * jobId: '123abc'
|
196 | * };
|
197 | *
|
198 | * model.createExtractJob(extractedModel, options, callback);
|
199 | *
|
200 | * //-
|
201 | * // If the callback is omitted, we'll return a Promise.
|
202 | * //-
|
203 | * model.createExtractJob(extractedModel, options).then((data) => {
|
204 | * const job = data[0];
|
205 | * const apiResponse = data[1];
|
206 | * });
|
207 | * ```
|
208 | */
|
209 | extract(destination: string | File, options?: CreateExtractJobOptions): Promise<JobMetadataResponse>;
|
210 | extract(destination: string | File, options: CreateExtractJobOptions, callback?: JobMetadataCallback): void;
|
211 | extract(destination: string | File, callback?: JobMetadataCallback): void;
|
212 | }
|
213 | /**
|
214 | * Reference to the {@link Model} class.
|
215 | * @name module:@google-cloud/bigquery.Model
|
216 | * @see Model
|
217 | */
|
218 | export { Model };
|