diff --git a/packages/google-cloud-bigquery-migration/protos/google/cloud/bigquery/migration/v2alpha/translation_service.proto b/packages/google-cloud-bigquery-migration/protos/google/cloud/bigquery/migration/v2alpha/translation_service.proto new file mode 100644 index 00000000000..59924506c04 --- /dev/null +++ b/packages/google-cloud-bigquery-migration/protos/google/cloud/bigquery/migration/v2alpha/translation_service.proto @@ -0,0 +1,135 @@ +// Copyright 2021 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. + +syntax = "proto3"; + +package google.cloud.bigquery.migration.v2alpha; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; + +option csharp_namespace = "Google.Cloud.BigQuery.Migration.V2Alpha"; +option go_package = "cloud.google.com/go/bigquery/migration/apiv2alpha/migrationpb;migrationpb"; +option java_multiple_files = true; +option java_outer_classname = "TranslationServiceProto"; +option java_package = "com.google.cloud.bigquery.migration.v2alpha"; +option php_namespace = "Google\\Cloud\\BigQuery\\Migration\\V2alpha"; + +// Provides other SQL dialects to GoogleSQL translation operations. +service SqlTranslationService { + option (google.api.default_host) = "bigquerymigration.googleapis.com"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + + // Translates input queries from source dialects to GoogleSQL. + rpc TranslateQuery(TranslateQueryRequest) returns (TranslateQueryResponse) { + option (google.api.http) = { + post: "/v2alpha/{parent=projects/*/locations/*}:translateQuery" + body: "*" + }; + option (google.api.method_signature) = "parent,source_dialect,query"; + } +} + +// The request of translating a SQL query to Standard SQL. +message TranslateQueryRequest { + // Supported SQL translation source dialects. + enum SqlTranslationSourceDialect { + // SqlTranslationSourceDialect not specified. + SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED = 0; + + // Teradata SQL. + TERADATA = 1; + } + + // Required. The name of the project to which this translation request belongs. + // Example: `projects/foo/locations/bar` + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "locations.googleapis.com/Location" + } + ]; + + // Required. The source SQL dialect of `queries`. + SqlTranslationSourceDialect source_dialect = 2 [(google.api.field_behavior) = REQUIRED]; + + // Required. The query to be translated. + string query = 3 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of translating a SQL query to Standard SQL. +message TranslateQueryResponse { + // Output only. Immutable. The unique identifier for the SQL translation job. + // Example: `projects/123/locations/us/translation/1234` + string translation_job = 4 [ + (google.api.field_behavior) = OUTPUT_ONLY, + (google.api.field_behavior) = IMMUTABLE + ]; + + // The translated result. This will be empty if the translation fails. + string translated_query = 1; + + // The list of errors encountered during the translation, if present. + repeated SqlTranslationError errors = 2; + + // The list of warnings encountered during the translation, if present, + // indicates non-semantically correct translation. + repeated SqlTranslationWarning warnings = 3; +} + +// Structured error object capturing the error message and the location in the +// source text where the error occurs. +message SqlTranslationErrorDetail { + // Specifies the row from the source text where the error occurred. + int64 row = 1; + + // Specifie the column from the source texts where the error occurred. + int64 column = 2; + + // A human-readable description of the error. + string message = 3; +} + +// The detailed error object if the SQL translation job fails. +message SqlTranslationError { + // The error type of the SQL translation job. + enum SqlTranslationErrorType { + // SqlTranslationErrorType not specified. + SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED = 0; + + // Failed to parse the input text as a SQL query. + SQL_PARSE_ERROR = 1; + + // Found unsupported functions in the input SQL query that are not able to + // translate. + UNSUPPORTED_SQL_FUNCTION = 2; + } + + // The type of SQL translation error. + SqlTranslationErrorType error_type = 1; + + // Specifies the details of the error, including the error message and + // location from the source text. + SqlTranslationErrorDetail error_detail = 2; +} + +// The detailed warning object if the SQL translation job is completed but not +// semantically correct. +message SqlTranslationWarning { + // Specifies the details of the warning, including the warning message and + // location from the source text. + SqlTranslationErrorDetail warning_detail = 1; +} diff --git a/packages/google-cloud-bigquery-migration/protos/protos.d.ts b/packages/google-cloud-bigquery-migration/protos/protos.d.ts index 5b6f9453f3d..b2a12eb6834 100644 --- a/packages/google-cloud-bigquery-migration/protos/protos.d.ts +++ b/packages/google-cloud-bigquery-migration/protos/protos.d.ts @@ -7988,6 +7988,603 @@ export namespace google { */ public static getTypeUrl(typeUrlPrefix?: string): string; } + + /** Represents a SqlTranslationService */ + class SqlTranslationService extends $protobuf.rpc.Service { + + /** + * Constructs a new SqlTranslationService service. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + */ + constructor(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean); + + /** + * Creates new SqlTranslationService service using the specified rpc implementation. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + * @returns RPC service. Useful where requests and/or responses are streamed. + */ + public static create(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean): SqlTranslationService; + + /** + * Calls TranslateQuery. + * @param request TranslateQueryRequest message or plain object + * @param callback Node-style callback called with the error, if any, and TranslateQueryResponse + */ + public translateQuery(request: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, callback: google.cloud.bigquery.migration.v2alpha.SqlTranslationService.TranslateQueryCallback): void; + + /** + * Calls TranslateQuery. + * @param request TranslateQueryRequest message or plain object + * @returns Promise + */ + public translateQuery(request: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest): Promise; + } + + namespace SqlTranslationService { + + /** + * Callback as used by {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationService|translateQuery}. + * @param error Error, if any + * @param [response] TranslateQueryResponse + */ + type TranslateQueryCallback = (error: (Error|null), response?: google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse) => void; + } + + /** Properties of a TranslateQueryRequest. */ + interface ITranslateQueryRequest { + + /** TranslateQueryRequest parent */ + parent?: (string|null); + + /** TranslateQueryRequest sourceDialect */ + sourceDialect?: (google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect|keyof typeof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect|null); + + /** TranslateQueryRequest query */ + query?: (string|null); + } + + /** Represents a TranslateQueryRequest. */ + class TranslateQueryRequest implements ITranslateQueryRequest { + + /** + * Constructs a new TranslateQueryRequest. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest); + + /** TranslateQueryRequest parent. */ + public parent: string; + + /** TranslateQueryRequest sourceDialect. */ + public sourceDialect: (google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect|keyof typeof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect); + + /** TranslateQueryRequest query. */ + public query: string; + + /** + * Creates a new TranslateQueryRequest instance using the specified properties. + * @param [properties] Properties to set + * @returns TranslateQueryRequest instance + */ + public static create(properties?: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest): google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest; + + /** + * Encodes the specified TranslateQueryRequest message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.verify|verify} messages. + * @param message TranslateQueryRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified TranslateQueryRequest message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.verify|verify} messages. + * @param message TranslateQueryRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a TranslateQueryRequest message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns TranslateQueryRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest; + + /** + * Decodes a TranslateQueryRequest message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns TranslateQueryRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest; + + /** + * Verifies a TranslateQueryRequest message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a TranslateQueryRequest message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns TranslateQueryRequest + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest; + + /** + * Creates a plain object from a TranslateQueryRequest message. Also converts values to other types if specified. + * @param message TranslateQueryRequest + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this TranslateQueryRequest to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for TranslateQueryRequest + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace TranslateQueryRequest { + + /** SqlTranslationSourceDialect enum. */ + enum SqlTranslationSourceDialect { + SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED = 0, + TERADATA = 1 + } + } + + /** Properties of a TranslateQueryResponse. */ + interface ITranslateQueryResponse { + + /** TranslateQueryResponse translationJob */ + translationJob?: (string|null); + + /** TranslateQueryResponse translatedQuery */ + translatedQuery?: (string|null); + + /** TranslateQueryResponse errors */ + errors?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationError[]|null); + + /** TranslateQueryResponse warnings */ + warnings?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning[]|null); + } + + /** Represents a TranslateQueryResponse. */ + class TranslateQueryResponse implements ITranslateQueryResponse { + + /** + * Constructs a new TranslateQueryResponse. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse); + + /** TranslateQueryResponse translationJob. */ + public translationJob: string; + + /** TranslateQueryResponse translatedQuery. */ + public translatedQuery: string; + + /** TranslateQueryResponse errors. */ + public errors: google.cloud.bigquery.migration.v2alpha.ISqlTranslationError[]; + + /** TranslateQueryResponse warnings. */ + public warnings: google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning[]; + + /** + * Creates a new TranslateQueryResponse instance using the specified properties. + * @param [properties] Properties to set + * @returns TranslateQueryResponse instance + */ + public static create(properties?: google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse): google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse; + + /** + * Encodes the specified TranslateQueryResponse message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.verify|verify} messages. + * @param message TranslateQueryResponse message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified TranslateQueryResponse message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.verify|verify} messages. + * @param message TranslateQueryResponse message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a TranslateQueryResponse message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns TranslateQueryResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse; + + /** + * Decodes a TranslateQueryResponse message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns TranslateQueryResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse; + + /** + * Verifies a TranslateQueryResponse message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a TranslateQueryResponse message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns TranslateQueryResponse + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse; + + /** + * Creates a plain object from a TranslateQueryResponse message. Also converts values to other types if specified. + * @param message TranslateQueryResponse + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this TranslateQueryResponse to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for TranslateQueryResponse + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + /** Properties of a SqlTranslationErrorDetail. */ + interface ISqlTranslationErrorDetail { + + /** SqlTranslationErrorDetail row */ + row?: (number|Long|string|null); + + /** SqlTranslationErrorDetail column */ + column?: (number|Long|string|null); + + /** SqlTranslationErrorDetail message */ + message?: (string|null); + } + + /** Represents a SqlTranslationErrorDetail. */ + class SqlTranslationErrorDetail implements ISqlTranslationErrorDetail { + + /** + * Constructs a new SqlTranslationErrorDetail. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail); + + /** SqlTranslationErrorDetail row. */ + public row: (number|Long|string); + + /** SqlTranslationErrorDetail column. */ + public column: (number|Long|string); + + /** SqlTranslationErrorDetail message. */ + public message: string; + + /** + * Creates a new SqlTranslationErrorDetail instance using the specified properties. + * @param [properties] Properties to set + * @returns SqlTranslationErrorDetail instance + */ + public static create(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail): google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail; + + /** + * Encodes the specified SqlTranslationErrorDetail message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify|verify} messages. + * @param message SqlTranslationErrorDetail message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified SqlTranslationErrorDetail message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify|verify} messages. + * @param message SqlTranslationErrorDetail message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SqlTranslationErrorDetail message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns SqlTranslationErrorDetail + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail; + + /** + * Decodes a SqlTranslationErrorDetail message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns SqlTranslationErrorDetail + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail; + + /** + * Verifies a SqlTranslationErrorDetail message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a SqlTranslationErrorDetail message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns SqlTranslationErrorDetail + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail; + + /** + * Creates a plain object from a SqlTranslationErrorDetail message. Also converts values to other types if specified. + * @param message SqlTranslationErrorDetail + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SqlTranslationErrorDetail to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for SqlTranslationErrorDetail + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + /** Properties of a SqlTranslationError. */ + interface ISqlTranslationError { + + /** SqlTranslationError errorType */ + errorType?: (google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType|keyof typeof google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType|null); + + /** SqlTranslationError errorDetail */ + errorDetail?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null); + } + + /** Represents a SqlTranslationError. */ + class SqlTranslationError implements ISqlTranslationError { + + /** + * Constructs a new SqlTranslationError. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationError); + + /** SqlTranslationError errorType. */ + public errorType: (google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType|keyof typeof google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType); + + /** SqlTranslationError errorDetail. */ + public errorDetail?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null); + + /** + * Creates a new SqlTranslationError instance using the specified properties. + * @param [properties] Properties to set + * @returns SqlTranslationError instance + */ + public static create(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationError): google.cloud.bigquery.migration.v2alpha.SqlTranslationError; + + /** + * Encodes the specified SqlTranslationError message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationError.verify|verify} messages. + * @param message SqlTranslationError message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationError, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified SqlTranslationError message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationError.verify|verify} messages. + * @param message SqlTranslationError message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationError, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SqlTranslationError message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns SqlTranslationError + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.bigquery.migration.v2alpha.SqlTranslationError; + + /** + * Decodes a SqlTranslationError message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns SqlTranslationError + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.bigquery.migration.v2alpha.SqlTranslationError; + + /** + * Verifies a SqlTranslationError message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a SqlTranslationError message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns SqlTranslationError + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.migration.v2alpha.SqlTranslationError; + + /** + * Creates a plain object from a SqlTranslationError message. Also converts values to other types if specified. + * @param message SqlTranslationError + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.migration.v2alpha.SqlTranslationError, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SqlTranslationError to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for SqlTranslationError + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace SqlTranslationError { + + /** SqlTranslationErrorType enum. */ + enum SqlTranslationErrorType { + SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED = 0, + SQL_PARSE_ERROR = 1, + UNSUPPORTED_SQL_FUNCTION = 2 + } + } + + /** Properties of a SqlTranslationWarning. */ + interface ISqlTranslationWarning { + + /** SqlTranslationWarning warningDetail */ + warningDetail?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null); + } + + /** Represents a SqlTranslationWarning. */ + class SqlTranslationWarning implements ISqlTranslationWarning { + + /** + * Constructs a new SqlTranslationWarning. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning); + + /** SqlTranslationWarning warningDetail. */ + public warningDetail?: (google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null); + + /** + * Creates a new SqlTranslationWarning instance using the specified properties. + * @param [properties] Properties to set + * @returns SqlTranslationWarning instance + */ + public static create(properties?: google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning): google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning; + + /** + * Encodes the specified SqlTranslationWarning message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.verify|verify} messages. + * @param message SqlTranslationWarning message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified SqlTranslationWarning message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.verify|verify} messages. + * @param message SqlTranslationWarning message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SqlTranslationWarning message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns SqlTranslationWarning + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning; + + /** + * Decodes a SqlTranslationWarning message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns SqlTranslationWarning + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning; + + /** + * Verifies a SqlTranslationWarning message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a SqlTranslationWarning message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns SqlTranslationWarning + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning; + + /** + * Creates a plain object from a SqlTranslationWarning message. Also converts values to other types if specified. + * @param message SqlTranslationWarning + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SqlTranslationWarning to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for SqlTranslationWarning + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } } } } diff --git a/packages/google-cloud-bigquery-migration/protos/protos.js b/packages/google-cloud-bigquery-migration/protos/protos.js index 0db3d7d0035..f8feb3e6f7d 100644 --- a/packages/google-cloud-bigquery-migration/protos/protos.js +++ b/packages/google-cloud-bigquery-migration/protos/protos.js @@ -19526,6 +19526,1432 @@ return ListMigrationSubtasksResponse; })(); + v2alpha.SqlTranslationService = (function() { + + /** + * Constructs a new SqlTranslationService service. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a SqlTranslationService + * @extends $protobuf.rpc.Service + * @constructor + * @param {$protobuf.RPCImpl} rpcImpl RPC implementation + * @param {boolean} [requestDelimited=false] Whether requests are length-delimited + * @param {boolean} [responseDelimited=false] Whether responses are length-delimited + */ + function SqlTranslationService(rpcImpl, requestDelimited, responseDelimited) { + $protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited); + } + + (SqlTranslationService.prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = SqlTranslationService; + + /** + * Creates new SqlTranslationService service using the specified rpc implementation. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationService + * @static + * @param {$protobuf.RPCImpl} rpcImpl RPC implementation + * @param {boolean} [requestDelimited=false] Whether requests are length-delimited + * @param {boolean} [responseDelimited=false] Whether responses are length-delimited + * @returns {SqlTranslationService} RPC service. Useful where requests and/or responses are streamed. + */ + SqlTranslationService.create = function create(rpcImpl, requestDelimited, responseDelimited) { + return new this(rpcImpl, requestDelimited, responseDelimited); + }; + + /** + * Callback as used by {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationService|translateQuery}. + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationService + * @typedef TranslateQueryCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} [response] TranslateQueryResponse + */ + + /** + * Calls TranslateQuery. + * @function translateQuery + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationService + * @instance + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest} request TranslateQueryRequest message or plain object + * @param {google.cloud.bigquery.migration.v2alpha.SqlTranslationService.TranslateQueryCallback} callback Node-style callback called with the error, if any, and TranslateQueryResponse + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(SqlTranslationService.prototype.translateQuery = function translateQuery(request, callback) { + return this.rpcCall(translateQuery, $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest, $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse, request, callback); + }, "name", { value: "TranslateQuery" }); + + /** + * Calls TranslateQuery. + * @function translateQuery + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationService + * @instance + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest} request TranslateQueryRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + + return SqlTranslationService; + })(); + + v2alpha.TranslateQueryRequest = (function() { + + /** + * Properties of a TranslateQueryRequest. + * @memberof google.cloud.bigquery.migration.v2alpha + * @interface ITranslateQueryRequest + * @property {string|null} [parent] TranslateQueryRequest parent + * @property {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect|null} [sourceDialect] TranslateQueryRequest sourceDialect + * @property {string|null} [query] TranslateQueryRequest query + */ + + /** + * Constructs a new TranslateQueryRequest. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a TranslateQueryRequest. + * @implements ITranslateQueryRequest + * @constructor + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest=} [properties] Properties to set + */ + function TranslateQueryRequest(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TranslateQueryRequest parent. + * @member {string} parent + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @instance + */ + TranslateQueryRequest.prototype.parent = ""; + + /** + * TranslateQueryRequest sourceDialect. + * @member {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect} sourceDialect + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @instance + */ + TranslateQueryRequest.prototype.sourceDialect = 0; + + /** + * TranslateQueryRequest query. + * @member {string} query + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @instance + */ + TranslateQueryRequest.prototype.query = ""; + + /** + * Creates a new TranslateQueryRequest instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest=} [properties] Properties to set + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest} TranslateQueryRequest instance + */ + TranslateQueryRequest.create = function create(properties) { + return new TranslateQueryRequest(properties); + }; + + /** + * Encodes the specified TranslateQueryRequest message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest} message TranslateQueryRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TranslateQueryRequest.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.parent); + if (message.sourceDialect != null && Object.hasOwnProperty.call(message, "sourceDialect")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.sourceDialect); + if (message.query != null && Object.hasOwnProperty.call(message, "query")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.query); + return writer; + }; + + /** + * Encodes the specified TranslateQueryRequest message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest} message TranslateQueryRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TranslateQueryRequest.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TranslateQueryRequest message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest} TranslateQueryRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TranslateQueryRequest.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.parent = reader.string(); + break; + } + case 2: { + message.sourceDialect = reader.int32(); + break; + } + case 3: { + message.query = reader.string(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TranslateQueryRequest message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest} TranslateQueryRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TranslateQueryRequest.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TranslateQueryRequest message. + * @function verify + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TranslateQueryRequest.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.parent != null && message.hasOwnProperty("parent")) + if (!$util.isString(message.parent)) + return "parent: string expected"; + if (message.sourceDialect != null && message.hasOwnProperty("sourceDialect")) + switch (message.sourceDialect) { + default: + return "sourceDialect: enum value expected"; + case 0: + case 1: + break; + } + if (message.query != null && message.hasOwnProperty("query")) + if (!$util.isString(message.query)) + return "query: string expected"; + return null; + }; + + /** + * Creates a TranslateQueryRequest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest} TranslateQueryRequest + */ + TranslateQueryRequest.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest) + return object; + var message = new $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest(); + if (object.parent != null) + message.parent = String(object.parent); + switch (object.sourceDialect) { + default: + if (typeof object.sourceDialect === "number") { + message.sourceDialect = object.sourceDialect; + break; + } + break; + case "SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED": + case 0: + message.sourceDialect = 0; + break; + case "TERADATA": + case 1: + message.sourceDialect = 1; + break; + } + if (object.query != null) + message.query = String(object.query); + return message; + }; + + /** + * Creates a plain object from a TranslateQueryRequest message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest} message TranslateQueryRequest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TranslateQueryRequest.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.parent = ""; + object.sourceDialect = options.enums === String ? "SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED" : 0; + object.query = ""; + } + if (message.parent != null && message.hasOwnProperty("parent")) + object.parent = message.parent; + if (message.sourceDialect != null && message.hasOwnProperty("sourceDialect")) + object.sourceDialect = options.enums === String ? $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect[message.sourceDialect] === undefined ? message.sourceDialect : $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect[message.sourceDialect] : message.sourceDialect; + if (message.query != null && message.hasOwnProperty("query")) + object.query = message.query; + return object; + }; + + /** + * Converts this TranslateQueryRequest to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @instance + * @returns {Object.} JSON object + */ + TranslateQueryRequest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for TranslateQueryRequest + * @function getTypeUrl + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + TranslateQueryRequest.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest"; + }; + + /** + * SqlTranslationSourceDialect enum. + * @name google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect + * @enum {number} + * @property {number} SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED=0 SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED value + * @property {number} TERADATA=1 TERADATA value + */ + TranslateQueryRequest.SqlTranslationSourceDialect = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED"] = 0; + values[valuesById[1] = "TERADATA"] = 1; + return values; + })(); + + return TranslateQueryRequest; + })(); + + v2alpha.TranslateQueryResponse = (function() { + + /** + * Properties of a TranslateQueryResponse. + * @memberof google.cloud.bigquery.migration.v2alpha + * @interface ITranslateQueryResponse + * @property {string|null} [translationJob] TranslateQueryResponse translationJob + * @property {string|null} [translatedQuery] TranslateQueryResponse translatedQuery + * @property {Array.|null} [errors] TranslateQueryResponse errors + * @property {Array.|null} [warnings] TranslateQueryResponse warnings + */ + + /** + * Constructs a new TranslateQueryResponse. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a TranslateQueryResponse. + * @implements ITranslateQueryResponse + * @constructor + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse=} [properties] Properties to set + */ + function TranslateQueryResponse(properties) { + this.errors = []; + this.warnings = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TranslateQueryResponse translationJob. + * @member {string} translationJob + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @instance + */ + TranslateQueryResponse.prototype.translationJob = ""; + + /** + * TranslateQueryResponse translatedQuery. + * @member {string} translatedQuery + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @instance + */ + TranslateQueryResponse.prototype.translatedQuery = ""; + + /** + * TranslateQueryResponse errors. + * @member {Array.} errors + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @instance + */ + TranslateQueryResponse.prototype.errors = $util.emptyArray; + + /** + * TranslateQueryResponse warnings. + * @member {Array.} warnings + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @instance + */ + TranslateQueryResponse.prototype.warnings = $util.emptyArray; + + /** + * Creates a new TranslateQueryResponse instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse=} [properties] Properties to set + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} TranslateQueryResponse instance + */ + TranslateQueryResponse.create = function create(properties) { + return new TranslateQueryResponse(properties); + }; + + /** + * Encodes the specified TranslateQueryResponse message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse} message TranslateQueryResponse message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TranslateQueryResponse.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.translatedQuery != null && Object.hasOwnProperty.call(message, "translatedQuery")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.translatedQuery); + if (message.errors != null && message.errors.length) + for (var i = 0; i < message.errors.length; ++i) + $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.encode(message.errors[i], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.warnings != null && message.warnings.length) + for (var i = 0; i < message.warnings.length; ++i) + $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.encode(message.warnings[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + if (message.translationJob != null && Object.hasOwnProperty.call(message, "translationJob")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.translationJob); + return writer; + }; + + /** + * Encodes the specified TranslateQueryResponse message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse} message TranslateQueryResponse message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TranslateQueryResponse.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TranslateQueryResponse message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} TranslateQueryResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TranslateQueryResponse.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 4: { + message.translationJob = reader.string(); + break; + } + case 1: { + message.translatedQuery = reader.string(); + break; + } + case 2: { + if (!(message.errors && message.errors.length)) + message.errors = []; + message.errors.push($root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.decode(reader, reader.uint32())); + break; + } + case 3: { + if (!(message.warnings && message.warnings.length)) + message.warnings = []; + message.warnings.push($root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.decode(reader, reader.uint32())); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TranslateQueryResponse message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} TranslateQueryResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TranslateQueryResponse.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TranslateQueryResponse message. + * @function verify + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TranslateQueryResponse.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.translationJob != null && message.hasOwnProperty("translationJob")) + if (!$util.isString(message.translationJob)) + return "translationJob: string expected"; + if (message.translatedQuery != null && message.hasOwnProperty("translatedQuery")) + if (!$util.isString(message.translatedQuery)) + return "translatedQuery: string expected"; + if (message.errors != null && message.hasOwnProperty("errors")) { + if (!Array.isArray(message.errors)) + return "errors: array expected"; + for (var i = 0; i < message.errors.length; ++i) { + var error = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.verify(message.errors[i]); + if (error) + return "errors." + error; + } + } + if (message.warnings != null && message.hasOwnProperty("warnings")) { + if (!Array.isArray(message.warnings)) + return "warnings: array expected"; + for (var i = 0; i < message.warnings.length; ++i) { + var error = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.verify(message.warnings[i]); + if (error) + return "warnings." + error; + } + } + return null; + }; + + /** + * Creates a TranslateQueryResponse message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} TranslateQueryResponse + */ + TranslateQueryResponse.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse) + return object; + var message = new $root.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse(); + if (object.translationJob != null) + message.translationJob = String(object.translationJob); + if (object.translatedQuery != null) + message.translatedQuery = String(object.translatedQuery); + if (object.errors) { + if (!Array.isArray(object.errors)) + throw TypeError(".google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.errors: array expected"); + message.errors = []; + for (var i = 0; i < object.errors.length; ++i) { + if (typeof object.errors[i] !== "object") + throw TypeError(".google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.errors: object expected"); + message.errors[i] = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.fromObject(object.errors[i]); + } + } + if (object.warnings) { + if (!Array.isArray(object.warnings)) + throw TypeError(".google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.warnings: array expected"); + message.warnings = []; + for (var i = 0; i < object.warnings.length; ++i) { + if (typeof object.warnings[i] !== "object") + throw TypeError(".google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse.warnings: object expected"); + message.warnings[i] = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.fromObject(object.warnings[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a TranslateQueryResponse message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse} message TranslateQueryResponse + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TranslateQueryResponse.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.errors = []; + object.warnings = []; + } + if (options.defaults) { + object.translatedQuery = ""; + object.translationJob = ""; + } + if (message.translatedQuery != null && message.hasOwnProperty("translatedQuery")) + object.translatedQuery = message.translatedQuery; + if (message.errors && message.errors.length) { + object.errors = []; + for (var j = 0; j < message.errors.length; ++j) + object.errors[j] = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.toObject(message.errors[j], options); + } + if (message.warnings && message.warnings.length) { + object.warnings = []; + for (var j = 0; j < message.warnings.length; ++j) + object.warnings[j] = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.toObject(message.warnings[j], options); + } + if (message.translationJob != null && message.hasOwnProperty("translationJob")) + object.translationJob = message.translationJob; + return object; + }; + + /** + * Converts this TranslateQueryResponse to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @instance + * @returns {Object.} JSON object + */ + TranslateQueryResponse.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for TranslateQueryResponse + * @function getTypeUrl + * @memberof google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + TranslateQueryResponse.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse"; + }; + + return TranslateQueryResponse; + })(); + + v2alpha.SqlTranslationErrorDetail = (function() { + + /** + * Properties of a SqlTranslationErrorDetail. + * @memberof google.cloud.bigquery.migration.v2alpha + * @interface ISqlTranslationErrorDetail + * @property {number|Long|null} [row] SqlTranslationErrorDetail row + * @property {number|Long|null} [column] SqlTranslationErrorDetail column + * @property {string|null} [message] SqlTranslationErrorDetail message + */ + + /** + * Constructs a new SqlTranslationErrorDetail. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a SqlTranslationErrorDetail. + * @implements ISqlTranslationErrorDetail + * @constructor + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail=} [properties] Properties to set + */ + function SqlTranslationErrorDetail(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * SqlTranslationErrorDetail row. + * @member {number|Long} row + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @instance + */ + SqlTranslationErrorDetail.prototype.row = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * SqlTranslationErrorDetail column. + * @member {number|Long} column + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @instance + */ + SqlTranslationErrorDetail.prototype.column = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * SqlTranslationErrorDetail message. + * @member {string} message + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @instance + */ + SqlTranslationErrorDetail.prototype.message = ""; + + /** + * Creates a new SqlTranslationErrorDetail instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail=} [properties] Properties to set + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail} SqlTranslationErrorDetail instance + */ + SqlTranslationErrorDetail.create = function create(properties) { + return new SqlTranslationErrorDetail(properties); + }; + + /** + * Encodes the specified SqlTranslationErrorDetail message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail} message SqlTranslationErrorDetail message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationErrorDetail.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.row != null && Object.hasOwnProperty.call(message, "row")) + writer.uint32(/* id 1, wireType 0 =*/8).int64(message.row); + if (message.column != null && Object.hasOwnProperty.call(message, "column")) + writer.uint32(/* id 2, wireType 0 =*/16).int64(message.column); + if (message.message != null && Object.hasOwnProperty.call(message, "message")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.message); + return writer; + }; + + /** + * Encodes the specified SqlTranslationErrorDetail message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail} message SqlTranslationErrorDetail message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationErrorDetail.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a SqlTranslationErrorDetail message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail} SqlTranslationErrorDetail + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationErrorDetail.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.row = reader.int64(); + break; + } + case 2: { + message.column = reader.int64(); + break; + } + case 3: { + message.message = reader.string(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a SqlTranslationErrorDetail message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail} SqlTranslationErrorDetail + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationErrorDetail.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a SqlTranslationErrorDetail message. + * @function verify + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + SqlTranslationErrorDetail.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.row != null && message.hasOwnProperty("row")) + if (!$util.isInteger(message.row) && !(message.row && $util.isInteger(message.row.low) && $util.isInteger(message.row.high))) + return "row: integer|Long expected"; + if (message.column != null && message.hasOwnProperty("column")) + if (!$util.isInteger(message.column) && !(message.column && $util.isInteger(message.column.low) && $util.isInteger(message.column.high))) + return "column: integer|Long expected"; + if (message.message != null && message.hasOwnProperty("message")) + if (!$util.isString(message.message)) + return "message: string expected"; + return null; + }; + + /** + * Creates a SqlTranslationErrorDetail message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail} SqlTranslationErrorDetail + */ + SqlTranslationErrorDetail.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail) + return object; + var message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail(); + if (object.row != null) + if ($util.Long) + (message.row = $util.Long.fromValue(object.row)).unsigned = false; + else if (typeof object.row === "string") + message.row = parseInt(object.row, 10); + else if (typeof object.row === "number") + message.row = object.row; + else if (typeof object.row === "object") + message.row = new $util.LongBits(object.row.low >>> 0, object.row.high >>> 0).toNumber(); + if (object.column != null) + if ($util.Long) + (message.column = $util.Long.fromValue(object.column)).unsigned = false; + else if (typeof object.column === "string") + message.column = parseInt(object.column, 10); + else if (typeof object.column === "number") + message.column = object.column; + else if (typeof object.column === "object") + message.column = new $util.LongBits(object.column.low >>> 0, object.column.high >>> 0).toNumber(); + if (object.message != null) + message.message = String(object.message); + return message; + }; + + /** + * Creates a plain object from a SqlTranslationErrorDetail message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail} message SqlTranslationErrorDetail + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + SqlTranslationErrorDetail.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.row = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.row = options.longs === String ? "0" : 0; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.column = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.column = options.longs === String ? "0" : 0; + object.message = ""; + } + if (message.row != null && message.hasOwnProperty("row")) + if (typeof message.row === "number") + object.row = options.longs === String ? String(message.row) : message.row; + else + object.row = options.longs === String ? $util.Long.prototype.toString.call(message.row) : options.longs === Number ? new $util.LongBits(message.row.low >>> 0, message.row.high >>> 0).toNumber() : message.row; + if (message.column != null && message.hasOwnProperty("column")) + if (typeof message.column === "number") + object.column = options.longs === String ? String(message.column) : message.column; + else + object.column = options.longs === String ? $util.Long.prototype.toString.call(message.column) : options.longs === Number ? new $util.LongBits(message.column.low >>> 0, message.column.high >>> 0).toNumber() : message.column; + if (message.message != null && message.hasOwnProperty("message")) + object.message = message.message; + return object; + }; + + /** + * Converts this SqlTranslationErrorDetail to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @instance + * @returns {Object.} JSON object + */ + SqlTranslationErrorDetail.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for SqlTranslationErrorDetail + * @function getTypeUrl + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + SqlTranslationErrorDetail.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail"; + }; + + return SqlTranslationErrorDetail; + })(); + + v2alpha.SqlTranslationError = (function() { + + /** + * Properties of a SqlTranslationError. + * @memberof google.cloud.bigquery.migration.v2alpha + * @interface ISqlTranslationError + * @property {google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType|null} [errorType] SqlTranslationError errorType + * @property {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null} [errorDetail] SqlTranslationError errorDetail + */ + + /** + * Constructs a new SqlTranslationError. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a SqlTranslationError. + * @implements ISqlTranslationError + * @constructor + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationError=} [properties] Properties to set + */ + function SqlTranslationError(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * SqlTranslationError errorType. + * @member {google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType} errorType + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @instance + */ + SqlTranslationError.prototype.errorType = 0; + + /** + * SqlTranslationError errorDetail. + * @member {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null|undefined} errorDetail + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @instance + */ + SqlTranslationError.prototype.errorDetail = null; + + /** + * Creates a new SqlTranslationError instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationError=} [properties] Properties to set + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationError} SqlTranslationError instance + */ + SqlTranslationError.create = function create(properties) { + return new SqlTranslationError(properties); + }; + + /** + * Encodes the specified SqlTranslationError message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationError.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationError} message SqlTranslationError message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationError.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.errorType != null && Object.hasOwnProperty.call(message, "errorType")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.errorType); + if (message.errorDetail != null && Object.hasOwnProperty.call(message, "errorDetail")) + $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.encode(message.errorDetail, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified SqlTranslationError message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationError.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationError} message SqlTranslationError message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationError.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a SqlTranslationError message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationError} SqlTranslationError + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationError.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.errorType = reader.int32(); + break; + } + case 2: { + message.errorDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a SqlTranslationError message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationError} SqlTranslationError + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationError.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a SqlTranslationError message. + * @function verify + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + SqlTranslationError.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.errorType != null && message.hasOwnProperty("errorType")) + switch (message.errorType) { + default: + return "errorType: enum value expected"; + case 0: + case 1: + case 2: + break; + } + if (message.errorDetail != null && message.hasOwnProperty("errorDetail")) { + var error = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify(message.errorDetail); + if (error) + return "errorDetail." + error; + } + return null; + }; + + /** + * Creates a SqlTranslationError message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationError} SqlTranslationError + */ + SqlTranslationError.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError) + return object; + var message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError(); + switch (object.errorType) { + default: + if (typeof object.errorType === "number") { + message.errorType = object.errorType; + break; + } + break; + case "SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED": + case 0: + message.errorType = 0; + break; + case "SQL_PARSE_ERROR": + case 1: + message.errorType = 1; + break; + case "UNSUPPORTED_SQL_FUNCTION": + case 2: + message.errorType = 2; + break; + } + if (object.errorDetail != null) { + if (typeof object.errorDetail !== "object") + throw TypeError(".google.cloud.bigquery.migration.v2alpha.SqlTranslationError.errorDetail: object expected"); + message.errorDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.fromObject(object.errorDetail); + } + return message; + }; + + /** + * Creates a plain object from a SqlTranslationError message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {google.cloud.bigquery.migration.v2alpha.SqlTranslationError} message SqlTranslationError + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + SqlTranslationError.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.errorType = options.enums === String ? "SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED" : 0; + object.errorDetail = null; + } + if (message.errorType != null && message.hasOwnProperty("errorType")) + object.errorType = options.enums === String ? $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType[message.errorType] === undefined ? message.errorType : $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType[message.errorType] : message.errorType; + if (message.errorDetail != null && message.hasOwnProperty("errorDetail")) + object.errorDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.toObject(message.errorDetail, options); + return object; + }; + + /** + * Converts this SqlTranslationError to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @instance + * @returns {Object.} JSON object + */ + SqlTranslationError.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for SqlTranslationError + * @function getTypeUrl + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationError + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + SqlTranslationError.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.migration.v2alpha.SqlTranslationError"; + }; + + /** + * SqlTranslationErrorType enum. + * @name google.cloud.bigquery.migration.v2alpha.SqlTranslationError.SqlTranslationErrorType + * @enum {number} + * @property {number} SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED=0 SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED value + * @property {number} SQL_PARSE_ERROR=1 SQL_PARSE_ERROR value + * @property {number} UNSUPPORTED_SQL_FUNCTION=2 UNSUPPORTED_SQL_FUNCTION value + */ + SqlTranslationError.SqlTranslationErrorType = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED"] = 0; + values[valuesById[1] = "SQL_PARSE_ERROR"] = 1; + values[valuesById[2] = "UNSUPPORTED_SQL_FUNCTION"] = 2; + return values; + })(); + + return SqlTranslationError; + })(); + + v2alpha.SqlTranslationWarning = (function() { + + /** + * Properties of a SqlTranslationWarning. + * @memberof google.cloud.bigquery.migration.v2alpha + * @interface ISqlTranslationWarning + * @property {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null} [warningDetail] SqlTranslationWarning warningDetail + */ + + /** + * Constructs a new SqlTranslationWarning. + * @memberof google.cloud.bigquery.migration.v2alpha + * @classdesc Represents a SqlTranslationWarning. + * @implements ISqlTranslationWarning + * @constructor + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning=} [properties] Properties to set + */ + function SqlTranslationWarning(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * SqlTranslationWarning warningDetail. + * @member {google.cloud.bigquery.migration.v2alpha.ISqlTranslationErrorDetail|null|undefined} warningDetail + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @instance + */ + SqlTranslationWarning.prototype.warningDetail = null; + + /** + * Creates a new SqlTranslationWarning instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning=} [properties] Properties to set + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning} SqlTranslationWarning instance + */ + SqlTranslationWarning.create = function create(properties) { + return new SqlTranslationWarning(properties); + }; + + /** + * Encodes the specified SqlTranslationWarning message. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning} message SqlTranslationWarning message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationWarning.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.warningDetail != null && Object.hasOwnProperty.call(message, "warningDetail")) + $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.encode(message.warningDetail, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified SqlTranslationWarning message, length delimited. Does not implicitly {@link google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {google.cloud.bigquery.migration.v2alpha.ISqlTranslationWarning} message SqlTranslationWarning message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SqlTranslationWarning.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a SqlTranslationWarning message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning} SqlTranslationWarning + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationWarning.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.warningDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a SqlTranslationWarning message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning} SqlTranslationWarning + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SqlTranslationWarning.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a SqlTranslationWarning message. + * @function verify + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + SqlTranslationWarning.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.warningDetail != null && message.hasOwnProperty("warningDetail")) { + var error = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.verify(message.warningDetail); + if (error) + return "warningDetail." + error; + } + return null; + }; + + /** + * Creates a SqlTranslationWarning message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning} SqlTranslationWarning + */ + SqlTranslationWarning.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning) + return object; + var message = new $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning(); + if (object.warningDetail != null) { + if (typeof object.warningDetail !== "object") + throw TypeError(".google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning.warningDetail: object expected"); + message.warningDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.fromObject(object.warningDetail); + } + return message; + }; + + /** + * Creates a plain object from a SqlTranslationWarning message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning} message SqlTranslationWarning + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + SqlTranslationWarning.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.warningDetail = null; + if (message.warningDetail != null && message.hasOwnProperty("warningDetail")) + object.warningDetail = $root.google.cloud.bigquery.migration.v2alpha.SqlTranslationErrorDetail.toObject(message.warningDetail, options); + return object; + }; + + /** + * Converts this SqlTranslationWarning to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @instance + * @returns {Object.} JSON object + */ + SqlTranslationWarning.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for SqlTranslationWarning + * @function getTypeUrl + * @memberof google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + SqlTranslationWarning.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.migration.v2alpha.SqlTranslationWarning"; + }; + + return SqlTranslationWarning; + })(); + return v2alpha; })(); diff --git a/packages/google-cloud-bigquery-migration/protos/protos.json b/packages/google-cloud-bigquery-migration/protos/protos.json index b19455057b9..7eac1696506 100644 --- a/packages/google-cloud-bigquery-migration/protos/protos.json +++ b/packages/google-cloud-bigquery-migration/protos/protos.json @@ -949,7 +949,7 @@ "csharp_namespace": "Google.Cloud.BigQuery.Migration.V2Alpha", "go_package": "cloud.google.com/go/bigquery/migration/apiv2alpha/migrationpb;migrationpb", "java_multiple_files": true, - "java_outer_classname": "MigrationServiceProto", + "java_outer_classname": "TranslationServiceProto", "java_package": "com.google.cloud.bigquery.migration.v2alpha", "php_namespace": "Google\\Cloud\\BigQuery\\Migration\\V2alpha" }, @@ -1843,6 +1843,138 @@ "id": 2 } } + }, + "SqlTranslationService": { + "options": { + "(google.api.default_host)": "bigquerymigration.googleapis.com", + "(google.api.oauth_scopes)": "https://www.googleapis.com/auth/cloud-platform" + }, + "methods": { + "TranslateQuery": { + "requestType": "TranslateQueryRequest", + "responseType": "TranslateQueryResponse", + "options": { + "(google.api.http).post": "/v2alpha/{parent=projects/*/locations/*}:translateQuery", + "(google.api.http).body": "*", + "(google.api.method_signature)": "parent,source_dialect,query" + }, + "parsedOptions": [ + { + "(google.api.http)": { + "post": "/v2alpha/{parent=projects/*/locations/*}:translateQuery", + "body": "*" + } + }, + { + "(google.api.method_signature)": "parent,source_dialect,query" + } + ] + } + } + }, + "TranslateQueryRequest": { + "fields": { + "parent": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED", + "(google.api.resource_reference).type": "locations.googleapis.com/Location" + } + }, + "sourceDialect": { + "type": "SqlTranslationSourceDialect", + "id": 2, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "query": { + "type": "string", + "id": 3, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + } + }, + "nested": { + "SqlTranslationSourceDialect": { + "values": { + "SQL_TRANSLATION_SOURCE_DIALECT_UNSPECIFIED": 0, + "TERADATA": 1 + } + } + } + }, + "TranslateQueryResponse": { + "fields": { + "translationJob": { + "type": "string", + "id": 4, + "options": { + "(google.api.field_behavior)": "IMMUTABLE" + } + }, + "translatedQuery": { + "type": "string", + "id": 1 + }, + "errors": { + "rule": "repeated", + "type": "SqlTranslationError", + "id": 2 + }, + "warnings": { + "rule": "repeated", + "type": "SqlTranslationWarning", + "id": 3 + } + } + }, + "SqlTranslationErrorDetail": { + "fields": { + "row": { + "type": "int64", + "id": 1 + }, + "column": { + "type": "int64", + "id": 2 + }, + "message": { + "type": "string", + "id": 3 + } + } + }, + "SqlTranslationError": { + "fields": { + "errorType": { + "type": "SqlTranslationErrorType", + "id": 1 + }, + "errorDetail": { + "type": "SqlTranslationErrorDetail", + "id": 2 + } + }, + "nested": { + "SqlTranslationErrorType": { + "values": { + "SQL_TRANSLATION_ERROR_TYPE_UNSPECIFIED": 0, + "SQL_PARSE_ERROR": 1, + "UNSUPPORTED_SQL_FUNCTION": 2 + } + } + } + }, + "SqlTranslationWarning": { + "fields": { + "warningDetail": { + "type": "SqlTranslationErrorDetail", + "id": 1 + } + } } } } diff --git a/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/snippet_metadata.google.cloud.bigquery.migration.v2alpha.json b/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/snippet_metadata.google.cloud.bigquery.migration.v2alpha.json index 2b93180ea49..cda38c5f65b 100644 --- a/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/snippet_metadata.google.cloud.bigquery.migration.v2alpha.json +++ b/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/snippet_metadata.google.cloud.bigquery.migration.v2alpha.json @@ -330,6 +330,54 @@ } } } + }, + { + "regionTag": "bigquerymigration_v2alpha_generated_SqlTranslationService_TranslateQuery_async", + "title": "MigrationService translateQuery Sample", + "origin": "API_DEFINITION", + "description": " Translates input queries from source dialects to GoogleSQL.", + "canonical": true, + "file": "sql_translation_service.translate_query.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 64, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "TranslateQuery", + "fullName": "google.cloud.bigquery.migration.v2alpha.SqlTranslationService.TranslateQuery", + "async": true, + "parameters": [ + { + "name": "parent", + "type": "TYPE_STRING" + }, + { + "name": "source_dialect", + "type": ".google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect" + }, + { + "name": "query", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse", + "client": { + "shortName": "SqlTranslationServiceClient", + "fullName": "google.cloud.bigquery.migration.v2alpha.SqlTranslationServiceClient" + }, + "method": { + "shortName": "TranslateQuery", + "fullName": "google.cloud.bigquery.migration.v2alpha.SqlTranslationService.TranslateQuery", + "service": { + "shortName": "SqlTranslationService", + "fullName": "google.cloud.bigquery.migration.v2alpha.SqlTranslationService" + } + } + } } ] } \ No newline at end of file diff --git a/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/sql_translation_service.translate_query.js b/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/sql_translation_service.translate_query.js new file mode 100644 index 00000000000..82349b4ce2a --- /dev/null +++ b/packages/google-cloud-bigquery-migration/samples/generated/v2alpha/sql_translation_service.translate_query.js @@ -0,0 +1,72 @@ +// Copyright 2023 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(parent, sourceDialect, query) { + // [START bigquerymigration_v2alpha_generated_SqlTranslationService_TranslateQuery_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the project to which this translation request belongs. + * Example: `projects/foo/locations/bar` + */ + // const parent = 'abc123' + /** + * Required. The source SQL dialect of `queries`. + */ + // const sourceDialect = {} + /** + * Required. The query to be translated. + */ + // const query = 'abc123' + + // Imports the Migration library + const {SqlTranslationServiceClient} = require('@google-cloud/bigquery-migration').v2alpha; + + // Instantiates a client + const migrationClient = new SqlTranslationServiceClient(); + + async function callTranslateQuery() { + // Construct request + const request = { + parent, + sourceDialect, + query, + }; + + // Run request + const response = await migrationClient.translateQuery(request); + console.log(response); + } + + callTranslateQuery(); + // [END bigquerymigration_v2alpha_generated_SqlTranslationService_TranslateQuery_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/gapic_metadata.json b/packages/google-cloud-bigquery-migration/src/v2alpha/gapic_metadata.json index adf8d0647aa..9621cae014f 100644 --- a/packages/google-cloud-bigquery-migration/src/v2alpha/gapic_metadata.json +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/gapic_metadata.json @@ -96,6 +96,30 @@ } } } + }, + "SqlTranslationService": { + "clients": { + "grpc": { + "libraryClient": "SqlTranslationServiceClient", + "rpcs": { + "TranslateQuery": { + "methods": [ + "translateQuery" + ] + } + } + }, + "grpc-fallback": { + "libraryClient": "SqlTranslationServiceClient", + "rpcs": { + "TranslateQuery": { + "methods": [ + "translateQuery" + ] + } + } + } + } } } } diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/index.ts b/packages/google-cloud-bigquery-migration/src/v2alpha/index.ts index a6758ff7f70..1205d4e20d0 100644 --- a/packages/google-cloud-bigquery-migration/src/v2alpha/index.ts +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/index.ts @@ -17,3 +17,4 @@ // ** All changes to this file may be overwritten. ** export {MigrationServiceClient} from './migration_service_client'; +export {SqlTranslationServiceClient} from './sql_translation_service_client'; diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/migration_service_proto_list.json b/packages/google-cloud-bigquery-migration/src/v2alpha/migration_service_proto_list.json index 8e91e42510d..fdbd5988dca 100644 --- a/packages/google-cloud-bigquery-migration/src/v2alpha/migration_service_proto_list.json +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/migration_service_proto_list.json @@ -4,5 +4,6 @@ "../../protos/google/cloud/bigquery/migration/v2alpha/migration_error_details.proto", "../../protos/google/cloud/bigquery/migration/v2alpha/migration_metrics.proto", "../../protos/google/cloud/bigquery/migration/v2alpha/migration_service.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/translation_service.proto", "../../protos/google/cloud/bigquery/migration/v2alpha/translation_task.proto" ] diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client.ts b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client.ts new file mode 100644 index 00000000000..f7f3d2f0a81 --- /dev/null +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client.ts @@ -0,0 +1,609 @@ +// Copyright 2023 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import type * as gax from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, +} from 'google-gax'; + +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +/** + * Client JSON configuration object, loaded from + * `src/v2alpha/sql_translation_service_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './sql_translation_service_client_config.json'; +const version = require('../../../package.json').version; + +/** + * Provides other SQL dialects to GoogleSQL translation operations. + * @class + * @memberof v2alpha + */ +export class SqlTranslationServiceClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; + sqlTranslationServiceStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of SqlTranslationServiceClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. + * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new SqlTranslationServiceClient({fallback: 'rest'}, gax); + * ``` + */ + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback + ) { + // Ensure that options include all the required fields. + const staticMembers = this + .constructor as typeof SqlTranslationServiceClient; + const servicePath = + opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + this._providedCustomServicePath = !!( + opts?.servicePath || opts?.apiEndpoint + ); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + + // Determine the client header string. + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else if (opts.fallback === 'rest') { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + locationPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/locations/{location}' + ), + migrationSubtaskPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/locations/{location}/workflows/{workflow}/subtasks/{subtask}' + ), + migrationWorkflowPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/locations/{location}/workflows/{workflow}' + ), + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.cloud.bigquery.migration.v2alpha.SqlTranslationService', + gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, + {'x-goog-api-client': clientHeader.join(' ')} + ); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.sqlTranslationServiceStub) { + return this.sqlTranslationServiceStub; + } + + // Put together the "service stub" for + // google.cloud.bigquery.migration.v2alpha.SqlTranslationService. + this.sqlTranslationServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.bigquery.migration.v2alpha.SqlTranslationService' + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.cloud.bigquery.migration.v2alpha + .SqlTranslationService, + this._opts, + this._providedCustomServicePath + ) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const sqlTranslationServiceStubMethods = ['translateQuery']; + for (const methodName of sqlTranslationServiceStubMethods) { + const callPromise = this.sqlTranslationServiceStub.then( + stub => + (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error | null | undefined) => () => { + throw err; + } + ); + + const descriptor = undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.sqlTranslationServiceStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'bigquerymigration.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'bigquerymigration.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return ['https://www.googleapis.com/auth/cloud-platform']; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId( + callback?: Callback + ): Promise | void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- + /** + * Translates input queries from source dialects to GoogleSQL. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project to which this translation request belongs. + * Example: `projects/foo/locations/bar` + * @param {google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest.SqlTranslationSourceDialect} request.sourceDialect + * Required. The source SQL dialect of `queries`. + * @param {string} request.query + * Required. The query to be translated. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse | TranslateQueryResponse}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example include:samples/generated/v2alpha/sql_translation_service.translate_query.js + * region_tag:bigquerymigration_v2alpha_generated_SqlTranslationService_TranslateQuery_async + */ + translateQuery( + request?: protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, + options?: CallOptions + ): Promise< + [ + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + ( + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | undefined + ), + {} | undefined + ] + >; + translateQuery( + request: protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | null + | undefined, + {} | null | undefined + > + ): void; + translateQuery( + request: protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, + callback: Callback< + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | null + | undefined, + {} | null | undefined + > + ): void; + translateQuery( + request?: protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest, + optionsOrCallback?: + | CallOptions + | Callback< + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | null + | undefined, + {} | null | undefined + > + ): Promise< + [ + protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse, + ( + | protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryRequest + | undefined + ), + {} | undefined + ] + > | void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.translateQuery(request, options, callback); + } + + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified location resource name string. + * + * @param {string} project + * @param {string} location + * @returns {string} Resource name string. + */ + locationPath(project: string, location: string) { + return this.pathTemplates.locationPathTemplate.render({ + project: project, + location: location, + }); + } + + /** + * Parse the project from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the project. + */ + matchProjectFromLocationName(locationName: string) { + return this.pathTemplates.locationPathTemplate.match(locationName).project; + } + + /** + * Parse the location from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the location. + */ + matchLocationFromLocationName(locationName: string) { + return this.pathTemplates.locationPathTemplate.match(locationName).location; + } + + /** + * Return a fully-qualified migrationSubtask resource name string. + * + * @param {string} project + * @param {string} location + * @param {string} workflow + * @param {string} subtask + * @returns {string} Resource name string. + */ + migrationSubtaskPath( + project: string, + location: string, + workflow: string, + subtask: string + ) { + return this.pathTemplates.migrationSubtaskPathTemplate.render({ + project: project, + location: location, + workflow: workflow, + subtask: subtask, + }); + } + + /** + * Parse the project from MigrationSubtask resource. + * + * @param {string} migrationSubtaskName + * A fully-qualified path representing MigrationSubtask resource. + * @returns {string} A string representing the project. + */ + matchProjectFromMigrationSubtaskName(migrationSubtaskName: string) { + return this.pathTemplates.migrationSubtaskPathTemplate.match( + migrationSubtaskName + ).project; + } + + /** + * Parse the location from MigrationSubtask resource. + * + * @param {string} migrationSubtaskName + * A fully-qualified path representing MigrationSubtask resource. + * @returns {string} A string representing the location. + */ + matchLocationFromMigrationSubtaskName(migrationSubtaskName: string) { + return this.pathTemplates.migrationSubtaskPathTemplate.match( + migrationSubtaskName + ).location; + } + + /** + * Parse the workflow from MigrationSubtask resource. + * + * @param {string} migrationSubtaskName + * A fully-qualified path representing MigrationSubtask resource. + * @returns {string} A string representing the workflow. + */ + matchWorkflowFromMigrationSubtaskName(migrationSubtaskName: string) { + return this.pathTemplates.migrationSubtaskPathTemplate.match( + migrationSubtaskName + ).workflow; + } + + /** + * Parse the subtask from MigrationSubtask resource. + * + * @param {string} migrationSubtaskName + * A fully-qualified path representing MigrationSubtask resource. + * @returns {string} A string representing the subtask. + */ + matchSubtaskFromMigrationSubtaskName(migrationSubtaskName: string) { + return this.pathTemplates.migrationSubtaskPathTemplate.match( + migrationSubtaskName + ).subtask; + } + + /** + * Return a fully-qualified migrationWorkflow resource name string. + * + * @param {string} project + * @param {string} location + * @param {string} workflow + * @returns {string} Resource name string. + */ + migrationWorkflowPath(project: string, location: string, workflow: string) { + return this.pathTemplates.migrationWorkflowPathTemplate.render({ + project: project, + location: location, + workflow: workflow, + }); + } + + /** + * Parse the project from MigrationWorkflow resource. + * + * @param {string} migrationWorkflowName + * A fully-qualified path representing MigrationWorkflow resource. + * @returns {string} A string representing the project. + */ + matchProjectFromMigrationWorkflowName(migrationWorkflowName: string) { + return this.pathTemplates.migrationWorkflowPathTemplate.match( + migrationWorkflowName + ).project; + } + + /** + * Parse the location from MigrationWorkflow resource. + * + * @param {string} migrationWorkflowName + * A fully-qualified path representing MigrationWorkflow resource. + * @returns {string} A string representing the location. + */ + matchLocationFromMigrationWorkflowName(migrationWorkflowName: string) { + return this.pathTemplates.migrationWorkflowPathTemplate.match( + migrationWorkflowName + ).location; + } + + /** + * Parse the workflow from MigrationWorkflow resource. + * + * @param {string} migrationWorkflowName + * A fully-qualified path representing MigrationWorkflow resource. + * @returns {string} A string representing the workflow. + */ + matchWorkflowFromMigrationWorkflowName(migrationWorkflowName: string) { + return this.pathTemplates.migrationWorkflowPathTemplate.match( + migrationWorkflowName + ).workflow; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.sqlTranslationServiceStub && !this._terminated) { + return this.sqlTranslationServiceStub.then(stub => { + this._terminated = true; + stub.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client_config.json b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client_config.json new file mode 100644 index 00000000000..8c186d79da3 --- /dev/null +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_client_config.json @@ -0,0 +1,30 @@ +{ + "interfaces": { + "google.cloud.bigquery.migration.v2alpha.SqlTranslationService": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "TranslateQuery": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_proto_list.json b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_proto_list.json new file mode 100644 index 00000000000..fdbd5988dca --- /dev/null +++ b/packages/google-cloud-bigquery-migration/src/v2alpha/sql_translation_service_proto_list.json @@ -0,0 +1,9 @@ +[ + "../../protos/google/cloud/bigquery/migration/v2alpha/assessment_task.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/migration_entities.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/migration_error_details.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/migration_metrics.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/migration_service.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/translation_service.proto", + "../../protos/google/cloud/bigquery/migration/v2alpha/translation_task.proto" +] diff --git a/packages/google-cloud-bigquery-migration/test/gapic_sql_translation_service_v2alpha.ts b/packages/google-cloud-bigquery-migration/test/gapic_sql_translation_service_v2alpha.ts new file mode 100644 index 00000000000..a67a6ed272a --- /dev/null +++ b/packages/google-cloud-bigquery-migration/test/gapic_sql_translation_service_v2alpha.ts @@ -0,0 +1,519 @@ +// Copyright 2023 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as sqltranslationserviceModule from '../src'; + +import {protobuf} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = ( + instance.constructor as typeof protobuf.Message + ).toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +describe('v2alpha.SqlTranslationServiceClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient + .servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = + sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTranslationServiceStub, undefined); + await client.initialize(); + assert(client.sqlTranslationServiceStub); + }); + + it('has close method for the initialized client', done => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.sqlTranslationServiceStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTranslationServiceStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + }); + + describe('translateQuery', () => { + it('invokes translateQuery without error', async () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse() + ); + client.innerApiCalls.translateQuery = stubSimpleCall(expectedResponse); + const [response] = await client.translateQuery(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes translateQuery without error using callback', async () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryResponse() + ); + client.innerApiCalls.translateQuery = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.translateQuery( + request, + ( + err?: Error | null, + result?: protos.google.cloud.bigquery.migration.v2alpha.ITranslateQueryResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes translateQuery with error', async () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.translateQuery = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(client.translateQuery(request), expectedError); + const actualRequest = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateQuery as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes translateQuery with closed client', async () => { + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.migration.v2alpha.TranslateQueryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.translateQuery(request), expectedError); + }); + }); + + describe('Path templates', () => { + describe('location', () => { + const fakePath = '/rendered/path/location'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + }; + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.locationPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.locationPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('locationPath', () => { + const result = client.locationPath('projectValue', 'locationValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.locationPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromLocationName', () => { + const result = client.matchProjectFromLocationName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromLocationName', () => { + const result = client.matchLocationFromLocationName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('migrationSubtask', () => { + const fakePath = '/rendered/path/migrationSubtask'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + workflow: 'workflowValue', + subtask: 'subtaskValue', + }; + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.migrationSubtaskPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.migrationSubtaskPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('migrationSubtaskPath', () => { + const result = client.migrationSubtaskPath( + 'projectValue', + 'locationValue', + 'workflowValue', + 'subtaskValue' + ); + assert.strictEqual(result, fakePath); + assert( + ( + client.pathTemplates.migrationSubtaskPathTemplate + .render as SinonStub + ) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromMigrationSubtaskName', () => { + const result = client.matchProjectFromMigrationSubtaskName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.migrationSubtaskPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromMigrationSubtaskName', () => { + const result = client.matchLocationFromMigrationSubtaskName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.migrationSubtaskPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchWorkflowFromMigrationSubtaskName', () => { + const result = client.matchWorkflowFromMigrationSubtaskName(fakePath); + assert.strictEqual(result, 'workflowValue'); + assert( + (client.pathTemplates.migrationSubtaskPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchSubtaskFromMigrationSubtaskName', () => { + const result = client.matchSubtaskFromMigrationSubtaskName(fakePath); + assert.strictEqual(result, 'subtaskValue'); + assert( + (client.pathTemplates.migrationSubtaskPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('migrationWorkflow', () => { + const fakePath = '/rendered/path/migrationWorkflow'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + workflow: 'workflowValue', + }; + const client = + new sqltranslationserviceModule.v2alpha.SqlTranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.migrationWorkflowPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.migrationWorkflowPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('migrationWorkflowPath', () => { + const result = client.migrationWorkflowPath( + 'projectValue', + 'locationValue', + 'workflowValue' + ); + assert.strictEqual(result, fakePath); + assert( + ( + client.pathTemplates.migrationWorkflowPathTemplate + .render as SinonStub + ) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromMigrationWorkflowName', () => { + const result = client.matchProjectFromMigrationWorkflowName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + ( + client.pathTemplates.migrationWorkflowPathTemplate + .match as SinonStub + ) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromMigrationWorkflowName', () => { + const result = client.matchLocationFromMigrationWorkflowName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + ( + client.pathTemplates.migrationWorkflowPathTemplate + .match as SinonStub + ) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchWorkflowFromMigrationWorkflowName', () => { + const result = client.matchWorkflowFromMigrationWorkflowName(fakePath); + assert.strictEqual(result, 'workflowValue'); + assert( + ( + client.pathTemplates.migrationWorkflowPathTemplate + .match as SinonStub + ) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +});