From 97a4451e60730fa282522f0ffc42ea93e8afdc96 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 12 Mar 2019 11:01:22 -0700 Subject: [PATCH 1/8] Generate protos for Models API. (#488) * Generate protos for Models API. The Models API is a component of the bigquery_v2 interface. It is not available as a gRPC API, but it does provide protocol buffers. This commit adds those protocol buffers to the client so that they can be used to avoid much manual work to create resource classes that can be serialized to/from JSON. --- bigquery/LICENSE | 7 +- bigquery/MANIFEST.in | 4 +- bigquery/docs/gapic/v2/types.rst | 5 + bigquery/docs/reference.rst | 12 +- bigquery/google/__init__.py | 6 +- bigquery/google/cloud/__init__.py | 6 +- .../cloud/bigquery_v2/gapic/__init__.py | 0 .../google/cloud/bigquery_v2/gapic/enums.py | 121 + .../cloud/bigquery_v2/proto/__init__.py | 0 .../bigquery_v2/proto/location_metadata.proto | 34 + .../proto/location_metadata_pb2.py | 98 + .../proto/location_metadata_pb2_grpc.py | 2 + .../cloud/bigquery_v2/proto/model.proto | 465 +++ .../cloud/bigquery_v2/proto/model_pb2.py | 3012 +++++++++++++++++ .../cloud/bigquery_v2/proto/model_pb2_grpc.py | 102 + .../bigquery_v2/proto/model_reference.proto | 39 + .../bigquery_v2/proto/model_reference_pb2.py | 137 + .../proto/model_reference_pb2_grpc.py | 2 + .../bigquery_v2/proto/standard_sql.proto | 110 + .../bigquery_v2/proto/standard_sql_pb2.py | 365 ++ .../proto/standard_sql_pb2_grpc.py | 2 + bigquery/google/cloud/bigquery_v2/types.py | 50 + bigquery/synth.metadata | 24 + bigquery/synth.py | 50 + 24 files changed, 4643 insertions(+), 10 deletions(-) create mode 100644 bigquery/docs/gapic/v2/types.rst create mode 100644 bigquery/google/cloud/bigquery_v2/gapic/__init__.py create mode 100644 bigquery/google/cloud/bigquery_v2/gapic/enums.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/__init__.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/location_metadata.proto create mode 100644 bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2_grpc.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model.proto create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model_pb2.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model_pb2_grpc.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model_reference.proto create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2_grpc.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/standard_sql.proto create mode 100644 bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2.py create mode 100644 bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2_grpc.py create mode 100644 bigquery/google/cloud/bigquery_v2/types.py create mode 100644 bigquery/synth.metadata create mode 100644 bigquery/synth.py diff --git a/bigquery/LICENSE b/bigquery/LICENSE index d64569567334..a8ee855de2aa 100644 --- a/bigquery/LICENSE +++ b/bigquery/LICENSE @@ -1,7 +1,6 @@ - - Apache License + Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +192,7 @@ 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 + 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, diff --git a/bigquery/MANIFEST.in b/bigquery/MANIFEST.in index 1fbc0d0b321e..9cbf175afe6b 100644 --- a/bigquery/MANIFEST.in +++ b/bigquery/MANIFEST.in @@ -1,3 +1,5 @@ include README.rst LICENSE +recursive-include google *.json *.proto recursive-include tests * -global-exclude *.pyc __pycache__ +global-exclude *.py[co] +global-exclude __pycache__ diff --git a/bigquery/docs/gapic/v2/types.rst b/bigquery/docs/gapic/v2/types.rst new file mode 100644 index 000000000000..97938768a690 --- /dev/null +++ b/bigquery/docs/gapic/v2/types.rst @@ -0,0 +1,5 @@ +Types for BigQuery API Client +============================= + +.. automodule:: google.cloud.bigquery_v2.types + :members: \ No newline at end of file diff --git a/bigquery/docs/reference.rst b/bigquery/docs/reference.rst index 6676c6f0128f..c9abc0208ed1 100644 --- a/bigquery/docs/reference.rst +++ b/bigquery/docs/reference.rst @@ -139,9 +139,19 @@ External Configuration Magics -====================== +====== .. toctree:: :maxdepth: 2 magics + +Additional Types +================ + +Protocol buffer classes for working with the Models API. + +.. toctree:: + :maxdepth: 2 + + gapic/v2/types diff --git a/bigquery/google/__init__.py b/bigquery/google/__init__.py index 0e1bc5131ba6..8fcc60e2b9c6 100644 --- a/bigquery/google/__init__.py +++ b/bigquery/google/__init__.py @@ -1,10 +1,12 @@ -# Copyright 2016 Google LLC +# -*- coding: utf-8 -*- +# +# Copyright 2019 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 +# 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, diff --git a/bigquery/google/cloud/__init__.py b/bigquery/google/cloud/__init__.py index 0e1bc5131ba6..8fcc60e2b9c6 100644 --- a/bigquery/google/cloud/__init__.py +++ b/bigquery/google/cloud/__init__.py @@ -1,10 +1,12 @@ -# Copyright 2016 Google LLC +# -*- coding: utf-8 -*- +# +# Copyright 2019 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 +# 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, diff --git a/bigquery/google/cloud/bigquery_v2/gapic/__init__.py b/bigquery/google/cloud/bigquery_v2/gapic/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/bigquery/google/cloud/bigquery_v2/gapic/enums.py b/bigquery/google/cloud/bigquery_v2/gapic/enums.py new file mode 100644 index 000000000000..8ffe9f2b9a7a --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/gapic/enums.py @@ -0,0 +1,121 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 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. +"""Wrappers for protocol buffer enum types.""" + +import enum + + +class Model(object): + class DataSplitMethod(enum.IntEnum): + """ + Indicates the method to split input data into multiple tables. + + Attributes: + DATA_SPLIT_METHOD_UNSPECIFIED (int) + RANDOM (int): Splits data randomly. + CUSTOM (int): Splits data with the user provided tags. + SEQUENTIAL (int): Splits data sequentially. + NO_SPLIT (int): Data split will be skipped. + AUTO_SPLIT (int): Splits data automatically: Uses NO\_SPLIT if the data size is small. + Otherwise uses RANDOM. + """ + + DATA_SPLIT_METHOD_UNSPECIFIED = 0 + RANDOM = 1 + CUSTOM = 2 + SEQUENTIAL = 3 + NO_SPLIT = 4 + AUTO_SPLIT = 5 + + class LearnRateStrategy(enum.IntEnum): + """ + Indicates the learning rate optimization strategy to use. + + Attributes: + LEARN_RATE_STRATEGY_UNSPECIFIED (int) + LINE_SEARCH (int): Use line search to determine learning rate. + CONSTANT (int): Use a constant learning rate. + """ + + LEARN_RATE_STRATEGY_UNSPECIFIED = 0 + LINE_SEARCH = 1 + CONSTANT = 2 + + class LossType(enum.IntEnum): + """ + Loss metric to evaluate model training performance. + + Attributes: + LOSS_TYPE_UNSPECIFIED (int) + MEAN_SQUARED_LOSS (int): Mean squared loss, used for linear regression. + MEAN_LOG_LOSS (int): Mean log loss, used for logistic regression. + """ + + LOSS_TYPE_UNSPECIFIED = 0 + MEAN_SQUARED_LOSS = 1 + MEAN_LOG_LOSS = 2 + + class ModelType(enum.IntEnum): + """ + Indicates the type of the Model. + + Attributes: + MODEL_TYPE_UNSPECIFIED (int) + LINEAR_REGRESSION (int): Linear regression model. + LOGISTIC_REGRESSION (int): Logistic regression model. + """ + + MODEL_TYPE_UNSPECIFIED = 0 + LINEAR_REGRESSION = 1 + LOGISTIC_REGRESSION = 2 + + +class StandardSqlDataType(object): + class TypeKind(enum.IntEnum): + """ + Attributes: + TYPE_KIND_UNSPECIFIED (int): Invalid type. + INT64 (int): Encoded as a string in decimal format. + BOOL (int): Encoded as a boolean "false" or "true". + FLOAT64 (int): Encoded as a number, or string "NaN", "Infinity" or "-Infinity". + STRING (int): Encoded as a string value. + BYTES (int): Encoded as a base64 string per RFC 4648, section 4. + TIMESTAMP (int): Encoded as an RFC 3339 timestamp with mandatory "Z" time zone string: + 1985-04-12T23:20:50.52Z + DATE (int): Encoded as RFC 3339 full-date format string: 1985-04-12 + TIME (int): Encoded as RFC 3339 partial-time format string: 23:20:50.52 + DATETIME (int): Encoded as RFC 3339 full-date "T" partial-time: 1985-04-12T23:20:50.52 + GEOGRAPHY (int): Encoded as WKT + NUMERIC (int): Encoded as a decimal string. + ARRAY (int): Encoded as a list with types matching Type.array\_type. + STRUCT (int): Encoded as a list with fields of type Type.struct\_type[i]. List is used + because a JSON object cannot have duplicate field names. + """ + + TYPE_KIND_UNSPECIFIED = 0 + INT64 = 2 + BOOL = 5 + FLOAT64 = 7 + STRING = 8 + BYTES = 9 + TIMESTAMP = 19 + DATE = 10 + TIME = 20 + DATETIME = 21 + GEOGRAPHY = 22 + NUMERIC = 23 + ARRAY = 16 + STRUCT = 17 diff --git a/bigquery/google/cloud/bigquery_v2/proto/__init__.py b/bigquery/google/cloud/bigquery_v2/proto/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/bigquery/google/cloud/bigquery_v2/proto/location_metadata.proto b/bigquery/google/cloud/bigquery_v2/proto/location_metadata.proto new file mode 100644 index 000000000000..95a3133c5755 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/location_metadata.proto @@ -0,0 +1,34 @@ +// Copyright 2019 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.v2; + +import "google/api/annotations.proto"; + +option go_package = "google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery"; +option java_outer_classname = "LocationMetadataProto"; +option java_package = "com.google.cloud.bigquery.v2"; + + +// BigQuery-specific metadata about a location. This will be set on +// google.cloud.location.Location.metadata in Cloud Location API +// responses. +message LocationMetadata { + // The legacy BigQuery location ID, e.g. “EU” for the “europe” location. + // This is for any API consumers that need the legacy “US” and “EU” locations. + string legacy_location_id = 1; +} diff --git a/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py new file mode 100644 index 000000000000..c1410ddc46d3 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py @@ -0,0 +1,98 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/bigquery_v2/proto/location_metadata.proto + +import sys + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name="google/cloud/bigquery_v2/proto/location_metadata.proto", + package="google.cloud.bigquery.v2", + syntax="proto3", + serialized_options=_b( + "\n\034com.google.cloud.bigquery.v2B\025LocationMetadataProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery" + ), + serialized_pb=_b( + '\n6google/cloud/bigquery_v2/proto/location_metadata.proto\x12\x18google.cloud.bigquery.v2\x1a\x1cgoogle/api/annotations.proto".\n\x10LocationMetadata\x12\x1a\n\x12legacy_location_id\x18\x01 \x01(\tBw\n\x1c\x63om.google.cloud.bigquery.v2B\x15LocationMetadataProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' + ), + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR], +) + + +_LOCATIONMETADATA = _descriptor.Descriptor( + name="LocationMetadata", + full_name="google.cloud.bigquery.v2.LocationMetadata", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="legacy_location_id", + full_name="google.cloud.bigquery.v2.LocationMetadata.legacy_location_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ) + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=114, + serialized_end=160, +) + +DESCRIPTOR.message_types_by_name["LocationMetadata"] = _LOCATIONMETADATA +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +LocationMetadata = _reflection.GeneratedProtocolMessageType( + "LocationMetadata", + (_message.Message,), + dict( + DESCRIPTOR=_LOCATIONMETADATA, + __module__="google.cloud.bigquery_v2.proto.location_metadata_pb2", + __doc__="""BigQuery-specific metadata about a location. This will be set on + google.cloud.location.Location.metadata in Cloud Location API responses. + + + Attributes: + legacy_location_id: + The legacy BigQuery location ID, e.g. “EU” for the “europe” + location. This is for any API consumers that need the legacy + “US” and “EU” locations. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.LocationMetadata) + ), +) +_sym_db.RegisterMessage(LocationMetadata) + + +DESCRIPTOR._options = None +# @@protoc_insertion_point(module_scope) diff --git a/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2_grpc.py b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2_grpc.py new file mode 100644 index 000000000000..07cb78fe03a9 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2_grpc.py @@ -0,0 +1,2 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc diff --git a/bigquery/google/cloud/bigquery_v2/proto/model.proto b/bigquery/google/cloud/bigquery_v2/proto/model.proto new file mode 100644 index 000000000000..6e50f8729a97 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model.proto @@ -0,0 +1,465 @@ +// Copyright 2019 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.v2; + +import "google/cloud/bigquery/v2/model_reference.proto"; +import "google/cloud/bigquery/v2/standard_sql.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/wrappers.proto"; +import "google/api/annotations.proto"; + +option go_package = "google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery"; +option java_outer_classname = "ModelProto"; +option java_package = "com.google.cloud.bigquery.v2"; + + +service ModelService { + // Gets the specified model resource by model ID. + rpc GetModel(GetModelRequest) returns (Model) { + } + + // Lists all models in the specified dataset. Requires the READER dataset + // role. + rpc ListModels(ListModelsRequest) returns (ListModelsResponse) { + } + + // Patch specific fields in the specified model. + rpc PatchModel(PatchModelRequest) returns (Model) { + } + + // Deletes the model specified by modelId from the dataset. + rpc DeleteModel(DeleteModelRequest) returns (google.protobuf.Empty) { + } +} + +message Model { + // Evaluation metrics for regression models. + message RegressionMetrics { + // Mean absolute error. + google.protobuf.DoubleValue mean_absolute_error = 1; + + // Mean squared error. + google.protobuf.DoubleValue mean_squared_error = 2; + + // Mean squared log error. + google.protobuf.DoubleValue mean_squared_log_error = 3; + + // Median absolute error. + google.protobuf.DoubleValue median_absolute_error = 4; + + // R^2 score. + google.protobuf.DoubleValue r_squared = 5; + } + + // Aggregate metrics for classification models. For multi-class models, + // the metrics are either macro-averaged: metrics are calculated for each + // label and then an unweighted average is taken of those values or + // micro-averaged: the metric is calculated globally by counting the total + // number of correctly predicted rows. + message AggregateClassificationMetrics { + // Precision is the fraction of actual positive predictions that had + // positive actual labels. For multiclass this is a macro-averaged + // metric treating each class as a binary classifier. + google.protobuf.DoubleValue precision = 1; + + // Recall is the fraction of actual positive labels that were given a + // positive prediction. For multiclass this is a macro-averaged metric. + google.protobuf.DoubleValue recall = 2; + + // Accuracy is the fraction of predictions given the correct label. For + // multiclass this is a micro-averaged metric. + google.protobuf.DoubleValue accuracy = 3; + + // Threshold at which the metrics are computed. For binary + // classification models this is the positive class threshold. + // For multi-class classfication models this is the confidence + // threshold. + google.protobuf.DoubleValue threshold = 4; + + // The F1 score is an average of recall and precision. For multiclass + // this is a macro-averaged metric. + google.protobuf.DoubleValue f1_score = 5; + + // Logarithmic Loss. For multiclass this is a macro-averaged metric. + google.protobuf.DoubleValue log_loss = 6; + + // Area Under a ROC Curve. For multiclass this is a macro-averaged + // metric. + google.protobuf.DoubleValue roc_auc = 7; + } + + // Evaluation metrics for binary classification models. + message BinaryClassificationMetrics { + // Confusion matrix for binary classification models. + message BinaryConfusionMatrix { + // Threshold value used when computing each of the following metric. + google.protobuf.DoubleValue positive_class_threshold = 1; + + // Number of true samples predicted as true. + google.protobuf.Int64Value true_positives = 2; + + // Number of false samples predicted as true. + google.protobuf.Int64Value false_positives = 3; + + // Number of true samples predicted as false. + google.protobuf.Int64Value true_negatives = 4; + + // Number of false samples predicted as false. + google.protobuf.Int64Value false_negatives = 5; + + // Aggregate precision. + google.protobuf.DoubleValue precision = 6; + + // Aggregate recall. + google.protobuf.DoubleValue recall = 7; + } + + // Aggregate classification metrics. + AggregateClassificationMetrics aggregate_classification_metrics = 1; + + // Binary confusion matrix at multiple thresholds. + repeated BinaryConfusionMatrix binary_confusion_matrix_list = 2; + } + + // Evaluation metrics for multi-class classification models. + message MultiClassClassificationMetrics { + // Confusion matrix for multi-class classification models. + message ConfusionMatrix { + // A single entry in the confusion matrix. + message Entry { + // The predicted label. For confidence_threshold > 0, we will + // also add an entry indicating the number of items under the + // confidence threshold. + string predicted_label = 1; + + // Number of items being predicted as this label. + google.protobuf.Int64Value item_count = 2; + } + + // A single row in the confusion matrix. + message Row { + // The original label of this row. + string actual_label = 1; + + // Info describing predicted label distribution. + repeated Entry entries = 2; + } + + // Confidence threshold used when computing the entries of the + // confusion matrix. + google.protobuf.DoubleValue confidence_threshold = 1; + + // One row per actual label. + repeated Row rows = 2; + } + + // Aggregate classification metrics. + AggregateClassificationMetrics aggregate_classification_metrics = 1; + + // Confusion matrix at different thresholds. + repeated ConfusionMatrix confusion_matrix_list = 2; + } + + // Evaluation metrics of a model. These are either computed on all + // training data or just the eval data based on whether eval data was used + // during training. + message EvaluationMetrics { + oneof metrics { + // Populated for regression models. + RegressionMetrics regression_metrics = 1; + + // Populated for binary classification models. + BinaryClassificationMetrics binary_classification_metrics = 2; + + // Populated for multi-class classification models. + MultiClassClassificationMetrics multi_class_classification_metrics = 3; + } + } + + // Information about a single training query run for the model. + message TrainingRun { + message TrainingOptions { + // The maximum number of iterations in training. + int64 max_iterations = 1; + + // Type of loss function used during training run. + LossType loss_type = 2; + + // Learning rate in training. + double learn_rate = 3; + + // L1 regularization coefficient. + google.protobuf.DoubleValue l1_regularization = 4; + + // L2 regularization coefficient. + google.protobuf.DoubleValue l2_regularization = 5; + + // When early_stop is true, stops training when accuracy improvement is + // less than 'min_relative_progress'. + google.protobuf.DoubleValue min_relative_progress = 6; + + // Whether to train a model from the last checkpoint. + google.protobuf.BoolValue warm_start = 7; + + // Whether to stop early when the loss doesn't improve significantly + // any more (compared to min_relative_progress). + google.protobuf.BoolValue early_stop = 8; + + // Name of input label columns in training data. + repeated string input_label_columns = 9; + + // The data split type for training and evaluation, e.g. RANDOM. + DataSplitMethod data_split_method = 10; + + // The fraction of evaluation data over the whole input data. The rest + // of data will be used as training data. The format should be double. + // Accurate to two decimal places. + // Default value is 0.2. + double data_split_eval_fraction = 11; + + // The column to split data with. This column won't be used as a + // feature. + // 1. When data_split_method is CUSTOM, the corresponding column should + // be boolean. The rows with true value tag are eval data, and the false + // are training data. + // 2. When data_split_method is SEQ, the first DATA_SPLIT_EVAL_FRACTION + // rows (from smallest to largest) in the corresponding column are used + // as training data, and the rest are eval data. It respects the order + // in Orderable data types: + // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#data-type-properties + string data_split_column = 12; + + // The strategy to determine learning rate. + LearnRateStrategy learn_rate_strategy = 13; + + // Specifies the initial learning rate for line search to start at. + double initial_learn_rate = 16; + + // Weights associated with each label class, for rebalancing the + // training data. + map label_class_weights = 17; + } + + // Information about a single iteration of the training run. + message IterationResult { + // Index of the iteration, 0 based. + google.protobuf.Int32Value index = 1; + + // Time taken to run the iteration in milliseconds. + google.protobuf.Int64Value duration_ms = 4; + + // Loss computed on the training data at the end of iteration. + google.protobuf.DoubleValue training_loss = 5; + + // Loss computed on the eval data at the end of iteration. + google.protobuf.DoubleValue eval_loss = 6; + + // Learn rate used for this iteration. + double learn_rate = 7; + } + + // Options that were used for this training run, includes + // user specified and default options that were used. + TrainingOptions training_options = 1; + + // The start time of this training run, in milliseconds since epoch. + int64 start_time = 2; + + // Output of each iteration run, results.size() <= max_iterations. + repeated IterationResult results = 6; + + // The evaluation metrics over training/eval data that were computed at the + // end of training. + EvaluationMetrics evaluation_metrics = 7; + } + + // Indicates the type of the Model. + enum ModelType { + MODEL_TYPE_UNSPECIFIED = 0; + + // Linear regression model. + LINEAR_REGRESSION = 1; + + // Logistic regression model. + LOGISTIC_REGRESSION = 2; + } + + // Loss metric to evaluate model training performance. + enum LossType { + LOSS_TYPE_UNSPECIFIED = 0; + + // Mean squared loss, used for linear regression. + MEAN_SQUARED_LOSS = 1; + + // Mean log loss, used for logistic regression. + MEAN_LOG_LOSS = 2; + } + + // Indicates the method to split input data into multiple tables. + enum DataSplitMethod { + DATA_SPLIT_METHOD_UNSPECIFIED = 0; + + // Splits data randomly. + RANDOM = 1; + + // Splits data with the user provided tags. + CUSTOM = 2; + + // Splits data sequentially. + SEQUENTIAL = 3; + + // Data split will be skipped. + NO_SPLIT = 4; + + // Splits data automatically: Uses NO_SPLIT if the data size is small. + // Otherwise uses RANDOM. + AUTO_SPLIT = 5; + } + + // Indicates the learning rate optimization strategy to use. + enum LearnRateStrategy { + LEARN_RATE_STRATEGY_UNSPECIFIED = 0; + + // Use line search to determine learning rate. + LINE_SEARCH = 1; + + // Use a constant learning rate. + CONSTANT = 2; + } + + // Output only. A hash of this resource. + string etag = 1; + + // Required. Unique identifier for this model. + ModelReference model_reference = 2; + + // Output only. The time when this model was created, in millisecs since the + // epoch. + int64 creation_time = 5; + + // Output only. The time when this model was last modified, in millisecs + // since the epoch. + int64 last_modified_time = 6; + + // [Optional] A user-friendly description of this model. + // @mutable bigquery.models.patch + string description = 12; + + // [Optional] A descriptive name for this model. + // @mutable bigquery.models.patch + string friendly_name = 14; + + // [Optional] The labels associated with this model. You can use these to + // organize and group your models. Label keys and values can be no longer + // than 63 characters, can only contain lowercase letters, numeric + // characters, underscores and dashes. International characters are allowed. + // Label values are optional. Label keys must start with a letter and each + // label in the list must have a different key. + // @mutable bigquery.models.patch + map labels = 15; + + // [Optional] The time when this model expires, in milliseconds since the + // epoch. If not present, the model will persist indefinitely. Expired models + // will be deleted and their storage reclaimed. The defaultTableExpirationMs + // property of the encapsulating dataset can be used to set a default + // expirationTime on newly created models. + // @mutable bigquery.models.patch + int64 expiration_time = 16; + + // Output only. The geographic location where the model resides. This value + // is inherited from the dataset. + string location = 13; + + // Output only. Type of the model resource. + ModelType model_type = 7; + + // Output only. Information for all training runs in increasing order of + // start_time. + repeated TrainingRun training_runs = 9; + + // Output only. Input feature columns that were used to train this model. + repeated StandardSqlField feature_columns = 10; + + // Output only. Label columns that were used to train this model. + // The output of the model will have a “predicted_” prefix to these columns. + repeated StandardSqlField label_columns = 11; +} + +message GetModelRequest { + // Project ID of the requested model. + string project_id = 1; + + // Dataset ID of the requested model. + string dataset_id = 2; + + // Model ID of the requested model. + string model_id = 3; +} + +message PatchModelRequest { + // Project ID of the model to patch + string project_id = 1; + + // Dataset ID of the model to patch + string dataset_id = 2; + + // Model ID of the model to patch + string model_id = 3; + + // Patched model. + // Follows patch semantics. Missing fields are not updated. To clear a field, + // explicitly set to default value. + Model model = 4; +} + +message DeleteModelRequest { + // Project ID of the requested model. + string project_id = 1; + + // Dataset ID of the requested model. + string dataset_id = 2; + + // Model ID of the requested model. + string model_id = 3; +} + +message ListModelsRequest { + // Project ID of the models to list. + string project_id = 1; + + // Dataset ID of the models to list. + string dataset_id = 2; + + // The maximum number of results per page. + google.protobuf.UInt32Value max_results = 3; + + // Page token, returned by a previous call to request the next page of + // results + string page_token = 4; +} + +message ListModelsResponse { + // Models in the requested dataset. Only the following fields are populated: + // model_reference, model_type, creation_time, last_modified_time and + // labels. + repeated Model models = 1; + + // A token to request the next page of results. + string next_page_token = 2; +} diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py new file mode 100644 index 000000000000..768a974ba08d --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py @@ -0,0 +1,3012 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/bigquery_v2/proto/model.proto + +import sys + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.cloud.bigquery_v2.proto import ( + model_reference_pb2 as google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__reference__pb2, +) +from google.cloud.bigquery_v2.proto import ( + standard_sql_pb2 as google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2, +) +from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 +from google.protobuf import field_mask_pb2 as google_dot_protobuf_dot_field__mask__pb2 +from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2 +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name="google/cloud/bigquery_v2/proto/model.proto", + package="google.cloud.bigquery.v2", + syntax="proto3", + serialized_options=_b( + "\n\034com.google.cloud.bigquery.v2B\nModelProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery" + ), + serialized_pb=_b( + '\n*google/cloud/bigquery_v2/proto/model.proto\x12\x18google.cloud.bigquery.v2\x1a\x34google/cloud/bigquery_v2/proto/model_reference.proto\x1a\x31google/cloud/bigquery_v2/proto/standard_sql.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/api/annotations.proto"\xb1$\n\x05Model\x12\x0c\n\x04\x65tag\x18\x01 \x01(\t\x12\x41\n\x0fmodel_reference\x18\x02 \x01(\x0b\x32(.google.cloud.bigquery.v2.ModelReference\x12\x15\n\rcreation_time\x18\x05 \x01(\x03\x12\x1a\n\x12last_modified_time\x18\x06 \x01(\x03\x12\x13\n\x0b\x64\x65scription\x18\x0c \x01(\t\x12\x15\n\rfriendly_name\x18\x0e \x01(\t\x12;\n\x06labels\x18\x0f \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.LabelsEntry\x12\x17\n\x0f\x65xpiration_time\x18\x10 \x01(\x03\x12\x10\n\x08location\x18\r \x01(\t\x12=\n\nmodel_type\x18\x07 \x01(\x0e\x32).google.cloud.bigquery.v2.Model.ModelType\x12\x42\n\rtraining_runs\x18\t \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.TrainingRun\x12\x43\n\x0f\x66\x65\x61ture_columns\x18\n \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x12\x41\n\rlabel_columns\x18\x0b \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x1a\xb4\x02\n\x11RegressionMetrics\x12\x39\n\x13mean_absolute_error\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x38\n\x12mean_squared_error\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12<\n\x16mean_squared_log_error\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15median_absolute_error\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tr_squared\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\xef\x02\n\x1e\x41ggregateClassificationMetrics\x12/\n\tprecision\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x61\x63\x63uracy\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tthreshold\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x66\x31_score\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08log_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12-\n\x07roc_auc\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x8f\x05\n\x1b\x42inaryClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12w\n\x1c\x62inary_confusion_matrix_list\x18\x02 \x03(\x0b\x32Q.google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix\x1a\x8c\x03\n\x15\x42inaryConfusionMatrix\x12>\n\x18positive_class_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x33\n\x0etrue_positives\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_positives\x18\x03 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\x0etrue_negatives\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_negatives\x18\x05 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12/\n\tprecision\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x87\x05\n\x1fMultiClassClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12n\n\x15\x63onfusion_matrix_list\x18\x02 \x03(\x0b\x32O.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix\x1a\x89\x03\n\x0f\x43onfusionMatrix\x12:\n\x14\x63onfidence_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x61\n\x04rows\x18\x02 \x03(\x0b\x32S.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row\x1aQ\n\x05\x45ntry\x12\x17\n\x0fpredicted_label\x18\x01 \x01(\t\x12/\n\nitem_count\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x1a\x83\x01\n\x03Row\x12\x14\n\x0c\x61\x63tual_label\x18\x01 \x01(\t\x12\x66\n\x07\x65ntries\x18\x02 \x03(\x0b\x32U.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry\x1a\xc4\x02\n\x11\x45valuationMetrics\x12O\n\x12regression_metrics\x18\x01 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.RegressionMetricsH\x00\x12\x64\n\x1d\x62inary_classification_metrics\x18\x02 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.BinaryClassificationMetricsH\x00\x12m\n"multi_class_classification_metrics\x18\x03 \x01(\x0b\x32?.google.cloud.bigquery.v2.Model.MultiClassClassificationMetricsH\x00\x42\t\n\x07metrics\x1a\xca\n\n\x0bTrainingRun\x12U\n\x10training_options\x18\x01 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions\x12\x12\n\nstart_time\x18\x02 \x01(\x03\x12L\n\x07results\x18\x06 \x03(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.IterationResult\x12M\n\x12\x65valuation_metrics\x18\x07 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.EvaluationMetrics\x1a\xc6\x06\n\x0fTrainingOptions\x12\x16\n\x0emax_iterations\x18\x01 \x01(\x03\x12;\n\tloss_type\x18\x02 \x01(\x0e\x32(.google.cloud.bigquery.v2.Model.LossType\x12\x12\n\nlearn_rate\x18\x03 \x01(\x01\x12\x37\n\x11l1_regularization\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x37\n\x11l2_regularization\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15min_relative_progress\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\nwarm_start\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12.\n\nearly_stop\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x1b\n\x13input_label_columns\x18\t \x03(\t\x12J\n\x11\x64\x61ta_split_method\x18\n \x01(\x0e\x32/.google.cloud.bigquery.v2.Model.DataSplitMethod\x12 \n\x18\x64\x61ta_split_eval_fraction\x18\x0b \x01(\x01\x12\x19\n\x11\x64\x61ta_split_column\x18\x0c \x01(\t\x12N\n\x13learn_rate_strategy\x18\r \x01(\x0e\x32\x31.google.cloud.bigquery.v2.Model.LearnRateStrategy\x12\x1a\n\x12initial_learn_rate\x18\x10 \x01(\x01\x12o\n\x13label_class_weights\x18\x11 \x03(\x0b\x32R.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry\x1a\x38\n\x16LabelClassWeightsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\x1a\xe9\x01\n\x0fIterationResult\x12*\n\x05index\x18\x01 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x30\n\x0b\x64uration_ms\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\rtraining_loss\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\teval_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x12\n\nlearn_rate\x18\x07 \x01(\x01\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01"W\n\tModelType\x12\x1a\n\x16MODEL_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11LINEAR_REGRESSION\x10\x01\x12\x17\n\x13LOGISTIC_REGRESSION\x10\x02"O\n\x08LossType\x12\x19\n\x15LOSS_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11MEAN_SQUARED_LOSS\x10\x01\x12\x11\n\rMEAN_LOG_LOSS\x10\x02"z\n\x0f\x44\x61taSplitMethod\x12!\n\x1d\x44\x41TA_SPLIT_METHOD_UNSPECIFIED\x10\x00\x12\n\n\x06RANDOM\x10\x01\x12\n\n\x06\x43USTOM\x10\x02\x12\x0e\n\nSEQUENTIAL\x10\x03\x12\x0c\n\x08NO_SPLIT\x10\x04\x12\x0e\n\nAUTO_SPLIT\x10\x05"W\n\x11LearnRateStrategy\x12#\n\x1fLEARN_RATE_STRATEGY_UNSPECIFIED\x10\x00\x12\x0f\n\x0bLINE_SEARCH\x10\x01\x12\x0c\n\x08\x43ONSTANT\x10\x02"K\n\x0fGetModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"}\n\x11PatchModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t\x12.\n\x05model\x18\x04 \x01(\x0b\x32\x1f.google.cloud.bigquery.v2.Model"N\n\x12\x44\x65leteModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"\x82\x01\n\x11ListModelsRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x31\n\x0bmax_results\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt32Value\x12\x12\n\npage_token\x18\x04 \x01(\t"^\n\x12ListModelsResponse\x12/\n\x06models\x18\x01 \x03(\x0b\x32\x1f.google.cloud.bigquery.v2.Model\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t2\x88\x03\n\x0cModelService\x12X\n\x08GetModel\x12).google.cloud.bigquery.v2.GetModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12i\n\nListModels\x12+.google.cloud.bigquery.v2.ListModelsRequest\x1a,.google.cloud.bigquery.v2.ListModelsResponse"\x00\x12\\\n\nPatchModel\x12+.google.cloud.bigquery.v2.PatchModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12U\n\x0b\x44\x65leteModel\x12,.google.cloud.bigquery.v2.DeleteModelRequest\x1a\x16.google.protobuf.Empty"\x00\x42l\n\x1c\x63om.google.cloud.bigquery.v2B\nModelProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' + ), + dependencies=[ + google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__reference__pb2.DESCRIPTOR, + google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2.DESCRIPTOR, + google_dot_protobuf_dot_empty__pb2.DESCRIPTOR, + google_dot_protobuf_dot_field__mask__pb2.DESCRIPTOR, + google_dot_protobuf_dot_wrappers__pb2.DESCRIPTOR, + google_dot_api_dot_annotations__pb2.DESCRIPTOR, + ], +) + + +_MODEL_MODELTYPE = _descriptor.EnumDescriptor( + name="ModelType", + full_name="google.cloud.bigquery.v2.Model.ModelType", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="MODEL_TYPE_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="LINEAR_REGRESSION", + index=1, + number=1, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="LOGISTIC_REGRESSION", + index=2, + number=2, + serialized_options=None, + type=None, + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=4579, + serialized_end=4666, +) +_sym_db.RegisterEnumDescriptor(_MODEL_MODELTYPE) + +_MODEL_LOSSTYPE = _descriptor.EnumDescriptor( + name="LossType", + full_name="google.cloud.bigquery.v2.Model.LossType", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="LOSS_TYPE_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="MEAN_SQUARED_LOSS", + index=1, + number=1, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="MEAN_LOG_LOSS", index=2, number=2, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=4668, + serialized_end=4747, +) +_sym_db.RegisterEnumDescriptor(_MODEL_LOSSTYPE) + +_MODEL_DATASPLITMETHOD = _descriptor.EnumDescriptor( + name="DataSplitMethod", + full_name="google.cloud.bigquery.v2.Model.DataSplitMethod", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="DATA_SPLIT_METHOD_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="RANDOM", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="CUSTOM", index=2, number=2, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="SEQUENTIAL", index=3, number=3, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="NO_SPLIT", index=4, number=4, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="AUTO_SPLIT", index=5, number=5, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=4749, + serialized_end=4871, +) +_sym_db.RegisterEnumDescriptor(_MODEL_DATASPLITMETHOD) + +_MODEL_LEARNRATESTRATEGY = _descriptor.EnumDescriptor( + name="LearnRateStrategy", + full_name="google.cloud.bigquery.v2.Model.LearnRateStrategy", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="LEARN_RATE_STRATEGY_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="LINE_SEARCH", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="CONSTANT", index=2, number=2, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=4873, + serialized_end=4960, +) +_sym_db.RegisterEnumDescriptor(_MODEL_LEARNRATESTRATEGY) + + +_MODEL_REGRESSIONMETRICS = _descriptor.Descriptor( + name="RegressionMetrics", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="mean_absolute_error", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics.mean_absolute_error", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="mean_squared_error", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics.mean_squared_error", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="mean_squared_log_error", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics.mean_squared_log_error", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="median_absolute_error", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics.median_absolute_error", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="r_squared", + full_name="google.cloud.bigquery.v2.Model.RegressionMetrics.r_squared", + index=4, + number=5, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=860, + serialized_end=1168, +) + +_MODEL_AGGREGATECLASSIFICATIONMETRICS = _descriptor.Descriptor( + name="AggregateClassificationMetrics", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="precision", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.precision", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="recall", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.recall", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="accuracy", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.accuracy", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="threshold", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.threshold", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="f1_score", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.f1_score", + index=4, + number=5, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="log_loss", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.log_loss", + index=5, + number=6, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="roc_auc", + full_name="google.cloud.bigquery.v2.Model.AggregateClassificationMetrics.roc_auc", + index=6, + number=7, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=1171, + serialized_end=1538, +) + +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX = _descriptor.Descriptor( + name="BinaryConfusionMatrix", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="positive_class_threshold", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.positive_class_threshold", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="true_positives", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.true_positives", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="false_positives", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.false_positives", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="true_negatives", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.true_negatives", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="false_negatives", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.false_negatives", + index=4, + number=5, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="precision", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.precision", + index=5, + number=6, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="recall", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix.recall", + index=6, + number=7, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=1800, + serialized_end=2196, +) + +_MODEL_BINARYCLASSIFICATIONMETRICS = _descriptor.Descriptor( + name="BinaryClassificationMetrics", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="aggregate_classification_metrics", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.aggregate_classification_metrics", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="binary_confusion_matrix_list", + full_name="google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.binary_confusion_matrix_list", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=1541, + serialized_end=2196, +) + +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY = _descriptor.Descriptor( + name="Entry", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="predicted_label", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry.predicted_label", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="item_count", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry.item_count", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=2631, + serialized_end=2712, +) + +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW = _descriptor.Descriptor( + name="Row", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="actual_label", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row.actual_label", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="entries", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row.entries", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=2715, + serialized_end=2846, +) + +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX = _descriptor.Descriptor( + name="ConfusionMatrix", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="confidence_threshold", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.confidence_threshold", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="rows", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.rows", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[ + _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY, + _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW, + ], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=2453, + serialized_end=2846, +) + +_MODEL_MULTICLASSCLASSIFICATIONMETRICS = _descriptor.Descriptor( + name="MultiClassClassificationMetrics", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="aggregate_classification_metrics", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.aggregate_classification_metrics", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="confusion_matrix_list", + full_name="google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.confusion_matrix_list", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=2199, + serialized_end=2846, +) + +_MODEL_EVALUATIONMETRICS = _descriptor.Descriptor( + name="EvaluationMetrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="regression_metrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics.regression_metrics", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="binary_classification_metrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics.binary_classification_metrics", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="multi_class_classification_metrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics.multi_class_classification_metrics", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name="metrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics.metrics", + index=0, + containing_type=None, + fields=[], + ) + ], + serialized_start=2849, + serialized_end=3173, +) + +_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY = _descriptor.Descriptor( + name="LabelClassWeightsEntry", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="key", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry.key", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="value", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry.value", + index=1, + number=2, + type=1, + cpp_type=5, + label=1, + has_default_value=False, + default_value=float(0), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=_b("8\001"), + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=4238, + serialized_end=4294, +) + +_MODEL_TRAININGRUN_TRAININGOPTIONS = _descriptor.Descriptor( + name="TrainingOptions", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="max_iterations", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.max_iterations", + index=0, + number=1, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="loss_type", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.loss_type", + index=1, + number=2, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="learn_rate", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.learn_rate", + index=2, + number=3, + type=1, + cpp_type=5, + label=1, + has_default_value=False, + default_value=float(0), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="l1_regularization", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.l1_regularization", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="l2_regularization", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.l2_regularization", + index=4, + number=5, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="min_relative_progress", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.min_relative_progress", + index=5, + number=6, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="warm_start", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.warm_start", + index=6, + number=7, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="early_stop", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.early_stop", + index=7, + number=8, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="input_label_columns", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.input_label_columns", + index=8, + number=9, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data_split_method", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.data_split_method", + index=9, + number=10, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data_split_eval_fraction", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.data_split_eval_fraction", + index=10, + number=11, + type=1, + cpp_type=5, + label=1, + has_default_value=False, + default_value=float(0), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data_split_column", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.data_split_column", + index=11, + number=12, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="learn_rate_strategy", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.learn_rate_strategy", + index=12, + number=13, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="initial_learn_rate", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.initial_learn_rate", + index=13, + number=16, + type=1, + cpp_type=5, + label=1, + has_default_value=False, + default_value=float(0), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="label_class_weights", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.label_class_weights", + index=14, + number=17, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=3456, + serialized_end=4294, +) + +_MODEL_TRAININGRUN_ITERATIONRESULT = _descriptor.Descriptor( + name="IterationResult", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="index", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.index", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="duration_ms", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.duration_ms", + index=1, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="training_loss", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.training_loss", + index=2, + number=5, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="eval_loss", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.eval_loss", + index=3, + number=6, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="learn_rate", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.learn_rate", + index=4, + number=7, + type=1, + cpp_type=5, + label=1, + has_default_value=False, + default_value=float(0), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=4297, + serialized_end=4530, +) + +_MODEL_TRAININGRUN = _descriptor.Descriptor( + name="TrainingRun", + full_name="google.cloud.bigquery.v2.Model.TrainingRun", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="training_options", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.training_options", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="start_time", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.start_time", + index=1, + number=2, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="results", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.results", + index=2, + number=6, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="evaluation_metrics", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.evaluation_metrics", + index=3, + number=7, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[ + _MODEL_TRAININGRUN_TRAININGOPTIONS, + _MODEL_TRAININGRUN_ITERATIONRESULT, + ], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=3176, + serialized_end=4530, +) + +_MODEL_LABELSENTRY = _descriptor.Descriptor( + name="LabelsEntry", + full_name="google.cloud.bigquery.v2.Model.LabelsEntry", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="key", + full_name="google.cloud.bigquery.v2.Model.LabelsEntry.key", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="value", + full_name="google.cloud.bigquery.v2.Model.LabelsEntry.value", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=_b("8\001"), + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=4532, + serialized_end=4577, +) + +_MODEL = _descriptor.Descriptor( + name="Model", + full_name="google.cloud.bigquery.v2.Model", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="etag", + full_name="google.cloud.bigquery.v2.Model.etag", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_reference", + full_name="google.cloud.bigquery.v2.Model.model_reference", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="creation_time", + full_name="google.cloud.bigquery.v2.Model.creation_time", + index=2, + number=5, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="last_modified_time", + full_name="google.cloud.bigquery.v2.Model.last_modified_time", + index=3, + number=6, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="description", + full_name="google.cloud.bigquery.v2.Model.description", + index=4, + number=12, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="friendly_name", + full_name="google.cloud.bigquery.v2.Model.friendly_name", + index=5, + number=14, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="labels", + full_name="google.cloud.bigquery.v2.Model.labels", + index=6, + number=15, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="expiration_time", + full_name="google.cloud.bigquery.v2.Model.expiration_time", + index=7, + number=16, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="location", + full_name="google.cloud.bigquery.v2.Model.location", + index=8, + number=13, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_type", + full_name="google.cloud.bigquery.v2.Model.model_type", + index=9, + number=7, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="training_runs", + full_name="google.cloud.bigquery.v2.Model.training_runs", + index=10, + number=9, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="feature_columns", + full_name="google.cloud.bigquery.v2.Model.feature_columns", + index=11, + number=10, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="label_columns", + full_name="google.cloud.bigquery.v2.Model.label_columns", + index=12, + number=11, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[ + _MODEL_REGRESSIONMETRICS, + _MODEL_AGGREGATECLASSIFICATIONMETRICS, + _MODEL_BINARYCLASSIFICATIONMETRICS, + _MODEL_MULTICLASSCLASSIFICATIONMETRICS, + _MODEL_EVALUATIONMETRICS, + _MODEL_TRAININGRUN, + _MODEL_LABELSENTRY, + ], + enum_types=[ + _MODEL_MODELTYPE, + _MODEL_LOSSTYPE, + _MODEL_DATASPLITMETHOD, + _MODEL_LEARNRATESTRATEGY, + ], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=303, + serialized_end=4960, +) + + +_GETMODELREQUEST = _descriptor.Descriptor( + name="GetModelRequest", + full_name="google.cloud.bigquery.v2.GetModelRequest", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="project_id", + full_name="google.cloud.bigquery.v2.GetModelRequest.project_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="dataset_id", + full_name="google.cloud.bigquery.v2.GetModelRequest.dataset_id", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_id", + full_name="google.cloud.bigquery.v2.GetModelRequest.model_id", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=4962, + serialized_end=5037, +) + + +_PATCHMODELREQUEST = _descriptor.Descriptor( + name="PatchModelRequest", + full_name="google.cloud.bigquery.v2.PatchModelRequest", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="project_id", + full_name="google.cloud.bigquery.v2.PatchModelRequest.project_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="dataset_id", + full_name="google.cloud.bigquery.v2.PatchModelRequest.dataset_id", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_id", + full_name="google.cloud.bigquery.v2.PatchModelRequest.model_id", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model", + full_name="google.cloud.bigquery.v2.PatchModelRequest.model", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=5039, + serialized_end=5164, +) + + +_DELETEMODELREQUEST = _descriptor.Descriptor( + name="DeleteModelRequest", + full_name="google.cloud.bigquery.v2.DeleteModelRequest", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="project_id", + full_name="google.cloud.bigquery.v2.DeleteModelRequest.project_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="dataset_id", + full_name="google.cloud.bigquery.v2.DeleteModelRequest.dataset_id", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_id", + full_name="google.cloud.bigquery.v2.DeleteModelRequest.model_id", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=5166, + serialized_end=5244, +) + + +_LISTMODELSREQUEST = _descriptor.Descriptor( + name="ListModelsRequest", + full_name="google.cloud.bigquery.v2.ListModelsRequest", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="project_id", + full_name="google.cloud.bigquery.v2.ListModelsRequest.project_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="dataset_id", + full_name="google.cloud.bigquery.v2.ListModelsRequest.dataset_id", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="max_results", + full_name="google.cloud.bigquery.v2.ListModelsRequest.max_results", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="page_token", + full_name="google.cloud.bigquery.v2.ListModelsRequest.page_token", + index=3, + number=4, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=5247, + serialized_end=5377, +) + + +_LISTMODELSRESPONSE = _descriptor.Descriptor( + name="ListModelsResponse", + full_name="google.cloud.bigquery.v2.ListModelsResponse", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="models", + full_name="google.cloud.bigquery.v2.ListModelsResponse.models", + index=0, + number=1, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="next_page_token", + full_name="google.cloud.bigquery.v2.ListModelsResponse.next_page_token", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=5379, + serialized_end=5473, +) + +_MODEL_REGRESSIONMETRICS.fields_by_name[ + "mean_absolute_error" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_REGRESSIONMETRICS.fields_by_name[ + "mean_squared_error" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_REGRESSIONMETRICS.fields_by_name[ + "mean_squared_log_error" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_REGRESSIONMETRICS.fields_by_name[ + "median_absolute_error" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_REGRESSIONMETRICS.fields_by_name[ + "r_squared" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_REGRESSIONMETRICS.containing_type = _MODEL +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "precision" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "recall" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "accuracy" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "threshold" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "f1_score" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "log_loss" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.fields_by_name[ + "roc_auc" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_AGGREGATECLASSIFICATIONMETRICS.containing_type = _MODEL +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "positive_class_threshold" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "true_positives" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "false_positives" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "true_negatives" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "false_negatives" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "precision" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.fields_by_name[ + "recall" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX.containing_type = ( + _MODEL_BINARYCLASSIFICATIONMETRICS +) +_MODEL_BINARYCLASSIFICATIONMETRICS.fields_by_name[ + "aggregate_classification_metrics" +].message_type = _MODEL_AGGREGATECLASSIFICATIONMETRICS +_MODEL_BINARYCLASSIFICATIONMETRICS.fields_by_name[ + "binary_confusion_matrix_list" +].message_type = _MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX +_MODEL_BINARYCLASSIFICATIONMETRICS.containing_type = _MODEL +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY.fields_by_name[ + "item_count" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY.containing_type = ( + _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX +) +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW.fields_by_name[ + "entries" +].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW.containing_type = ( + _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX +) +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX.fields_by_name[ + "confidence_threshold" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX.fields_by_name[ + "rows" +].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW +_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX.containing_type = ( + _MODEL_MULTICLASSCLASSIFICATIONMETRICS +) +_MODEL_MULTICLASSCLASSIFICATIONMETRICS.fields_by_name[ + "aggregate_classification_metrics" +].message_type = _MODEL_AGGREGATECLASSIFICATIONMETRICS +_MODEL_MULTICLASSCLASSIFICATIONMETRICS.fields_by_name[ + "confusion_matrix_list" +].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX +_MODEL_MULTICLASSCLASSIFICATIONMETRICS.containing_type = _MODEL +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "regression_metrics" +].message_type = _MODEL_REGRESSIONMETRICS +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "binary_classification_metrics" +].message_type = _MODEL_BINARYCLASSIFICATIONMETRICS +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "multi_class_classification_metrics" +].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS +_MODEL_EVALUATIONMETRICS.containing_type = _MODEL +_MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"].fields.append( + _MODEL_EVALUATIONMETRICS.fields_by_name["regression_metrics"] +) +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "regression_metrics" +].containing_oneof = _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"] +_MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"].fields.append( + _MODEL_EVALUATIONMETRICS.fields_by_name["binary_classification_metrics"] +) +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "binary_classification_metrics" +].containing_oneof = _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"] +_MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"].fields.append( + _MODEL_EVALUATIONMETRICS.fields_by_name["multi_class_classification_metrics"] +) +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "multi_class_classification_metrics" +].containing_oneof = _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"] +_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY.containing_type = ( + _MODEL_TRAININGRUN_TRAININGOPTIONS +) +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "loss_type" +].enum_type = _MODEL_LOSSTYPE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "l1_regularization" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "l2_regularization" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "min_relative_progress" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "warm_start" +].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "early_stop" +].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "data_split_method" +].enum_type = _MODEL_DATASPLITMETHOD +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "learn_rate_strategy" +].enum_type = _MODEL_LEARNRATESTRATEGY +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "label_class_weights" +].message_type = _MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY +_MODEL_TRAININGRUN_TRAININGOPTIONS.containing_type = _MODEL_TRAININGRUN +_MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ + "index" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +_MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ + "duration_ms" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ + "training_loss" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ + "eval_loss" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_ITERATIONRESULT.containing_type = _MODEL_TRAININGRUN +_MODEL_TRAININGRUN.fields_by_name[ + "training_options" +].message_type = _MODEL_TRAININGRUN_TRAININGOPTIONS +_MODEL_TRAININGRUN.fields_by_name[ + "results" +].message_type = _MODEL_TRAININGRUN_ITERATIONRESULT +_MODEL_TRAININGRUN.fields_by_name[ + "evaluation_metrics" +].message_type = _MODEL_EVALUATIONMETRICS +_MODEL_TRAININGRUN.containing_type = _MODEL +_MODEL_LABELSENTRY.containing_type = _MODEL +_MODEL.fields_by_name[ + "model_reference" +].message_type = ( + google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__reference__pb2._MODELREFERENCE +) +_MODEL.fields_by_name["labels"].message_type = _MODEL_LABELSENTRY +_MODEL.fields_by_name["model_type"].enum_type = _MODEL_MODELTYPE +_MODEL.fields_by_name["training_runs"].message_type = _MODEL_TRAININGRUN +_MODEL.fields_by_name[ + "feature_columns" +].message_type = ( + google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2._STANDARDSQLFIELD +) +_MODEL.fields_by_name[ + "label_columns" +].message_type = ( + google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2._STANDARDSQLFIELD +) +_MODEL_MODELTYPE.containing_type = _MODEL +_MODEL_LOSSTYPE.containing_type = _MODEL +_MODEL_DATASPLITMETHOD.containing_type = _MODEL +_MODEL_LEARNRATESTRATEGY.containing_type = _MODEL +_PATCHMODELREQUEST.fields_by_name["model"].message_type = _MODEL +_LISTMODELSREQUEST.fields_by_name[ + "max_results" +].message_type = google_dot_protobuf_dot_wrappers__pb2._UINT32VALUE +_LISTMODELSRESPONSE.fields_by_name["models"].message_type = _MODEL +DESCRIPTOR.message_types_by_name["Model"] = _MODEL +DESCRIPTOR.message_types_by_name["GetModelRequest"] = _GETMODELREQUEST +DESCRIPTOR.message_types_by_name["PatchModelRequest"] = _PATCHMODELREQUEST +DESCRIPTOR.message_types_by_name["DeleteModelRequest"] = _DELETEMODELREQUEST +DESCRIPTOR.message_types_by_name["ListModelsRequest"] = _LISTMODELSREQUEST +DESCRIPTOR.message_types_by_name["ListModelsResponse"] = _LISTMODELSRESPONSE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +Model = _reflection.GeneratedProtocolMessageType( + "Model", + (_message.Message,), + dict( + RegressionMetrics=_reflection.GeneratedProtocolMessageType( + "RegressionMetrics", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_REGRESSIONMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Evaluation metrics for regression models. + + + Attributes: + mean_absolute_error: + Mean absolute error. + mean_squared_error: + Mean squared error. + mean_squared_log_error: + Mean squared log error. + median_absolute_error: + Median absolute error. + r_squared: + R^2 score. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.RegressionMetrics) + ), + ), + AggregateClassificationMetrics=_reflection.GeneratedProtocolMessageType( + "AggregateClassificationMetrics", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_AGGREGATECLASSIFICATIONMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Aggregate metrics for classification models. For multi-class models, the + metrics are either macro-averaged: metrics are calculated for each label + and then an unweighted average is taken of those values or + micro-averaged: the metric is calculated globally by counting the total + number of correctly predicted rows. + + + Attributes: + precision: + Precision is the fraction of actual positive predictions that + had positive actual labels. For multiclass this is a macro- + averaged metric treating each class as a binary classifier. + recall: + Recall is the fraction of actual positive labels that were + given a positive prediction. For multiclass this is a macro- + averaged metric. + accuracy: + Accuracy is the fraction of predictions given the correct + label. For multiclass this is a micro-averaged metric. + threshold: + Threshold at which the metrics are computed. For binary + classification models this is the positive class threshold. + For multi-class classfication models this is the confidence + threshold. + f1_score: + The F1 score is an average of recall and precision. For + multiclass this is a macro-averaged metric. + log_loss: + Logarithmic Loss. For multiclass this is a macro-averaged + metric. + roc_auc: + Area Under a ROC Curve. For multiclass this is a macro- + averaged metric. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.AggregateClassificationMetrics) + ), + ), + BinaryClassificationMetrics=_reflection.GeneratedProtocolMessageType( + "BinaryClassificationMetrics", + (_message.Message,), + dict( + BinaryConfusionMatrix=_reflection.GeneratedProtocolMessageType( + "BinaryConfusionMatrix", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Confusion matrix for binary classification models. + + + Attributes: + positive_class_threshold: + Threshold value used when computing each of the following + metric. + true_positives: + Number of true samples predicted as true. + false_positives: + Number of false samples predicted as true. + true_negatives: + Number of true samples predicted as false. + false_negatives: + Number of false samples predicted as false. + precision: + Aggregate precision. + recall: + Aggregate recall. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix) + ), + ), + DESCRIPTOR=_MODEL_BINARYCLASSIFICATIONMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Evaluation metrics for binary classification models. + + + Attributes: + aggregate_classification_metrics: + Aggregate classification metrics. + binary_confusion_matrix_list: + Binary confusion matrix at multiple thresholds. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.BinaryClassificationMetrics) + ), + ), + MultiClassClassificationMetrics=_reflection.GeneratedProtocolMessageType( + "MultiClassClassificationMetrics", + (_message.Message,), + dict( + ConfusionMatrix=_reflection.GeneratedProtocolMessageType( + "ConfusionMatrix", + (_message.Message,), + dict( + Entry=_reflection.GeneratedProtocolMessageType( + "Entry", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""A single entry in the confusion matrix. + + + Attributes: + predicted_label: + The predicted label. For confidence\_threshold > 0, we will + also add an entry indicating the number of items under the + confidence threshold. + item_count: + Number of items being predicted as this label. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry) + ), + ), + Row=_reflection.GeneratedProtocolMessageType( + "Row", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""A single row in the confusion matrix. + + + Attributes: + actual_label: + The original label of this row. + entries: + Info describing predicted label distribution. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row) + ), + ), + DESCRIPTOR=_MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Confusion matrix for multi-class classification models. + + + Attributes: + confidence_threshold: + Confidence threshold used when computing the entries of the + confusion matrix. + rows: + One row per actual label. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix) + ), + ), + DESCRIPTOR=_MODEL_MULTICLASSCLASSIFICATIONMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Evaluation metrics for multi-class classification models. + + + Attributes: + aggregate_classification_metrics: + Aggregate classification metrics. + confusion_matrix_list: + Confusion matrix at different thresholds. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics) + ), + ), + EvaluationMetrics=_reflection.GeneratedProtocolMessageType( + "EvaluationMetrics", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_EVALUATIONMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Evaluation metrics of a model. These are either computed on all training + data or just the eval data based on whether eval data was used during + training. + + + Attributes: + regression_metrics: + Populated for regression models. + binary_classification_metrics: + Populated for binary classification models. + multi_class_classification_metrics: + Populated for multi-class classification models. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.EvaluationMetrics) + ), + ), + TrainingRun=_reflection.GeneratedProtocolMessageType( + "TrainingRun", + (_message.Message,), + dict( + TrainingOptions=_reflection.GeneratedProtocolMessageType( + "TrainingOptions", + (_message.Message,), + dict( + LabelClassWeightsEntry=_reflection.GeneratedProtocolMessageType( + "LabelClassWeightsEntry", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY, + __module__="google.cloud.bigquery_v2.proto.model_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry) + ), + ), + DESCRIPTOR=_MODEL_TRAININGRUN_TRAININGOPTIONS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + max_iterations: + The maximum number of iterations in training. + loss_type: + Type of loss function used during training run. + learn_rate: + Learning rate in training. + l1_regularization: + L1 regularization coefficient. + l2_regularization: + L2 regularization coefficient. + min_relative_progress: + When early\_stop is true, stops training when accuracy + improvement is less than 'min\_relative\_progress'. + warm_start: + Whether to train a model from the last checkpoint. + early_stop: + Whether to stop early when the loss doesn't improve + significantly any more (compared to min\_relative\_progress). + input_label_columns: + Name of input label columns in training data. + data_split_method: + The data split type for training and evaluation, e.g. RANDOM. + data_split_eval_fraction: + The fraction of evaluation data over the whole input data. The + rest of data will be used as training data. The format should + be double. Accurate to two decimal places. Default value is + 0.2. + data_split_column: + The column to split data with. This column won't be used as a + feature. 1. When data\_split\_method is CUSTOM, the + corresponding column should be boolean. The rows with true + value tag are eval data, and the false are training data. 2. + When data\_split\_method is SEQ, the first + DATA\_SPLIT\_EVAL\_FRACTION rows (from smallest to largest) in + the corresponding column are used as training data, and the + rest are eval data. It respects the order in Orderable data + types: + https://cloud.google.com/bigquery/docs/reference/standard- + sql/data-types#data-type-properties + learn_rate_strategy: + The strategy to determine learning rate. + initial_learn_rate: + Specifies the initial learning rate for line search to start + at. + label_class_weights: + Weights associated with each label class, for rebalancing the + training data. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions) + ), + ), + IterationResult=_reflection.GeneratedProtocolMessageType( + "IterationResult", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_TRAININGRUN_ITERATIONRESULT, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Information about a single iteration of the training run. + + + Attributes: + index: + Index of the iteration, 0 based. + duration_ms: + Time taken to run the iteration in milliseconds. + training_loss: + Loss computed on the training data at the end of iteration. + eval_loss: + Loss computed on the eval data at the end of iteration. + learn_rate: + Learn rate used for this iteration. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.IterationResult) + ), + ), + DESCRIPTOR=_MODEL_TRAININGRUN, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Information about a single training query run for the model. + + + Attributes: + training_options: + Options that were used for this training run, includes user + specified and default options that were used. + start_time: + The start time of this training run, in milliseconds since + epoch. + results: + Output of each iteration run, results.size() <= + max\_iterations. + evaluation_metrics: + The evaluation metrics over training/eval data that were + computed at the end of training. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun) + ), + ), + LabelsEntry=_reflection.GeneratedProtocolMessageType( + "LabelsEntry", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_LABELSENTRY, + __module__="google.cloud.bigquery_v2.proto.model_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.LabelsEntry) + ), + ), + DESCRIPTOR=_MODEL, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + etag: + Output only. A hash of this resource. + model_reference: + Required. Unique identifier for this model. + creation_time: + Output only. The time when this model was created, in + millisecs since the epoch. + last_modified_time: + Output only. The time when this model was last modified, in + millisecs since the epoch. + description: + [Optional] A user-friendly description of this model. @mutable + bigquery.models.patch + friendly_name: + [Optional] A descriptive name for this model. @mutable + bigquery.models.patch + labels: + [Optional] The labels associated with this model. You can use + these to organize and group your models. Label keys and values + can be no longer than 63 characters, can only contain + lowercase letters, numeric characters, underscores and dashes. + International characters are allowed. Label values are + optional. Label keys must start with a letter and each label + in the list must have a different key. @mutable + bigquery.models.patch + expiration_time: + [Optional] The time when this model expires, in milliseconds + since the epoch. If not present, the model will persist + indefinitely. Expired models will be deleted and their storage + reclaimed. The defaultTableExpirationMs property of the + encapsulating dataset can be used to set a default + expirationTime on newly created models. @mutable + bigquery.models.patch + location: + Output only. The geographic location where the model resides. + This value is inherited from the dataset. + model_type: + Output only. Type of the model resource. + training_runs: + Output only. Information for all training runs in increasing + order of start\_time. + feature_columns: + Output only. Input feature columns that were used to train + this model. + label_columns: + Output only. Label columns that were used to train this model. + The output of the model will have a “predicted\_” prefix to + these columns. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model) + ), +) +_sym_db.RegisterMessage(Model) +_sym_db.RegisterMessage(Model.RegressionMetrics) +_sym_db.RegisterMessage(Model.AggregateClassificationMetrics) +_sym_db.RegisterMessage(Model.BinaryClassificationMetrics) +_sym_db.RegisterMessage(Model.BinaryClassificationMetrics.BinaryConfusionMatrix) +_sym_db.RegisterMessage(Model.MultiClassClassificationMetrics) +_sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix) +_sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry) +_sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix.Row) +_sym_db.RegisterMessage(Model.EvaluationMetrics) +_sym_db.RegisterMessage(Model.TrainingRun) +_sym_db.RegisterMessage(Model.TrainingRun.TrainingOptions) +_sym_db.RegisterMessage(Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry) +_sym_db.RegisterMessage(Model.TrainingRun.IterationResult) +_sym_db.RegisterMessage(Model.LabelsEntry) + +GetModelRequest = _reflection.GeneratedProtocolMessageType( + "GetModelRequest", + (_message.Message,), + dict( + DESCRIPTOR=_GETMODELREQUEST, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + project_id: + Project ID of the requested model. + dataset_id: + Dataset ID of the requested model. + model_id: + Model ID of the requested model. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.GetModelRequest) + ), +) +_sym_db.RegisterMessage(GetModelRequest) + +PatchModelRequest = _reflection.GeneratedProtocolMessageType( + "PatchModelRequest", + (_message.Message,), + dict( + DESCRIPTOR=_PATCHMODELREQUEST, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + project_id: + Project ID of the model to patch + dataset_id: + Dataset ID of the model to patch + model_id: + Model ID of the model to patch + model: + Patched model. Follows patch semantics. Missing fields are not + updated. To clear a field, explicitly set to default value. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.PatchModelRequest) + ), +) +_sym_db.RegisterMessage(PatchModelRequest) + +DeleteModelRequest = _reflection.GeneratedProtocolMessageType( + "DeleteModelRequest", + (_message.Message,), + dict( + DESCRIPTOR=_DELETEMODELREQUEST, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + project_id: + Project ID of the requested model. + dataset_id: + Dataset ID of the requested model. + model_id: + Model ID of the requested model. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.DeleteModelRequest) + ), +) +_sym_db.RegisterMessage(DeleteModelRequest) + +ListModelsRequest = _reflection.GeneratedProtocolMessageType( + "ListModelsRequest", + (_message.Message,), + dict( + DESCRIPTOR=_LISTMODELSREQUEST, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + project_id: + Project ID of the models to list. + dataset_id: + Dataset ID of the models to list. + max_results: + The maximum number of results per page. + page_token: + Page token, returned by a previous call to request the next + page of results + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.ListModelsRequest) + ), +) +_sym_db.RegisterMessage(ListModelsRequest) + +ListModelsResponse = _reflection.GeneratedProtocolMessageType( + "ListModelsResponse", + (_message.Message,), + dict( + DESCRIPTOR=_LISTMODELSRESPONSE, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Protocol buffer. + + Attributes: + models: + Models in the requested dataset. Only the following fields are + populated: model\_reference, model\_type, creation\_time, + last\_modified\_time and labels. + next_page_token: + A token to request the next page of results. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.ListModelsResponse) + ), +) +_sym_db.RegisterMessage(ListModelsResponse) + + +DESCRIPTOR._options = None +_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY._options = None +_MODEL_LABELSENTRY._options = None + +_MODELSERVICE = _descriptor.ServiceDescriptor( + name="ModelService", + full_name="google.cloud.bigquery.v2.ModelService", + file=DESCRIPTOR, + index=0, + serialized_options=None, + serialized_start=5476, + serialized_end=5868, + methods=[ + _descriptor.MethodDescriptor( + name="GetModel", + full_name="google.cloud.bigquery.v2.ModelService.GetModel", + index=0, + containing_service=None, + input_type=_GETMODELREQUEST, + output_type=_MODEL, + serialized_options=None, + ), + _descriptor.MethodDescriptor( + name="ListModels", + full_name="google.cloud.bigquery.v2.ModelService.ListModels", + index=1, + containing_service=None, + input_type=_LISTMODELSREQUEST, + output_type=_LISTMODELSRESPONSE, + serialized_options=None, + ), + _descriptor.MethodDescriptor( + name="PatchModel", + full_name="google.cloud.bigquery.v2.ModelService.PatchModel", + index=2, + containing_service=None, + input_type=_PATCHMODELREQUEST, + output_type=_MODEL, + serialized_options=None, + ), + _descriptor.MethodDescriptor( + name="DeleteModel", + full_name="google.cloud.bigquery.v2.ModelService.DeleteModel", + index=3, + containing_service=None, + input_type=_DELETEMODELREQUEST, + output_type=google_dot_protobuf_dot_empty__pb2._EMPTY, + serialized_options=None, + ), + ], +) +_sym_db.RegisterServiceDescriptor(_MODELSERVICE) + +DESCRIPTOR.services_by_name["ModelService"] = _MODELSERVICE + +# @@protoc_insertion_point(module_scope) diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_pb2_grpc.py b/bigquery/google/cloud/bigquery_v2/proto/model_pb2_grpc.py new file mode 100644 index 000000000000..5abcdf0f2606 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model_pb2_grpc.py @@ -0,0 +1,102 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + +from google.cloud.bigquery_v2.proto import ( + model_pb2 as google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2, +) +from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 + + +class ModelServiceStub(object): + # missing associated documentation comment in .proto file + pass + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetModel = channel.unary_unary( + "/google.cloud.bigquery.v2.ModelService/GetModel", + request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.GetModelRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.FromString, + ) + self.ListModels = channel.unary_unary( + "/google.cloud.bigquery.v2.ModelService/ListModels", + request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsResponse.FromString, + ) + self.PatchModel = channel.unary_unary( + "/google.cloud.bigquery.v2.ModelService/PatchModel", + request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.PatchModelRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.FromString, + ) + self.DeleteModel = channel.unary_unary( + "/google.cloud.bigquery.v2.ModelService/DeleteModel", + request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.DeleteModelRequest.SerializeToString, + response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ) + + +class ModelServiceServicer(object): + # missing associated documentation comment in .proto file + pass + + def GetModel(self, request, context): + """Gets the specified model resource by model ID. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def ListModels(self, request, context): + """Lists all models in the specified dataset. Requires the READER dataset + role. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def PatchModel(self, request, context): + """Patch specific fields in the specified model. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def DeleteModel(self, request, context): + """Deletes the model specified by modelId from the dataset. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + +def add_ModelServiceServicer_to_server(servicer, server): + rpc_method_handlers = { + "GetModel": grpc.unary_unary_rpc_method_handler( + servicer.GetModel, + request_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.GetModelRequest.FromString, + response_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.SerializeToString, + ), + "ListModels": grpc.unary_unary_rpc_method_handler( + servicer.ListModels, + request_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsRequest.FromString, + response_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsResponse.SerializeToString, + ), + "PatchModel": grpc.unary_unary_rpc_method_handler( + servicer.PatchModel, + request_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.PatchModelRequest.FromString, + response_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.SerializeToString, + ), + "DeleteModel": grpc.unary_unary_rpc_method_handler( + servicer.DeleteModel, + request_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.DeleteModelRequest.FromString, + response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + "google.cloud.bigquery.v2.ModelService", rpc_method_handlers + ) + server.add_generic_rpc_handlers((generic_handler,)) diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_reference.proto b/bigquery/google/cloud/bigquery_v2/proto/model_reference.proto new file mode 100644 index 000000000000..8e1e218f969c --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model_reference.proto @@ -0,0 +1,39 @@ +// Copyright 2019 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.v2; + +import "google/api/annotations.proto"; + +option go_package = "google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery"; +option java_outer_classname = "ModelReferenceProto"; +option java_package = "com.google.cloud.bigquery.v2"; + + +// Id path of a model. +message ModelReference { + // [Required] The ID of the project containing this model. + string project_id = 1; + + // [Required] The ID of the dataset containing this model. + string dataset_id = 2; + + // [Required] The ID of the model. The ID must contain only + // letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum + // length is 1,024 characters. + string model_id = 3; +} diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2.py new file mode 100644 index 000000000000..3d1b53e44800 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2.py @@ -0,0 +1,137 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/bigquery_v2/proto/model_reference.proto + +import sys + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name="google/cloud/bigquery_v2/proto/model_reference.proto", + package="google.cloud.bigquery.v2", + syntax="proto3", + serialized_options=_b( + "\n\034com.google.cloud.bigquery.v2B\023ModelReferenceProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery" + ), + serialized_pb=_b( + '\n4google/cloud/bigquery_v2/proto/model_reference.proto\x12\x18google.cloud.bigquery.v2\x1a\x1cgoogle/api/annotations.proto"J\n\x0eModelReference\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\tBu\n\x1c\x63om.google.cloud.bigquery.v2B\x13ModelReferenceProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' + ), + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR], +) + + +_MODELREFERENCE = _descriptor.Descriptor( + name="ModelReference", + full_name="google.cloud.bigquery.v2.ModelReference", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="project_id", + full_name="google.cloud.bigquery.v2.ModelReference.project_id", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="dataset_id", + full_name="google.cloud.bigquery.v2.ModelReference.dataset_id", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="model_id", + full_name="google.cloud.bigquery.v2.ModelReference.model_id", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=112, + serialized_end=186, +) + +DESCRIPTOR.message_types_by_name["ModelReference"] = _MODELREFERENCE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +ModelReference = _reflection.GeneratedProtocolMessageType( + "ModelReference", + (_message.Message,), + dict( + DESCRIPTOR=_MODELREFERENCE, + __module__="google.cloud.bigquery_v2.proto.model_reference_pb2", + __doc__="""Id path of a model. + + + Attributes: + project_id: + [Required] The ID of the project containing this model. + dataset_id: + [Required] The ID of the dataset containing this model. + model_id: + [Required] The ID of the model. The ID must contain only + letters (a-z, A-Z), numbers (0-9), or underscores (\_). The + maximum length is 1,024 characters. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.ModelReference) + ), +) +_sym_db.RegisterMessage(ModelReference) + + +DESCRIPTOR._options = None +# @@protoc_insertion_point(module_scope) diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2_grpc.py b/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2_grpc.py new file mode 100644 index 000000000000..07cb78fe03a9 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/model_reference_pb2_grpc.py @@ -0,0 +1,2 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc diff --git a/bigquery/google/cloud/bigquery_v2/proto/standard_sql.proto b/bigquery/google/cloud/bigquery_v2/proto/standard_sql.proto new file mode 100644 index 000000000000..82d9960242b3 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/standard_sql.proto @@ -0,0 +1,110 @@ +// Copyright 2019 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.v2; + +import "google/api/annotations.proto"; + +option go_package = "google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery"; +option java_outer_classname = "StandardSqlProto"; +option java_package = "com.google.cloud.bigquery.v2"; + + +// The type of a variable, e.g., a function argument. +// Examples: +// INT64: {type_kind="INT64"} +// ARRAY: {type_kind="ARRAY", array_element_type="STRING"} +// STRUCT>: +// {type_kind="STRUCT", +// struct_type={fields=[ +// {name="x", type={type_kind="STRING"}}, +// {name="y", type={type_kind="ARRAY", array_element_type="DATE"}} +// ]}} +message StandardSqlDataType { + enum TypeKind { + // Invalid type. + TYPE_KIND_UNSPECIFIED = 0; + + // Encoded as a string in decimal format. + INT64 = 2; + + // Encoded as a boolean "false" or "true". + BOOL = 5; + + // Encoded as a number, or string "NaN", "Infinity" or "-Infinity". + FLOAT64 = 7; + + // Encoded as a string value. + STRING = 8; + + // Encoded as a base64 string per RFC 4648, section 4. + BYTES = 9; + + // Encoded as an RFC 3339 timestamp with mandatory "Z" time zone string: + // 1985-04-12T23:20:50.52Z + TIMESTAMP = 19; + + // Encoded as RFC 3339 full-date format string: 1985-04-12 + DATE = 10; + + // Encoded as RFC 3339 partial-time format string: 23:20:50.52 + TIME = 20; + + // Encoded as RFC 3339 full-date "T" partial-time: 1985-04-12T23:20:50.52 + DATETIME = 21; + + // Encoded as WKT + GEOGRAPHY = 22; + + // Encoded as a decimal string. + NUMERIC = 23; + + // Encoded as a list with types matching Type.array_type. + ARRAY = 16; + + // Encoded as a list with fields of type Type.struct_type[i]. List is used + // because a JSON object cannot have duplicate field names. + STRUCT = 17; + } + + // Required. The top level type of this field. + // Can be any standard SQL data type (e.g., "INT64", "DATE", "ARRAY"). + TypeKind type_kind = 1; + + oneof sub_type { + // The type of the array's elements, if type_kind = "ARRAY". + StandardSqlDataType array_element_type = 2; + + // The fields of this struct, in order, if type_kind = "STRUCT". + StandardSqlStructType struct_type = 3; + } +} + +// A field or a column. +message StandardSqlField { + // Optional. The name of this field. Can be absent for struct fields. + string name = 1; + + // Optional. The type of this parameter. Absent if not explicitly + // specified (e.g., CREATE FUNCTION statement can omit the return type; + // in this case the output parameter does not have this "type" field). + StandardSqlDataType type = 2; +} + +message StandardSqlStructType { + repeated StandardSqlField fields = 1; +} diff --git a/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2.py new file mode 100644 index 000000000000..5f4a40278140 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2.py @@ -0,0 +1,365 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/bigquery_v2/proto/standard_sql.proto + +import sys + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name="google/cloud/bigquery_v2/proto/standard_sql.proto", + package="google.cloud.bigquery.v2", + syntax="proto3", + serialized_options=_b( + "\n\034com.google.cloud.bigquery.v2B\020StandardSqlProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery" + ), + serialized_pb=_b( + '\n1google/cloud/bigquery_v2/proto/standard_sql.proto\x12\x18google.cloud.bigquery.v2\x1a\x1cgoogle/api/annotations.proto"\xc6\x03\n\x13StandardSqlDataType\x12I\n\ttype_kind\x18\x01 \x01(\x0e\x32\x36.google.cloud.bigquery.v2.StandardSqlDataType.TypeKind\x12K\n\x12\x61rray_element_type\x18\x02 \x01(\x0b\x32-.google.cloud.bigquery.v2.StandardSqlDataTypeH\x00\x12\x46\n\x0bstruct_type\x18\x03 \x01(\x0b\x32/.google.cloud.bigquery.v2.StandardSqlStructTypeH\x00"\xc2\x01\n\x08TypeKind\x12\x19\n\x15TYPE_KIND_UNSPECIFIED\x10\x00\x12\t\n\x05INT64\x10\x02\x12\x08\n\x04\x42OOL\x10\x05\x12\x0b\n\x07\x46LOAT64\x10\x07\x12\n\n\x06STRING\x10\x08\x12\t\n\x05\x42YTES\x10\t\x12\r\n\tTIMESTAMP\x10\x13\x12\x08\n\x04\x44\x41TE\x10\n\x12\x08\n\x04TIME\x10\x14\x12\x0c\n\x08\x44\x41TETIME\x10\x15\x12\r\n\tGEOGRAPHY\x10\x16\x12\x0b\n\x07NUMERIC\x10\x17\x12\t\n\x05\x41RRAY\x10\x10\x12\n\n\x06STRUCT\x10\x11\x42\n\n\x08sub_type"]\n\x10StandardSqlField\x12\x0c\n\x04name\x18\x01 \x01(\t\x12;\n\x04type\x18\x02 \x01(\x0b\x32-.google.cloud.bigquery.v2.StandardSqlDataType"S\n\x15StandardSqlStructType\x12:\n\x06\x66ields\x18\x01 \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlFieldBr\n\x1c\x63om.google.cloud.bigquery.v2B\x10StandardSqlProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' + ), + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR], +) + + +_STANDARDSQLDATATYPE_TYPEKIND = _descriptor.EnumDescriptor( + name="TypeKind", + full_name="google.cloud.bigquery.v2.StandardSqlDataType.TypeKind", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="TYPE_KIND_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="INT64", index=1, number=2, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="BOOL", index=2, number=5, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="FLOAT64", index=3, number=7, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="STRING", index=4, number=8, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="BYTES", index=5, number=9, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="TIMESTAMP", index=6, number=19, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="DATE", index=7, number=10, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="TIME", index=8, number=20, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="DATETIME", index=9, number=21, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="GEOGRAPHY", index=10, number=22, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="NUMERIC", index=11, number=23, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="ARRAY", index=12, number=16, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="STRUCT", index=13, number=17, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=358, + serialized_end=552, +) +_sym_db.RegisterEnumDescriptor(_STANDARDSQLDATATYPE_TYPEKIND) + + +_STANDARDSQLDATATYPE = _descriptor.Descriptor( + name="StandardSqlDataType", + full_name="google.cloud.bigquery.v2.StandardSqlDataType", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="type_kind", + full_name="google.cloud.bigquery.v2.StandardSqlDataType.type_kind", + index=0, + number=1, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="array_element_type", + full_name="google.cloud.bigquery.v2.StandardSqlDataType.array_element_type", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="struct_type", + full_name="google.cloud.bigquery.v2.StandardSqlDataType.struct_type", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[_STANDARDSQLDATATYPE_TYPEKIND], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name="sub_type", + full_name="google.cloud.bigquery.v2.StandardSqlDataType.sub_type", + index=0, + containing_type=None, + fields=[], + ) + ], + serialized_start=110, + serialized_end=564, +) + + +_STANDARDSQLFIELD = _descriptor.Descriptor( + name="StandardSqlField", + full_name="google.cloud.bigquery.v2.StandardSqlField", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="name", + full_name="google.cloud.bigquery.v2.StandardSqlField.name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="type", + full_name="google.cloud.bigquery.v2.StandardSqlField.type", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=566, + serialized_end=659, +) + + +_STANDARDSQLSTRUCTTYPE = _descriptor.Descriptor( + name="StandardSqlStructType", + full_name="google.cloud.bigquery.v2.StandardSqlStructType", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="fields", + full_name="google.cloud.bigquery.v2.StandardSqlStructType.fields", + index=0, + number=1, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ) + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=661, + serialized_end=744, +) + +_STANDARDSQLDATATYPE.fields_by_name[ + "type_kind" +].enum_type = _STANDARDSQLDATATYPE_TYPEKIND +_STANDARDSQLDATATYPE.fields_by_name[ + "array_element_type" +].message_type = _STANDARDSQLDATATYPE +_STANDARDSQLDATATYPE.fields_by_name["struct_type"].message_type = _STANDARDSQLSTRUCTTYPE +_STANDARDSQLDATATYPE_TYPEKIND.containing_type = _STANDARDSQLDATATYPE +_STANDARDSQLDATATYPE.oneofs_by_name["sub_type"].fields.append( + _STANDARDSQLDATATYPE.fields_by_name["array_element_type"] +) +_STANDARDSQLDATATYPE.fields_by_name[ + "array_element_type" +].containing_oneof = _STANDARDSQLDATATYPE.oneofs_by_name["sub_type"] +_STANDARDSQLDATATYPE.oneofs_by_name["sub_type"].fields.append( + _STANDARDSQLDATATYPE.fields_by_name["struct_type"] +) +_STANDARDSQLDATATYPE.fields_by_name[ + "struct_type" +].containing_oneof = _STANDARDSQLDATATYPE.oneofs_by_name["sub_type"] +_STANDARDSQLFIELD.fields_by_name["type"].message_type = _STANDARDSQLDATATYPE +_STANDARDSQLSTRUCTTYPE.fields_by_name["fields"].message_type = _STANDARDSQLFIELD +DESCRIPTOR.message_types_by_name["StandardSqlDataType"] = _STANDARDSQLDATATYPE +DESCRIPTOR.message_types_by_name["StandardSqlField"] = _STANDARDSQLFIELD +DESCRIPTOR.message_types_by_name["StandardSqlStructType"] = _STANDARDSQLSTRUCTTYPE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +StandardSqlDataType = _reflection.GeneratedProtocolMessageType( + "StandardSqlDataType", + (_message.Message,), + dict( + DESCRIPTOR=_STANDARDSQLDATATYPE, + __module__="google.cloud.bigquery_v2.proto.standard_sql_pb2", + __doc__="""The type of a variable, e.g., a function argument. Examples: INT64: + {type\_kind="INT64"} ARRAY: {type\_kind="ARRAY", + array\_element\_type="STRING"} STRUCT: + {type\_kind="STRUCT", struct\_type={fields=[ {name="x", + type={type\_kind="STRING"}}, {name="y", type={type\_kind="ARRAY", + array\_element\_type="DATE"}} ]}} + + + Attributes: + type_kind: + Required. The top level type of this field. Can be any + standard SQL data type (e.g., "INT64", "DATE", "ARRAY"). + array_element_type: + The type of the array's elements, if type\_kind = "ARRAY". + struct_type: + The fields of this struct, in order, if type\_kind = "STRUCT". + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.StandardSqlDataType) + ), +) +_sym_db.RegisterMessage(StandardSqlDataType) + +StandardSqlField = _reflection.GeneratedProtocolMessageType( + "StandardSqlField", + (_message.Message,), + dict( + DESCRIPTOR=_STANDARDSQLFIELD, + __module__="google.cloud.bigquery_v2.proto.standard_sql_pb2", + __doc__="""A field or a column. + + + Attributes: + name: + Optional. The name of this field. Can be absent for struct + fields. + type: + Optional. The type of this parameter. Absent if not explicitly + specified (e.g., CREATE FUNCTION statement can omit the return + type; in this case the output parameter does not have this + "type" field). + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.StandardSqlField) + ), +) +_sym_db.RegisterMessage(StandardSqlField) + +StandardSqlStructType = _reflection.GeneratedProtocolMessageType( + "StandardSqlStructType", + (_message.Message,), + dict( + DESCRIPTOR=_STANDARDSQLSTRUCTTYPE, + __module__="google.cloud.bigquery_v2.proto.standard_sql_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.StandardSqlStructType) + ), +) +_sym_db.RegisterMessage(StandardSqlStructType) + + +DESCRIPTOR._options = None +# @@protoc_insertion_point(module_scope) diff --git a/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2_grpc.py b/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2_grpc.py new file mode 100644 index 000000000000..07cb78fe03a9 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/proto/standard_sql_pb2_grpc.py @@ -0,0 +1,2 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc diff --git a/bigquery/google/cloud/bigquery_v2/types.py b/bigquery/google/cloud/bigquery_v2/types.py new file mode 100644 index 000000000000..3a0be08718ae --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/types.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 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. + +from __future__ import absolute_import +import sys + +from google.api_core.protobuf_helpers import get_messages + +from google.cloud.bigquery_v2.proto import location_metadata_pb2 +from google.cloud.bigquery_v2.proto import model_pb2 +from google.cloud.bigquery_v2.proto import model_reference_pb2 +from google.cloud.bigquery_v2.proto import standard_sql_pb2 +from google.protobuf import empty_pb2 +from google.protobuf import wrappers_pb2 + +_shared_modules = [empty_pb2, wrappers_pb2] + +_local_modules = [ + location_metadata_pb2, + model_pb2, + model_reference_pb2, + standard_sql_pb2, +] + +names = [] + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) +for module in _local_modules: + for name, message in get_messages(module).items(): + message.__module__ = "google.cloud.bigquery_v2.types" + setattr(sys.modules[__name__], name, message) + names.append(name) + +__all__ = tuple(sorted(names)) diff --git a/bigquery/synth.metadata b/bigquery/synth.metadata new file mode 100644 index 000000000000..b3292f22cb5a --- /dev/null +++ b/bigquery/synth.metadata @@ -0,0 +1,24 @@ +{ + "updateTime": "2019-03-12T17:32:21.942838Z", + "sources": [ + { + "generator": { + "name": "artman", + "version": "0.16.16", + "dockerImage": "googleapis/artman@sha256:30babbfce7f05a62b1892c63c575aa2c8c502eb4bcc8f3bb90ec83e955d5d319" + } + } + ], + "destinations": [ + { + "client": { + "source": "googleapis", + "apiName": "bigquery", + "apiVersion": "v2", + "language": "python", + "generator": "gapic", + "config": "google/cloud/bigquery/artman_bigquery_v2.yaml" + } + } + ] +} \ No newline at end of file diff --git a/bigquery/synth.py b/bigquery/synth.py new file mode 100644 index 000000000000..cb951221dce8 --- /dev/null +++ b/bigquery/synth.py @@ -0,0 +1,50 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This script is used to synthesize generated parts of this library.""" + +import synthtool as s +from synthtool import gcp + +gapic = gcp.GAPICGenerator() + +version = 'v2' + +library = gapic.py_library( + 'bigquery', + version, + config_path='/google/cloud/bigquery/' + 'artman_bigquery_v2.yaml', + artman_output_name='bigquery-v2', + include_protos=True, +) + +s.move( + [ + library / "google/cloud/bigquery_v2/gapic/enums.py", + library / "google/cloud/bigquery_v2/types.py", + library / "google/cloud/bigquery_v2/proto/location*", + library / "google/cloud/bigquery_v2/proto/model*", + library / "google/cloud/bigquery_v2/proto/standard_sql*", + ], +) + +# Fix up proto docs that are missing summary line. +s.replace( + "google/cloud/bigquery_v2/proto/model_pb2.py", + '"""Attributes:', + '"""Protocol buffer.\n\n Attributes:', +) + +s.shell.run(["nox", "-s", "blacken"], hide_output=False) From b453aaf0c4e36516561a84363743126a336bd19e Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Wed, 13 Mar 2019 14:10:53 -0700 Subject: [PATCH 2/8] Fixes BQ Models API generated code for Python 2.7 (#491) * Fixes BQ Models API generated code for Python 2.7 * Format quoted strings as plain text. --- bigquery/google/cloud/bigquery_v2/__init__.py | 33 +++++++++++++++++++ .../proto/location_metadata_pb2.py | 4 +-- .../cloud/bigquery_v2/proto/model_pb2.py | 2 +- bigquery/synth.metadata | 6 ++-- bigquery/synth.py | 4 +++ bigquery/tests/unit/model/__init__.py | 0 6 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 bigquery/google/cloud/bigquery_v2/__init__.py create mode 100644 bigquery/tests/unit/model/__init__.py diff --git a/bigquery/google/cloud/bigquery_v2/__init__.py b/bigquery/google/cloud/bigquery_v2/__init__.py new file mode 100644 index 000000000000..e582214329f3 --- /dev/null +++ b/bigquery/google/cloud/bigquery_v2/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# 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. + +from __future__ import absolute_import + +import pkg_resources + +__version__ = pkg_resources.get_distribution("google-cloud-bigquery").version # noqa + +from google.cloud.bigquery_v2 import types +from google.cloud.bigquery_v2.gapic import enums + + +__all__ = ( + # google.cloud.bigquery_v2 + "__version__", + "types", + # google.cloud.bigquery_v2 + "enums", +) diff --git a/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py index c1410ddc46d3..6dd9da52e4ed 100644 --- a/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py +++ b/bigquery/google/cloud/bigquery_v2/proto/location_metadata_pb2.py @@ -84,9 +84,9 @@ Attributes: legacy_location_id: - The legacy BigQuery location ID, e.g. “EU” for the “europe” + The legacy BigQuery location ID, e.g. ``EU`` for the ``europe`` location. This is for any API consumers that need the legacy - “US” and “EU” locations. + ``US`` and ``EU`` locations. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.LocationMetadata) ), diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py index 768a974ba08d..42660268ec54 100644 --- a/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py +++ b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py @@ -2820,7 +2820,7 @@ this model. label_columns: Output only. Label columns that were used to train this model. - The output of the model will have a “predicted\_” prefix to + The output of the model will have a ``predicted\_`` prefix to these columns. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model) diff --git a/bigquery/synth.metadata b/bigquery/synth.metadata index b3292f22cb5a..4fc1eea2ab89 100644 --- a/bigquery/synth.metadata +++ b/bigquery/synth.metadata @@ -1,11 +1,11 @@ { - "updateTime": "2019-03-12T17:32:21.942838Z", + "updateTime": "2019-03-13T16:39:59.875284Z", "sources": [ { "generator": { "name": "artman", - "version": "0.16.16", - "dockerImage": "googleapis/artman@sha256:30babbfce7f05a62b1892c63c575aa2c8c502eb4bcc8f3bb90ec83e955d5d319" + "version": "0.16.17", + "dockerImage": "googleapis/artman@sha256:7231f27272231a884e09edb5953148c85ecd8467780d33c4a35c3e507885715b" } } ], diff --git a/bigquery/synth.py b/bigquery/synth.py index cb951221dce8..a8370fd4e96a 100644 --- a/bigquery/synth.py +++ b/bigquery/synth.py @@ -47,4 +47,8 @@ '"""Protocol buffer.\n\n Attributes:', ) +# Remove non-ascii characters from docstrings for Python 2.7. +# Format quoted strings as plain text. +s.replace("google/cloud/bigquery_v2/proto/*.py", "[“”]", '``') + s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/bigquery/tests/unit/model/__init__.py b/bigquery/tests/unit/model/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 From 0dd27b9fcdd53a1f2a78cea08150788ae4e8f136 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 19 Mar 2019 12:54:36 -0700 Subject: [PATCH 3/8] Add handwritten model API classes. (#492) * Add handwritten model API classes. These classes provide the top-level classes for the Model API. The protocol buffer objects are used for all sub-objects. The pattern for mutable properties follows the same as with Table and Dataset: a `_properties` dictionary contains the property values in the REST API format. * Address review comments in Model. Use setdefault for labels. Simplify setter logic for expires. * Combine error messages for too many and too few parts in model/table ID. --- bigquery/docs/gapic/v2/enums.rst | 5 + bigquery/docs/reference.rst | 9 + bigquery/google/cloud/bigquery/__init__.py | 5 + bigquery/google/cloud/bigquery/_helpers.py | 49 +++ bigquery/google/cloud/bigquery/dataset.py | 36 +- bigquery/google/cloud/bigquery/model.py | 364 ++++++++++++++++++ bigquery/google/cloud/bigquery/table.py | 48 +-- bigquery/tests/unit/model/test_model.py | 249 ++++++++++++ .../tests/unit/model/test_model_reference.py | 122 ++++++ bigquery/tests/unit/test_dataset.py | 7 + 10 files changed, 841 insertions(+), 53 deletions(-) create mode 100644 bigquery/docs/gapic/v2/enums.rst create mode 100644 bigquery/google/cloud/bigquery/model.py create mode 100644 bigquery/tests/unit/model/test_model.py create mode 100644 bigquery/tests/unit/model/test_model_reference.py diff --git a/bigquery/docs/gapic/v2/enums.rst b/bigquery/docs/gapic/v2/enums.rst new file mode 100644 index 000000000000..9f47e3941904 --- /dev/null +++ b/bigquery/docs/gapic/v2/enums.rst @@ -0,0 +1,5 @@ +Enums for BigQuery API Client +============================= + +.. automodule:: google.cloud.bigquery_v2.gapic.enums + :members: \ No newline at end of file diff --git a/bigquery/docs/reference.rst b/bigquery/docs/reference.rst index c9abc0208ed1..b3f949e3daab 100644 --- a/bigquery/docs/reference.rst +++ b/bigquery/docs/reference.rst @@ -92,6 +92,14 @@ Table table.TimePartitioning table.TimePartitioningType +Model +===== + +.. autosummary:: + :toctree: generated + + model.Model + model.ModelReference Schema ====== @@ -154,4 +162,5 @@ Protocol buffer classes for working with the Models API. .. toctree:: :maxdepth: 2 + gapic/v2/enums gapic/v2/types diff --git a/bigquery/google/cloud/bigquery/__init__.py b/bigquery/google/cloud/bigquery/__init__.py index c3865d511b6c..0b972bb7297b 100644 --- a/bigquery/google/cloud/bigquery/__init__.py +++ b/bigquery/google/cloud/bigquery/__init__.py @@ -60,6 +60,8 @@ from google.cloud.bigquery.job import SourceFormat from google.cloud.bigquery.job import UnknownJob from google.cloud.bigquery.job import WriteDisposition +from google.cloud.bigquery.model import Model +from google.cloud.bigquery.model import ModelReference from google.cloud.bigquery.query import ArrayQueryParameter from google.cloud.bigquery.query import ScalarQueryParameter from google.cloud.bigquery.query import StructQueryParameter @@ -100,6 +102,9 @@ "UnknownJob", "TimePartitioningType", "TimePartitioning", + # Models + "Model", + "ModelReference", # Shared helpers "SchemaField", "UDFResource", diff --git a/bigquery/google/cloud/bigquery/_helpers.py b/bigquery/google/cloud/bigquery/_helpers.py index 72e1fa276dd7..90b1f14016b7 100644 --- a/bigquery/google/cloud/bigquery/_helpers.py +++ b/bigquery/google/cloud/bigquery/_helpers.py @@ -581,3 +581,52 @@ def _str_or_none(value): """Helper: serialize value to JSON string.""" if value is not None: return str(value) + + +def _parse_3_part_id(full_id, default_project=None, property_name="table_id"): + output_project_id = default_project + output_dataset_id = None + output_resource_id = None + parts = full_id.split(".") + + if len(parts) != 2 and len(parts) != 3: + raise ValueError( + "{property_name} must be a fully-qualified ID in " + 'standard SQL format. e.g. "project.dataset.{property_name}", ' + "got {}".format(full_id, property_name=property_name) + ) + + if len(parts) == 2 and not default_project: + raise ValueError( + "When default_project is not set, {property_name} must be a " + "fully-qualified ID in standard SQL format. " + 'e.g. "project.dataset_id.{property_name}", got {}'.format( + full_id, property_name=property_name + ) + ) + + if len(parts) == 2: + output_dataset_id, output_resource_id = parts + else: + output_project_id, output_dataset_id, output_resource_id = parts + + return output_project_id, output_dataset_id, output_resource_id + + +def _build_resource_from_properties(obj, filter_fields): + """Build a resource based on a ``_properties`` dictionary, filtered by + ``filter_fields``, which follow the name of the Python object. + """ + partial = {} + for filter_field in filter_fields: + api_field = obj._PROPERTY_TO_API_FIELD.get(filter_field) + if api_field is None and filter_field not in obj._properties: + raise ValueError("No property %s" % filter_field) + elif api_field is not None: + partial[api_field] = obj._properties.get(api_field) + else: + # allows properties that are not defined in the library + # and properties that have the same name as API resource key + partial[filter_field] = obj._properties[filter_field] + + return partial diff --git a/bigquery/google/cloud/bigquery/dataset.py b/bigquery/google/cloud/bigquery/dataset.py index 2a71c900baf0..8566e183cda0 100644 --- a/bigquery/google/cloud/bigquery/dataset.py +++ b/bigquery/google/cloud/bigquery/dataset.py @@ -21,6 +21,7 @@ import google.cloud._helpers from google.cloud.bigquery import _helpers +from google.cloud.bigquery.model import ModelReference from google.cloud.bigquery.table import TableReference @@ -37,6 +38,21 @@ def _get_table_reference(self, table_id): return TableReference(self, table_id) +def _get_model_reference(self, model_id): + """Constructs a ModelReference. + + Args: + model_id (str): the ID of the model. + + Returns: + google.cloud.bigquery.model.ModelReference: + A ModelReference for a model in this dataset. + """ + return ModelReference.from_api_repr( + {"projectId": self.project, "datasetId": self.dataset_id, "modelId": model_id} + ) + + class AccessEntry(object): """Represents grant of an access role to an entity. @@ -206,6 +222,8 @@ def path(self): table = _get_table_reference + model = _get_model_reference + @classmethod def from_api_repr(cls, resource): """Factory: construct a dataset reference given its API representation @@ -567,22 +585,12 @@ def to_api_repr(self): def _build_resource(self, filter_fields): """Generate a resource for ``update``.""" - partial = {} - for filter_field in filter_fields: - api_field = self._PROPERTY_TO_API_FIELD.get(filter_field) - if api_field is None and filter_field not in self._properties: - raise ValueError("No Dataset property %s" % filter_field) - elif api_field is not None: - partial[api_field] = self._properties.get(api_field) - else: - # allows properties that are not defined in the library - # and properties that have the same name as API resource key - partial[filter_field] = self._properties[filter_field] - - return partial + return _helpers._build_resource_from_properties(self, filter_fields) table = _get_table_reference + model = _get_model_reference + def __repr__(self): return "Dataset({})".format(repr(self.reference)) @@ -662,3 +670,5 @@ def reference(self): return DatasetReference(self.project, self.dataset_id) table = _get_table_reference + + model = _get_model_reference diff --git a/bigquery/google/cloud/bigquery/model.py b/bigquery/google/cloud/bigquery/model.py new file mode 100644 index 000000000000..5d9ec810b2d0 --- /dev/null +++ b/bigquery/google/cloud/bigquery/model.py @@ -0,0 +1,364 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 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. + +"""Define resources for the BigQuery ML Models API.""" + +import datetime + +from google.protobuf import json_format +import six + +import google.cloud._helpers +from google.cloud.bigquery import _helpers +from google.cloud.bigquery_v2 import types + + +class Model(object): + """Model represents a machine learning model resource. + + See + https://cloud.google.com/bigquery/docs/reference/rest/v2/models + + Args: + model_ref (Union[ \ + :class:`~google.cloud.bigquery.model.ModelReference`, \ + str, \ + ]): + A pointer to a model. If ``model_ref`` is a string, it must + included a project ID, dataset ID, and model ID, each separated + by ``.``. + """ + + _PROPERTY_TO_API_FIELD = { + "expires": "expirationTime", + "friendly_name": "friendlyName", + # Even though it's not necessary for field mapping to map when the + # property name equals the resource name, we add these here so that we + # have an exhaustive list of all mutable properties. + "labels": "labels", + "description": "description", + } + + def __init__(self, model_ref): + # Use _proto on read-only properties to use it's built-in type + # conversion. + self._proto = types.Model() + + # Use _properties on read-write properties to match the REST API + # semantics. The BigQuery API makes a distinction between an unset + # value, a null value, and a default value (0 or ""), but the protocol + # buffer classes do not. + self._properties = {} + + if isinstance(model_ref, six.string_types): + model_ref = ModelReference.from_string(model_ref) + + if model_ref: + self._proto.model_reference.CopyFrom(model_ref._proto) + + @property + def reference(self): + """A :class:`~google.cloud.bigquery.model.ModelReference` pointing to + this model. + + Read-only. + + Returns: + google.cloud.bigquery.model.ModelReference: pointer to this model. + """ + ref = ModelReference() + ref._proto = self._proto.model_reference + return ref + + @property + def location(self): + """str: The geographic location where the model resides. This value + is inherited from the dataset. + + Read-only. + """ + return self._proto.location + + @property + def etag(self): + """str: ETag for the model resource (:data:`None` until + set from the server). + + Read-only. + """ + return self._proto.etag + + @property + def created(self): + """Union[datetime.datetime, None]: Datetime at which the model was + created (:data:`None` until set from the server). + + Read-only. + """ + value = self._proto.creation_time + if value is not None and value != 0: + # value will be in milliseconds. + return google.cloud._helpers._datetime_from_microseconds( + 1000.0 * float(value) + ) + + @property + def modified(self): + """Union[datetime.datetime, None]: Datetime at which the model was last + modified (:data:`None` until set from the server). + + Read-only. + """ + value = self._proto.last_modified_time + if value is not None and value != 0: + # value will be in milliseconds. + return google.cloud._helpers._datetime_from_microseconds( + 1000.0 * float(value) + ) + + @property + def model_type(self): + """google.cloud.bigquery_v2.gapic.enums.Model.ModelType: Type of the + model resource. + + Read-only. + + The value is one of elements of the + :class:`~google.cloud.bigquery_v2.gapic.enums.Model.ModelType` + enumeration. + """ + return self._proto.model_type + + @property + def training_runs(self): + """Sequence[google.cloud.bigquery_v2.types.Model.TrainingRun]: Information + for all training runs in increasing order of start time. + + Read-only. + + An iterable of :class:`~google.cloud.bigquery_v2.types.Model.TrainingRun`. + """ + return self._proto.training_runs + + @property + def feature_columns(self): + """Sequence[google.cloud.bigquery_v2.types.StandardSqlField]: Input + feature columns that were used to train this model. + + Read-only. + + An iterable of :class:`~google.cloud.bigquery_v2.types.StandardSqlField`. + """ + return self._proto.feature_columns + + @property + def label_columns(self): + """Sequence[google.cloud.bigquery_v2.types.StandardSqlField]: Label + columns that were used to train this model. The output of the model + will have a ``predicted_`` prefix to these columns. + + Read-only. + + An iterable of :class:`~google.cloud.bigquery_v2.types.StandardSqlField`. + """ + return self._proto.label_columns + + @property + def expires(self): + """Union[datetime.datetime, None]: The datetime when this model + expires. If not present, the model will persist indefinitely. Expired + models will be deleted and their storage reclaimed. + """ + value = self._properties.get("expirationTime") + if value is not None: + # value will be in milliseconds. + return google.cloud._helpers._datetime_from_microseconds( + 1000.0 * float(value) + ) + + @expires.setter + def expires(self, value): + if value is not None: + value = google.cloud._helpers._millis_from_datetime(value) + self._properties["expirationTime"] = value + + @property + def description(self): + """Union[str, None]: Description of the model (defaults to + :data:`None`). + """ + return self._properties.get("description") + + @description.setter + def description(self, value): + self._properties["description"] = value + + @property + def friendly_name(self): + """Union[str, None]: Title of the table (defaults to :data:`None`). + + Raises: + ValueError: For invalid value types. + """ + return self._properties.get("friendlyName") + + @friendly_name.setter + def friendly_name(self, value): + self._properties["friendlyName"] = value + + @property + def labels(self): + """Dict[str, str]: Labels for the table. + + This method always returns a dict. To change a model's labels, + modify the dict, then call ``Client.update_model``. To delete a + label, set its value to :data:`None` before updating. + """ + return self._properties.setdefault("labels", {}) + + @labels.setter + def labels(self, value): + if value is None: + value = {} + self._properties["labels"] = value + + @classmethod + def from_api_repr(cls, resource): + """Factory: construct a model resource given its API representation + + Args: + resource (Dict[str, object]): + Model resource representation from the API + + Returns: + google.cloud.bigquery.model.Model: Model parsed from ``resource``. + """ + this = cls(None) + this._proto = json_format.ParseDict(resource, types.Model()) + for key in six.itervalues(cls._PROPERTY_TO_API_FIELD): + # Leave missing keys unset. This allows us to use setdefault in the + # getters where we want a default value other than None. + if key in resource: + this._properties[key] = resource[key] + return this + + def _build_resource(self, filter_fields): + """Generate a resource for ``update``.""" + return _helpers._build_resource_from_properties(self, filter_fields) + + def __repr__(self): + return "Model(reference={})".format(repr(self.reference)) + + +class ModelReference(object): + """ModelReferences are pointers to models. + + See + https://cloud.google.com/bigquery/docs/reference/rest/v2/models + """ + + def __init__(self): + self._proto = types.ModelReference() + + @property + def project(self): + """str: Project bound to the model""" + return self._proto.project_id + + @property + def dataset_id(self): + """str: ID of dataset containing the model.""" + return self._proto.dataset_id + + @property + def model_id(self): + """str: The model ID.""" + return self._proto.model_id + + @classmethod + def from_api_repr(cls, resource): + """Factory: construct a model reference given its API representation + + Args: + resource (Dict[str, object]): + Model reference representation returned from the API + + Returns: + google.cloud.bigquery.model.ModelReference: + Model reference parsed from ``resource``. + """ + ref = cls() + ref._proto = json_format.ParseDict(resource, types.ModelReference()) + return ref + + @classmethod + def from_string(cls, model_id, default_project=None): + """Construct a model reference from model ID string. + + Args: + model_id (str): + A model ID in standard SQL format. If ``default_project`` + is not specified, this must included a project ID, dataset + ID, and model ID, each separated by ``.``. + default_project (str): + Optional. The project ID to use when ``model_id`` does not + include a project ID. + + Returns: + ModelReference: Model reference parsed from ``model_id``. + + Raises: + ValueError: + If ``model_id`` is not a fully-qualified table ID in + standard SQL format. + """ + proj, dset, model = _helpers._parse_3_part_id( + model_id, default_project=default_project, property_name="model_id" + ) + return cls.from_api_repr( + {"projectId": proj, "datasetId": dset, "modelId": model} + ) + + def to_api_repr(self): + """Construct the API resource representation of this model reference. + + Returns: + Dict[str, object]: Model reference represented as an API resource + """ + return json_format.MessageToDict(self._proto) + + def _key(self): + """Unique key for this model. + + This is used for hashing a ModelReference. + """ + return self.project, self.dataset_id, self.model_id + + def __eq__(self, other): + if not isinstance(other, ModelReference): + return NotImplemented + return self._proto == other._proto + + def __ne__(self, other): + return not self == other + + def __hash__(self): + return hash(self._key()) + + def __repr__(self): + return "ModelReference(project='{}', dataset_id='{}', project_id='{}')".format( + self.project, self.dataset_id, self.model_id + ) diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/bigquery/table.py index 35f950e7d94a..e9fe4c4b0991 100644 --- a/bigquery/google/cloud/bigquery/table.py +++ b/bigquery/google/cloud/bigquery/table.py @@ -218,33 +218,13 @@ def from_string(cls, table_id, default_project=None): """ from google.cloud.bigquery.dataset import DatasetReference - output_project_id = default_project - output_dataset_id = None - output_table_id = None - parts = table_id.split(".") - - if len(parts) < 2: - raise ValueError( - "table_id must be a fully-qualified table ID in " - 'standard SQL format. e.g. "project.dataset.table", got ' - "{}".format(table_id) - ) - elif len(parts) == 2: - if not default_project: - raise ValueError( - "When default_project is not set, table_id must be a " - "fully-qualified table ID in standard SQL format. " - 'e.g. "project.dataset_id.table_id", got {}'.format(table_id) - ) - output_dataset_id, output_table_id = parts - elif len(parts) == 3: - output_project_id, output_dataset_id, output_table_id = parts - if len(parts) > 3: - raise ValueError( - "Too many parts in table_id. Must be a fully-qualified table " - 'ID in standard SQL format. e.g. "project.dataset.table", ' - "got {}".format(table_id) - ) + ( + output_project_id, + output_dataset_id, + output_table_id, + ) = _helpers._parse_3_part_id( + table_id, default_project=default_project, property_name="table_id" + ) return cls( DatasetReference(output_project_id, output_dataset_id), output_table_id @@ -870,19 +850,7 @@ def to_bqstorage(self): def _build_resource(self, filter_fields): """Generate a resource for ``update``.""" - partial = {} - for filter_field in filter_fields: - api_field = self._PROPERTY_TO_API_FIELD.get(filter_field) - if api_field is None and filter_field not in self._properties: - raise ValueError("No Table property %s" % filter_field) - elif api_field is not None: - partial[api_field] = self._properties.get(api_field) - else: - # allows properties that are not defined in the library - # and properties that have the same name as API resource key - partial[filter_field] = self._properties[filter_field] - - return partial + return _helpers._build_resource_from_properties(self, filter_fields) def __repr__(self): return "Table({})".format(repr(self.reference)) diff --git a/bigquery/tests/unit/model/test_model.py b/bigquery/tests/unit/model/test_model.py new file mode 100644 index 000000000000..26008453e64e --- /dev/null +++ b/bigquery/tests/unit/model/test_model.py @@ -0,0 +1,249 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 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. + +import datetime + +import pytest + +import google.cloud._helpers +from google.cloud.bigquery_v2.gapic import enums + + +@pytest.fixture +def target_class(): + from google.cloud.bigquery import Model + + return Model + + +@pytest.fixture +def object_under_test(target_class): + return target_class("project-id.dataset_id.model_id") + + +def test_ctor(target_class): + from google.cloud.bigquery import ModelReference + + ref = ModelReference.from_string("my-proj.my_dset.my_model") + got = target_class(ref) + assert got.reference == ref + + +def test_ctor_string(target_class): + from google.cloud.bigquery import ModelReference + + model_id = "my-proj.my_dset.my_model" + ref = ModelReference.from_string(model_id) + got = target_class(model_id) + assert got.reference == ref + + +def test_from_api_repr(target_class): + from google.cloud.bigquery import ModelReference + + creation_time = datetime.datetime( + 2010, 5, 19, 16, 0, 0, tzinfo=google.cloud._helpers.UTC + ) + modified_time = datetime.datetime( + 2011, 10, 1, 16, 0, 0, tzinfo=google.cloud._helpers.UTC + ) + expiration_time = datetime.datetime( + 2012, 12, 21, 16, 0, 0, tzinfo=google.cloud._helpers.UTC + ) + resource = { + "modelReference": { + "projectId": "my-project", + "datasetId": "my_dataset", + "modelId": "my_model", + }, + "location": "US", + "etag": "abcdefg", + "creationTime": str(google.cloud._helpers._millis(creation_time)), + "lastModifiedTime": str(google.cloud._helpers._millis(modified_time)), + "expirationTime": str(google.cloud._helpers._millis(expiration_time)), + "description": "A friendly description.", + "friendlyName": "A friendly name.", + "modelType": "LOGISTIC_REGRESSION", + "labels": {"greeting": u"こんにちは"}, + "trainingRuns": [ + { + "trainingOptions": {"initialLearnRate": 1.0}, + "startTime": str(google.cloud._helpers._millis(creation_time)), + }, + { + "trainingOptions": {"initialLearnRate": 0.5}, + "startTime": str(google.cloud._helpers._millis(modified_time)), + }, + ], + "featureColumns": [], + } + got = target_class.from_api_repr(resource) + + assert got.reference == ModelReference.from_string("my-project.my_dataset.my_model") + assert got.location == "US" + assert got.etag == "abcdefg" + assert got.created == creation_time + assert got.modified == modified_time + assert got.expires == expiration_time + assert got.description == u"A friendly description." + assert got.friendly_name == u"A friendly name." + assert got.model_type == enums.Model.ModelType.LOGISTIC_REGRESSION + assert got.labels == {"greeting": u"こんにちは"} + assert got.training_runs[0].training_options.initial_learn_rate == 1.0 + assert got.training_runs[0].start_time == google.cloud._helpers._millis( + creation_time + ) + assert got.training_runs[1].training_options.initial_learn_rate == 0.5 + assert got.training_runs[1].start_time == google.cloud._helpers._millis( + modified_time + ) + + +def test_from_api_repr_w_minimal_resource(target_class): + from google.cloud.bigquery import ModelReference + + resource = { + "modelReference": { + "projectId": "my-project", + "datasetId": "my_dataset", + "modelId": "my_model", + } + } + got = target_class.from_api_repr(resource) + assert got.reference == ModelReference.from_string("my-project.my_dataset.my_model") + assert got.location == "" + assert got.etag == "" + assert got.created is None + assert got.modified is None + assert got.expires is None + assert got.description is None + assert got.friendly_name is None + assert got.model_type == enums.Model.ModelType.MODEL_TYPE_UNSPECIFIED + assert got.labels == {} + assert len(got.training_runs) == 0 + assert len(got.feature_columns) == 0 + assert len(got.label_columns) == 0 + + +@pytest.mark.parametrize( + "resource,filter_fields,expected", + [ + ( + { + "friendlyName": "hello", + "description": "world", + "expirationTime": "12345", + "labels": {"a-label": "a-value"}, + }, + ["description"], + {"description": "world"}, + ), + ( + {"friendlyName": "hello", "description": "world"}, + ["friendlyName"], + {"friendlyName": "hello"}, + ), + ( + { + "friendlyName": "hello", + "description": "world", + "expirationTime": "12345", + "labels": {"a-label": "a-value"}, + }, + ["expires"], + {"expirationTime": "12345"}, + ), + ( + { + "friendlyName": "hello", + "description": "world", + "expirationTime": None, + "labels": {"a-label": "a-value"}, + }, + ["expires"], + {"expirationTime": None}, + ), + ( + { + "friendlyName": "hello", + "description": "world", + "expirationTime": None, + "labels": {"a-label": "a-value"}, + }, + ["labels"], + {"labels": {"a-label": "a-value"}}, + ), + ], +) +def test_build_resource(object_under_test, resource, filter_fields, expected): + object_under_test._properties = resource + got = object_under_test._build_resource(filter_fields) + assert got == expected + + +def test_set_description(object_under_test): + assert not object_under_test.description + object_under_test.description = "A model description." + assert object_under_test.description == "A model description." + object_under_test.description = None + assert not object_under_test.description + + +def test_set_expires(object_under_test): + assert not object_under_test.expires + expiration_time = datetime.datetime( + 2012, 12, 21, 16, 0, 0, tzinfo=google.cloud._helpers.UTC + ) + object_under_test.expires = expiration_time + assert object_under_test.expires == expiration_time + object_under_test.expires = None + assert not object_under_test.expires + + +def test_set_friendly_name(object_under_test): + assert not object_under_test.friendly_name + object_under_test.friendly_name = "A model name." + assert object_under_test.friendly_name == "A model name." + object_under_test.friendly_name = None + assert not object_under_test.friendly_name + + +def test_set_labels(object_under_test): + assert object_under_test.labels == {} + object_under_test.labels["data_owner"] = "someteam" + assert object_under_test.labels == {"data_owner": "someteam"} + del object_under_test.labels["data_owner"] + assert object_under_test.labels == {} + + +def test_replace_labels(object_under_test): + assert object_under_test.labels == {} + object_under_test.labels = {"data_owner": "someteam"} + assert object_under_test.labels == {"data_owner": "someteam"} + labels = {} + object_under_test.labels = labels + assert object_under_test.labels is labels + object_under_test.labels = None + assert object_under_test.labels == {} + + +def test_repr(target_class): + model = target_class("my-proj.my_dset.my_model") + got = repr(model) + assert got == ( + "Model(reference=ModelReference(" + "project='my-proj', dataset_id='my_dset', project_id='my_model'))" + ) diff --git a/bigquery/tests/unit/model/test_model_reference.py b/bigquery/tests/unit/model/test_model_reference.py new file mode 100644 index 000000000000..ea8a76fb14b6 --- /dev/null +++ b/bigquery/tests/unit/model/test_model_reference.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 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. + +import pytest + + +@pytest.fixture +def target_class(): + from google.cloud.bigquery import ModelReference + + return ModelReference + + +def test_from_api_repr(target_class): + resource = { + "projectId": "my-project", + "datasetId": "my_dataset", + "modelId": "my_model", + } + got = target_class.from_api_repr(resource) + assert got.project == "my-project" + assert got.dataset_id == "my_dataset" + assert got.model_id == "my_model" + + +def test_to_api_repr(target_class): + ref = target_class.from_string("my-project.my_dataset.my_model") + got = ref.to_api_repr() + assert got == { + "projectId": "my-project", + "datasetId": "my_dataset", + "modelId": "my_model", + } + + +def test_from_string(target_class): + got = target_class.from_string("string-project.string_dataset.string_model") + assert got.project == "string-project" + assert got.dataset_id == "string_dataset" + assert got.model_id == "string_model" + + +def test_from_string_legacy_string(target_class): + with pytest.raises(ValueError): + target_class.from_string("string-project:string_dataset.string_model") + + +def test_from_string_not_fully_qualified(target_class): + with pytest.raises(ValueError): + target_class.from_string("string_model") + + with pytest.raises(ValueError): + target_class.from_string("string_dataset.string_model") + + with pytest.raises(ValueError): + target_class.from_string("a.b.c.d") + + +def test_from_string_with_default_project(target_class): + got = target_class.from_string( + "string_dataset.string_model", default_project="default-project" + ) + assert got.project == "default-project" + assert got.dataset_id == "string_dataset" + assert got.model_id == "string_model" + + +def test_from_string_ignores_default_project(target_class): + got = target_class.from_string( + "string-project.string_dataset.string_model", default_project="default-project" + ) + assert got.project == "string-project" + assert got.dataset_id == "string_dataset" + assert got.model_id == "string_model" + + +def test_eq(target_class): + model = target_class.from_string("my-proj.my_dset.my_model") + model_too = target_class.from_string("my-proj.my_dset.my_model") + assert model == model_too + assert not (model != model_too) + + other_model = target_class.from_string("my-proj.my_dset.my_model2") + assert not (model == other_model) + assert model != other_model + + notamodel = object() + assert not (model == notamodel) + assert model != notamodel + + +def test_hash(target_class): + model = target_class.from_string("my-proj.my_dset.my_model") + model2 = target_class.from_string("my-proj.my_dset.model2") + got = {model: "hello", model2: "world"} + assert got[model] == "hello" + assert got[model2] == "world" + + model_too = target_class.from_string("my-proj.my_dset.my_model") + assert got[model_too] == "hello" + + +def test_repr(target_class): + model = target_class.from_string("my-proj.my_dset.my_model") + got = repr(model) + assert ( + got + == "ModelReference(project='my-proj', dataset_id='my_dset', project_id='my_model')" + ) diff --git a/bigquery/tests/unit/test_dataset.py b/bigquery/tests/unit/test_dataset.py index 7774ccfe8814..96a2ace7da0c 100644 --- a/bigquery/tests/unit/test_dataset.py +++ b/bigquery/tests/unit/test_dataset.py @@ -151,6 +151,13 @@ def test_table(self): self.assertEqual(table_ref.project, "some-project-1") self.assertEqual(table_ref.table_id, "table_1") + def test_model(self): + dataset_ref = self._make_one("some-project-1", "dataset_1") + model_ref = dataset_ref.model("model_1") + self.assertEqual(model_ref.project, "some-project-1") + self.assertEqual(model_ref.dataset_id, "dataset_1") + self.assertEqual(model_ref.model_id, "model_1") + def test_to_api_repr(self): dataset = self._make_one("project_1", "dataset_1") From ecc0f18c6391016a8673f74926185c4facc009e0 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 19 Mar 2019 12:58:31 -0700 Subject: [PATCH 4/8] Regen BigQuery Model API classes. (#493) * Regen BigQuery Model API classes. This commit is auto-generated by: SYNTHTOOL_GOOGLEAPIS=$HOME/src/googleapis-private python -m synthtool * Update test for Model to new representation of TrainingRun.startTime. --- .../google/cloud/bigquery_v2/gapic/enums.py | 16 + .../cloud/bigquery_v2/proto/model.proto | 66 ++- .../cloud/bigquery_v2/proto/model_pb2.py | 451 +++++++++++++++--- bigquery/google/cloud/bigquery_v2/types.py | 3 +- bigquery/synth.metadata | 2 +- bigquery/tests/unit/model/test_model.py | 22 +- 6 files changed, 477 insertions(+), 83 deletions(-) diff --git a/bigquery/google/cloud/bigquery_v2/gapic/enums.py b/bigquery/google/cloud/bigquery_v2/gapic/enums.py index 8ffe9f2b9a7a..69d3d670a628 100644 --- a/bigquery/google/cloud/bigquery_v2/gapic/enums.py +++ b/bigquery/google/cloud/bigquery_v2/gapic/enums.py @@ -40,6 +40,20 @@ class DataSplitMethod(enum.IntEnum): NO_SPLIT = 4 AUTO_SPLIT = 5 + class DistanceType(enum.IntEnum): + """ + Distance metric used to compute the distance between two points. + + Attributes: + DISTANCE_TYPE_UNSPECIFIED (int) + EUCLIDEAN (int): Eculidean distance. + COSINE (int): Cosine distance. + """ + + DISTANCE_TYPE_UNSPECIFIED = 0 + EUCLIDEAN = 1 + COSINE = 2 + class LearnRateStrategy(enum.IntEnum): """ Indicates the learning rate optimization strategy to use. @@ -76,11 +90,13 @@ class ModelType(enum.IntEnum): MODEL_TYPE_UNSPECIFIED (int) LINEAR_REGRESSION (int): Linear regression model. LOGISTIC_REGRESSION (int): Logistic regression model. + KMEANS (int): [Beta] K-means clustering model. """ MODEL_TYPE_UNSPECIFIED = 0 LINEAR_REGRESSION = 1 LOGISTIC_REGRESSION = 2 + KMEANS = 3 class StandardSqlDataType(object): diff --git a/bigquery/google/cloud/bigquery_v2/proto/model.proto b/bigquery/google/cloud/bigquery_v2/proto/model.proto index 6e50f8729a97..b94cb3f5efd5 100644 --- a/bigquery/google/cloud/bigquery_v2/proto/model.proto +++ b/bigquery/google/cloud/bigquery_v2/proto/model.proto @@ -20,7 +20,7 @@ package google.cloud.bigquery.v2; import "google/cloud/bigquery/v2/model_reference.proto"; import "google/cloud/bigquery/v2/standard_sql.proto"; import "google/protobuf/empty.proto"; -import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; import "google/protobuf/wrappers.proto"; import "google/api/annotations.proto"; @@ -176,6 +176,15 @@ message Model { repeated ConfusionMatrix confusion_matrix_list = 2; } + // Evaluation metrics for clustering models. + message ClusteringMetrics { + // Davies-Bouldin index. + google.protobuf.DoubleValue davies_bouldin_index = 1; + + // Mean of squared distances between each sample to its cluster centroid. + google.protobuf.DoubleValue mean_squared_distance = 2; + } + // Evaluation metrics of a model. These are either computed on all // training data or just the eval data based on whether eval data was used // during training. @@ -189,6 +198,9 @@ message Model { // Populated for multi-class classification models. MultiClassClassificationMetrics multi_class_classification_metrics = 3; + + // [Beta] Populated for clustering models. + ClusteringMetrics clustering_metrics = 4; } } @@ -254,10 +266,29 @@ message Model { // Weights associated with each label class, for rebalancing the // training data. map label_class_weights = 17; + + // [Beta] Distance type for clustering models. + DistanceType distance_type = 20; + + // [Beta] Number of clusters for clustering models. + int64 num_clusters = 21; } // Information about a single iteration of the training run. message IterationResult { + // Information about a single cluster for clustering model. + message ClusterInfo { + // Centroid id. + int64 centroid_id = 1; + + // Cluster radius, the average distance from centroid + // to each point assigned to the cluster. + google.protobuf.DoubleValue cluster_radius = 2; + + // Cluster size, the total number of points assigned to the cluster. + google.protobuf.Int64Value cluster_size = 3; + } + // Index of the iteration, 0 based. google.protobuf.Int32Value index = 1; @@ -272,14 +303,17 @@ message Model { // Learn rate used for this iteration. double learn_rate = 7; + + // [Beta] Information about top clusters for clustering models. + repeated ClusterInfo cluster_infos = 8; } // Options that were used for this training run, includes // user specified and default options that were used. TrainingOptions training_options = 1; - // The start time of this training run, in milliseconds since epoch. - int64 start_time = 2; + // The start time of this training run. + google.protobuf.Timestamp start_time = 8; // Output of each iteration run, results.size() <= max_iterations. repeated IterationResult results = 6; @@ -298,6 +332,9 @@ message Model { // Logistic regression model. LOGISTIC_REGRESSION = 2; + + // [Beta] K-means clustering model. + KMEANS = 3; } // Loss metric to evaluate model training performance. @@ -311,6 +348,17 @@ message Model { MEAN_LOG_LOSS = 2; } + // Distance metric used to compute the distance between two points. + enum DistanceType { + DISTANCE_TYPE_UNSPECIFIED = 0; + + // Eculidean distance. + EUCLIDEAN = 1; + + // Cosine distance. + COSINE = 2; + } + // Indicates the method to split input data into multiple tables. enum DataSplitMethod { DATA_SPLIT_METHOD_UNSPECIFIED = 0; @@ -413,13 +461,13 @@ message GetModelRequest { } message PatchModelRequest { - // Project ID of the model to patch + // Project ID of the model to patch. string project_id = 1; - // Dataset ID of the model to patch + // Dataset ID of the model to patch. string dataset_id = 2; - // Model ID of the model to patch + // Model ID of the model to patch. string model_id = 3; // Patched model. @@ -429,13 +477,13 @@ message PatchModelRequest { } message DeleteModelRequest { - // Project ID of the requested model. + // Project ID of the model to delete. string project_id = 1; - // Dataset ID of the requested model. + // Dataset ID of the model to delete. string dataset_id = 2; - // Model ID of the requested model. + // Model ID of the model to delete. string model_id = 3; } diff --git a/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py index 42660268ec54..afa3d8cf640d 100644 --- a/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py +++ b/bigquery/google/cloud/bigquery_v2/proto/model_pb2.py @@ -21,7 +21,7 @@ standard_sql_pb2 as google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2, ) from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 -from google.protobuf import field_mask_pb2 as google_dot_protobuf_dot_field__mask__pb2 +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2 from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 @@ -34,13 +34,13 @@ "\n\034com.google.cloud.bigquery.v2B\nModelProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigquery" ), serialized_pb=_b( - '\n*google/cloud/bigquery_v2/proto/model.proto\x12\x18google.cloud.bigquery.v2\x1a\x34google/cloud/bigquery_v2/proto/model_reference.proto\x1a\x31google/cloud/bigquery_v2/proto/standard_sql.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/api/annotations.proto"\xb1$\n\x05Model\x12\x0c\n\x04\x65tag\x18\x01 \x01(\t\x12\x41\n\x0fmodel_reference\x18\x02 \x01(\x0b\x32(.google.cloud.bigquery.v2.ModelReference\x12\x15\n\rcreation_time\x18\x05 \x01(\x03\x12\x1a\n\x12last_modified_time\x18\x06 \x01(\x03\x12\x13\n\x0b\x64\x65scription\x18\x0c \x01(\t\x12\x15\n\rfriendly_name\x18\x0e \x01(\t\x12;\n\x06labels\x18\x0f \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.LabelsEntry\x12\x17\n\x0f\x65xpiration_time\x18\x10 \x01(\x03\x12\x10\n\x08location\x18\r \x01(\t\x12=\n\nmodel_type\x18\x07 \x01(\x0e\x32).google.cloud.bigquery.v2.Model.ModelType\x12\x42\n\rtraining_runs\x18\t \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.TrainingRun\x12\x43\n\x0f\x66\x65\x61ture_columns\x18\n \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x12\x41\n\rlabel_columns\x18\x0b \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x1a\xb4\x02\n\x11RegressionMetrics\x12\x39\n\x13mean_absolute_error\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x38\n\x12mean_squared_error\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12<\n\x16mean_squared_log_error\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15median_absolute_error\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tr_squared\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\xef\x02\n\x1e\x41ggregateClassificationMetrics\x12/\n\tprecision\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x61\x63\x63uracy\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tthreshold\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x66\x31_score\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08log_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12-\n\x07roc_auc\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x8f\x05\n\x1b\x42inaryClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12w\n\x1c\x62inary_confusion_matrix_list\x18\x02 \x03(\x0b\x32Q.google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix\x1a\x8c\x03\n\x15\x42inaryConfusionMatrix\x12>\n\x18positive_class_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x33\n\x0etrue_positives\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_positives\x18\x03 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\x0etrue_negatives\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_negatives\x18\x05 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12/\n\tprecision\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x87\x05\n\x1fMultiClassClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12n\n\x15\x63onfusion_matrix_list\x18\x02 \x03(\x0b\x32O.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix\x1a\x89\x03\n\x0f\x43onfusionMatrix\x12:\n\x14\x63onfidence_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x61\n\x04rows\x18\x02 \x03(\x0b\x32S.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row\x1aQ\n\x05\x45ntry\x12\x17\n\x0fpredicted_label\x18\x01 \x01(\t\x12/\n\nitem_count\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x1a\x83\x01\n\x03Row\x12\x14\n\x0c\x61\x63tual_label\x18\x01 \x01(\t\x12\x66\n\x07\x65ntries\x18\x02 \x03(\x0b\x32U.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry\x1a\xc4\x02\n\x11\x45valuationMetrics\x12O\n\x12regression_metrics\x18\x01 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.RegressionMetricsH\x00\x12\x64\n\x1d\x62inary_classification_metrics\x18\x02 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.BinaryClassificationMetricsH\x00\x12m\n"multi_class_classification_metrics\x18\x03 \x01(\x0b\x32?.google.cloud.bigquery.v2.Model.MultiClassClassificationMetricsH\x00\x42\t\n\x07metrics\x1a\xca\n\n\x0bTrainingRun\x12U\n\x10training_options\x18\x01 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions\x12\x12\n\nstart_time\x18\x02 \x01(\x03\x12L\n\x07results\x18\x06 \x03(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.IterationResult\x12M\n\x12\x65valuation_metrics\x18\x07 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.EvaluationMetrics\x1a\xc6\x06\n\x0fTrainingOptions\x12\x16\n\x0emax_iterations\x18\x01 \x01(\x03\x12;\n\tloss_type\x18\x02 \x01(\x0e\x32(.google.cloud.bigquery.v2.Model.LossType\x12\x12\n\nlearn_rate\x18\x03 \x01(\x01\x12\x37\n\x11l1_regularization\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x37\n\x11l2_regularization\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15min_relative_progress\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\nwarm_start\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12.\n\nearly_stop\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x1b\n\x13input_label_columns\x18\t \x03(\t\x12J\n\x11\x64\x61ta_split_method\x18\n \x01(\x0e\x32/.google.cloud.bigquery.v2.Model.DataSplitMethod\x12 \n\x18\x64\x61ta_split_eval_fraction\x18\x0b \x01(\x01\x12\x19\n\x11\x64\x61ta_split_column\x18\x0c \x01(\t\x12N\n\x13learn_rate_strategy\x18\r \x01(\x0e\x32\x31.google.cloud.bigquery.v2.Model.LearnRateStrategy\x12\x1a\n\x12initial_learn_rate\x18\x10 \x01(\x01\x12o\n\x13label_class_weights\x18\x11 \x03(\x0b\x32R.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry\x1a\x38\n\x16LabelClassWeightsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\x1a\xe9\x01\n\x0fIterationResult\x12*\n\x05index\x18\x01 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x30\n\x0b\x64uration_ms\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\rtraining_loss\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\teval_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x12\n\nlearn_rate\x18\x07 \x01(\x01\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01"W\n\tModelType\x12\x1a\n\x16MODEL_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11LINEAR_REGRESSION\x10\x01\x12\x17\n\x13LOGISTIC_REGRESSION\x10\x02"O\n\x08LossType\x12\x19\n\x15LOSS_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11MEAN_SQUARED_LOSS\x10\x01\x12\x11\n\rMEAN_LOG_LOSS\x10\x02"z\n\x0f\x44\x61taSplitMethod\x12!\n\x1d\x44\x41TA_SPLIT_METHOD_UNSPECIFIED\x10\x00\x12\n\n\x06RANDOM\x10\x01\x12\n\n\x06\x43USTOM\x10\x02\x12\x0e\n\nSEQUENTIAL\x10\x03\x12\x0c\n\x08NO_SPLIT\x10\x04\x12\x0e\n\nAUTO_SPLIT\x10\x05"W\n\x11LearnRateStrategy\x12#\n\x1fLEARN_RATE_STRATEGY_UNSPECIFIED\x10\x00\x12\x0f\n\x0bLINE_SEARCH\x10\x01\x12\x0c\n\x08\x43ONSTANT\x10\x02"K\n\x0fGetModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"}\n\x11PatchModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t\x12.\n\x05model\x18\x04 \x01(\x0b\x32\x1f.google.cloud.bigquery.v2.Model"N\n\x12\x44\x65leteModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"\x82\x01\n\x11ListModelsRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x31\n\x0bmax_results\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt32Value\x12\x12\n\npage_token\x18\x04 \x01(\t"^\n\x12ListModelsResponse\x12/\n\x06models\x18\x01 \x03(\x0b\x32\x1f.google.cloud.bigquery.v2.Model\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t2\x88\x03\n\x0cModelService\x12X\n\x08GetModel\x12).google.cloud.bigquery.v2.GetModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12i\n\nListModels\x12+.google.cloud.bigquery.v2.ListModelsRequest\x1a,.google.cloud.bigquery.v2.ListModelsResponse"\x00\x12\\\n\nPatchModel\x12+.google.cloud.bigquery.v2.PatchModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12U\n\x0b\x44\x65leteModel\x12,.google.cloud.bigquery.v2.DeleteModelRequest\x1a\x16.google.protobuf.Empty"\x00\x42l\n\x1c\x63om.google.cloud.bigquery.v2B\nModelProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' + '\n*google/cloud/bigquery_v2/proto/model.proto\x12\x18google.cloud.bigquery.v2\x1a\x34google/cloud/bigquery_v2/proto/model_reference.proto\x1a\x31google/cloud/bigquery_v2/proto/standard_sql.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/api/annotations.proto"\xcc)\n\x05Model\x12\x0c\n\x04\x65tag\x18\x01 \x01(\t\x12\x41\n\x0fmodel_reference\x18\x02 \x01(\x0b\x32(.google.cloud.bigquery.v2.ModelReference\x12\x15\n\rcreation_time\x18\x05 \x01(\x03\x12\x1a\n\x12last_modified_time\x18\x06 \x01(\x03\x12\x13\n\x0b\x64\x65scription\x18\x0c \x01(\t\x12\x15\n\rfriendly_name\x18\x0e \x01(\t\x12;\n\x06labels\x18\x0f \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.LabelsEntry\x12\x17\n\x0f\x65xpiration_time\x18\x10 \x01(\x03\x12\x10\n\x08location\x18\r \x01(\t\x12=\n\nmodel_type\x18\x07 \x01(\x0e\x32).google.cloud.bigquery.v2.Model.ModelType\x12\x42\n\rtraining_runs\x18\t \x03(\x0b\x32+.google.cloud.bigquery.v2.Model.TrainingRun\x12\x43\n\x0f\x66\x65\x61ture_columns\x18\n \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x12\x41\n\rlabel_columns\x18\x0b \x03(\x0b\x32*.google.cloud.bigquery.v2.StandardSqlField\x1a\xb4\x02\n\x11RegressionMetrics\x12\x39\n\x13mean_absolute_error\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x38\n\x12mean_squared_error\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12<\n\x16mean_squared_log_error\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15median_absolute_error\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tr_squared\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\xef\x02\n\x1e\x41ggregateClassificationMetrics\x12/\n\tprecision\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x61\x63\x63uracy\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\tthreshold\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08\x66\x31_score\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\x08log_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12-\n\x07roc_auc\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x8f\x05\n\x1b\x42inaryClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12w\n\x1c\x62inary_confusion_matrix_list\x18\x02 \x03(\x0b\x32Q.google.cloud.bigquery.v2.Model.BinaryClassificationMetrics.BinaryConfusionMatrix\x1a\x8c\x03\n\x15\x42inaryConfusionMatrix\x12>\n\x18positive_class_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x33\n\x0etrue_positives\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_positives\x18\x03 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\x0etrue_negatives\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x34\n\x0f\x66\x61lse_negatives\x18\x05 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12/\n\tprecision\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12,\n\x06recall\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x87\x05\n\x1fMultiClassClassificationMetrics\x12h\n aggregate_classification_metrics\x18\x01 \x01(\x0b\x32>.google.cloud.bigquery.v2.Model.AggregateClassificationMetrics\x12n\n\x15\x63onfusion_matrix_list\x18\x02 \x03(\x0b\x32O.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix\x1a\x89\x03\n\x0f\x43onfusionMatrix\x12:\n\x14\x63onfidence_threshold\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x61\n\x04rows\x18\x02 \x03(\x0b\x32S.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row\x1aQ\n\x05\x45ntry\x12\x17\n\x0fpredicted_label\x18\x01 \x01(\t\x12/\n\nitem_count\x18\x02 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x1a\x83\x01\n\x03Row\x12\x14\n\x0c\x61\x63tual_label\x18\x01 \x01(\t\x12\x66\n\x07\x65ntries\x18\x02 \x03(\x0b\x32U.google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry\x1a\x8c\x01\n\x11\x43lusteringMetrics\x12:\n\x14\x64\x61vies_bouldin_index\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15mean_squared_distance\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x1a\x95\x03\n\x11\x45valuationMetrics\x12O\n\x12regression_metrics\x18\x01 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.RegressionMetricsH\x00\x12\x64\n\x1d\x62inary_classification_metrics\x18\x02 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.BinaryClassificationMetricsH\x00\x12m\n"multi_class_classification_metrics\x18\x03 \x01(\x0b\x32?.google.cloud.bigquery.v2.Model.MultiClassClassificationMetricsH\x00\x12O\n\x12\x63lustering_metrics\x18\x04 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.ClusteringMetricsH\x00\x42\t\n\x07metrics\x1a\xaf\r\n\x0bTrainingRun\x12U\n\x10training_options\x18\x01 \x01(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions\x12.\n\nstart_time\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12L\n\x07results\x18\x06 \x03(\x0b\x32;.google.cloud.bigquery.v2.Model.TrainingRun.IterationResult\x12M\n\x12\x65valuation_metrics\x18\x07 \x01(\x0b\x32\x31.google.cloud.bigquery.v2.Model.EvaluationMetrics\x1a\xa1\x07\n\x0fTrainingOptions\x12\x16\n\x0emax_iterations\x18\x01 \x01(\x03\x12;\n\tloss_type\x18\x02 \x01(\x0e\x32(.google.cloud.bigquery.v2.Model.LossType\x12\x12\n\nlearn_rate\x18\x03 \x01(\x01\x12\x37\n\x11l1_regularization\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x37\n\x11l2_regularization\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12;\n\x15min_relative_progress\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12.\n\nwarm_start\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12.\n\nearly_stop\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x1b\n\x13input_label_columns\x18\t \x03(\t\x12J\n\x11\x64\x61ta_split_method\x18\n \x01(\x0e\x32/.google.cloud.bigquery.v2.Model.DataSplitMethod\x12 \n\x18\x64\x61ta_split_eval_fraction\x18\x0b \x01(\x01\x12\x19\n\x11\x64\x61ta_split_column\x18\x0c \x01(\t\x12N\n\x13learn_rate_strategy\x18\r \x01(\x0e\x32\x31.google.cloud.bigquery.v2.Model.LearnRateStrategy\x12\x1a\n\x12initial_learn_rate\x18\x10 \x01(\x01\x12o\n\x13label_class_weights\x18\x11 \x03(\x0b\x32R.google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry\x12\x43\n\rdistance_type\x18\x14 \x01(\x0e\x32,.google.cloud.bigquery.v2.Model.DistanceType\x12\x14\n\x0cnum_clusters\x18\x15 \x01(\x03\x1a\x38\n\x16LabelClassWeightsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\x1a\xd7\x03\n\x0fIterationResult\x12*\n\x05index\x18\x01 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x30\n\x0b\x64uration_ms\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x12\x33\n\rtraining_loss\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12/\n\teval_loss\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x12\n\nlearn_rate\x18\x07 \x01(\x01\x12^\n\rcluster_infos\x18\x08 \x03(\x0b\x32G.google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo\x1a\x8b\x01\n\x0b\x43lusterInfo\x12\x13\n\x0b\x63\x65ntroid_id\x18\x01 \x01(\x03\x12\x34\n\x0e\x63luster_radius\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\x12\x31\n\x0c\x63luster_size\x18\x03 \x01(\x0b\x32\x1b.google.protobuf.Int64Value\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01"c\n\tModelType\x12\x1a\n\x16MODEL_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11LINEAR_REGRESSION\x10\x01\x12\x17\n\x13LOGISTIC_REGRESSION\x10\x02\x12\n\n\x06KMEANS\x10\x03"O\n\x08LossType\x12\x19\n\x15LOSS_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11MEAN_SQUARED_LOSS\x10\x01\x12\x11\n\rMEAN_LOG_LOSS\x10\x02"H\n\x0c\x44istanceType\x12\x1d\n\x19\x44ISTANCE_TYPE_UNSPECIFIED\x10\x00\x12\r\n\tEUCLIDEAN\x10\x01\x12\n\n\x06\x43OSINE\x10\x02"z\n\x0f\x44\x61taSplitMethod\x12!\n\x1d\x44\x41TA_SPLIT_METHOD_UNSPECIFIED\x10\x00\x12\n\n\x06RANDOM\x10\x01\x12\n\n\x06\x43USTOM\x10\x02\x12\x0e\n\nSEQUENTIAL\x10\x03\x12\x0c\n\x08NO_SPLIT\x10\x04\x12\x0e\n\nAUTO_SPLIT\x10\x05"W\n\x11LearnRateStrategy\x12#\n\x1fLEARN_RATE_STRATEGY_UNSPECIFIED\x10\x00\x12\x0f\n\x0bLINE_SEARCH\x10\x01\x12\x0c\n\x08\x43ONSTANT\x10\x02"K\n\x0fGetModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"}\n\x11PatchModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t\x12.\n\x05model\x18\x04 \x01(\x0b\x32\x1f.google.cloud.bigquery.v2.Model"N\n\x12\x44\x65leteModelRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x10\n\x08model_id\x18\x03 \x01(\t"\x82\x01\n\x11ListModelsRequest\x12\x12\n\nproject_id\x18\x01 \x01(\t\x12\x12\n\ndataset_id\x18\x02 \x01(\t\x12\x31\n\x0bmax_results\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt32Value\x12\x12\n\npage_token\x18\x04 \x01(\t"^\n\x12ListModelsResponse\x12/\n\x06models\x18\x01 \x03(\x0b\x32\x1f.google.cloud.bigquery.v2.Model\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t2\x88\x03\n\x0cModelService\x12X\n\x08GetModel\x12).google.cloud.bigquery.v2.GetModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12i\n\nListModels\x12+.google.cloud.bigquery.v2.ListModelsRequest\x1a,.google.cloud.bigquery.v2.ListModelsResponse"\x00\x12\\\n\nPatchModel\x12+.google.cloud.bigquery.v2.PatchModelRequest\x1a\x1f.google.cloud.bigquery.v2.Model"\x00\x12U\n\x0b\x44\x65leteModel\x12,.google.cloud.bigquery.v2.DeleteModelRequest\x1a\x16.google.protobuf.Empty"\x00\x42l\n\x1c\x63om.google.cloud.bigquery.v2B\nModelProtoZ@google.golang.org/genproto/googleapis/cloud/bigquery/v2;bigqueryb\x06proto3' ), dependencies=[ google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__reference__pb2.DESCRIPTOR, google_dot_cloud_dot_bigquery__v2_dot_proto_dot_standard__sql__pb2.DESCRIPTOR, google_dot_protobuf_dot_empty__pb2.DESCRIPTOR, - google_dot_protobuf_dot_field__mask__pb2.DESCRIPTOR, + google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR, google_dot_protobuf_dot_wrappers__pb2.DESCRIPTOR, google_dot_api_dot_annotations__pb2.DESCRIPTOR, ], @@ -74,11 +74,14 @@ serialized_options=None, type=None, ), + _descriptor.EnumValueDescriptor( + name="KMEANS", index=3, number=3, serialized_options=None, type=None + ), ], containing_type=None, serialized_options=None, - serialized_start=4579, - serialized_end=4666, + serialized_start=5159, + serialized_end=5258, ) _sym_db.RegisterEnumDescriptor(_MODEL_MODELTYPE) @@ -108,11 +111,38 @@ ], containing_type=None, serialized_options=None, - serialized_start=4668, - serialized_end=4747, + serialized_start=5260, + serialized_end=5339, ) _sym_db.RegisterEnumDescriptor(_MODEL_LOSSTYPE) +_MODEL_DISTANCETYPE = _descriptor.EnumDescriptor( + name="DistanceType", + full_name="google.cloud.bigquery.v2.Model.DistanceType", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="DISTANCE_TYPE_UNSPECIFIED", + index=0, + number=0, + serialized_options=None, + type=None, + ), + _descriptor.EnumValueDescriptor( + name="EUCLIDEAN", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="COSINE", index=2, number=2, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=5341, + serialized_end=5413, +) +_sym_db.RegisterEnumDescriptor(_MODEL_DISTANCETYPE) + _MODEL_DATASPLITMETHOD = _descriptor.EnumDescriptor( name="DataSplitMethod", full_name="google.cloud.bigquery.v2.Model.DataSplitMethod", @@ -144,8 +174,8 @@ ], containing_type=None, serialized_options=None, - serialized_start=4749, - serialized_end=4871, + serialized_start=5415, + serialized_end=5537, ) _sym_db.RegisterEnumDescriptor(_MODEL_DATASPLITMETHOD) @@ -171,8 +201,8 @@ ], containing_type=None, serialized_options=None, - serialized_start=4873, - serialized_end=4960, + serialized_start=5539, + serialized_end=5626, ) _sym_db.RegisterEnumDescriptor(_MODEL_LEARNRATESTRATEGY) @@ -283,8 +313,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=860, - serialized_end=1168, + serialized_start=859, + serialized_end=1167, ) _MODEL_AGGREGATECLASSIFICATIONMETRICS = _descriptor.Descriptor( @@ -429,8 +459,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=1171, - serialized_end=1538, + serialized_start=1170, + serialized_end=1537, ) _MODEL_BINARYCLASSIFICATIONMETRICS_BINARYCONFUSIONMATRIX = _descriptor.Descriptor( @@ -575,8 +605,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=1800, - serialized_end=2196, + serialized_start=1799, + serialized_end=2195, ) _MODEL_BINARYCLASSIFICATIONMETRICS = _descriptor.Descriptor( @@ -631,8 +661,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=1541, - serialized_end=2196, + serialized_start=1540, + serialized_end=2195, ) _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ENTRY = _descriptor.Descriptor( @@ -687,8 +717,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=2631, - serialized_end=2712, + serialized_start=2630, + serialized_end=2711, ) _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX_ROW = _descriptor.Descriptor( @@ -743,8 +773,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=2715, - serialized_end=2846, + serialized_start=2714, + serialized_end=2845, ) _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX = _descriptor.Descriptor( @@ -802,8 +832,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=2453, - serialized_end=2846, + serialized_start=2452, + serialized_end=2845, ) _MODEL_MULTICLASSCLASSIFICATIONMETRICS = _descriptor.Descriptor( @@ -858,8 +888,64 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=2199, - serialized_end=2846, + serialized_start=2198, + serialized_end=2845, +) + +_MODEL_CLUSTERINGMETRICS = _descriptor.Descriptor( + name="ClusteringMetrics", + full_name="google.cloud.bigquery.v2.Model.ClusteringMetrics", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="davies_bouldin_index", + full_name="google.cloud.bigquery.v2.Model.ClusteringMetrics.davies_bouldin_index", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="mean_squared_distance", + full_name="google.cloud.bigquery.v2.Model.ClusteringMetrics.mean_squared_distance", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=2848, + serialized_end=2988, ) _MODEL_EVALUATIONMETRICS = _descriptor.Descriptor( @@ -923,6 +1009,24 @@ serialized_options=None, file=DESCRIPTOR, ), + _descriptor.FieldDescriptor( + name="clustering_metrics", + full_name="google.cloud.bigquery.v2.Model.EvaluationMetrics.clustering_metrics", + index=3, + number=4, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), ], extensions=[], nested_types=[], @@ -940,8 +1044,8 @@ fields=[], ) ], - serialized_start=2849, - serialized_end=3173, + serialized_start=2991, + serialized_end=3396, ) _MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY = _descriptor.Descriptor( @@ -996,8 +1100,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=4238, - serialized_end=4294, + serialized_start=4580, + serialized_end=4636, ) _MODEL_TRAININGRUN_TRAININGOPTIONS = _descriptor.Descriptor( @@ -1277,6 +1381,42 @@ serialized_options=None, file=DESCRIPTOR, ), + _descriptor.FieldDescriptor( + name="distance_type", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.distance_type", + index=15, + number=20, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="num_clusters", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions.num_clusters", + index=16, + number=21, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), ], extensions=[], nested_types=[_MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY], @@ -1286,8 +1426,82 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=3456, - serialized_end=4294, + serialized_start=3707, + serialized_end=4636, +) + +_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO = _descriptor.Descriptor( + name="ClusterInfo", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="centroid_id", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo.centroid_id", + index=0, + number=1, + type=3, + cpp_type=2, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="cluster_radius", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo.cluster_radius", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="cluster_size", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo.cluster_size", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=4971, + serialized_end=5110, ) _MODEL_TRAININGRUN_ITERATIONRESULT = _descriptor.Descriptor( @@ -1387,17 +1601,35 @@ serialized_options=None, file=DESCRIPTOR, ), + _descriptor.FieldDescriptor( + name="cluster_infos", + full_name="google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.cluster_infos", + index=5, + number=8, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), ], extensions=[], - nested_types=[], + nested_types=[_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO], enum_types=[], serialized_options=None, is_extendable=False, syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=4297, - serialized_end=4530, + serialized_start=4639, + serialized_end=5110, ) _MODEL_TRAININGRUN = _descriptor.Descriptor( @@ -1429,12 +1661,12 @@ name="start_time", full_name="google.cloud.bigquery.v2.Model.TrainingRun.start_time", index=1, - number=2, - type=3, - cpp_type=2, + number=8, + type=11, + cpp_type=10, label=1, has_default_value=False, - default_value=0, + default_value=None, message_type=None, enum_type=None, containing_type=None, @@ -1491,8 +1723,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=3176, - serialized_end=4530, + serialized_start=3399, + serialized_end=5110, ) _MODEL_LABELSENTRY = _descriptor.Descriptor( @@ -1547,8 +1779,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=4532, - serialized_end=4577, + serialized_start=5112, + serialized_end=5157, ) _MODEL = _descriptor.Descriptor( @@ -1799,6 +2031,7 @@ _MODEL_AGGREGATECLASSIFICATIONMETRICS, _MODEL_BINARYCLASSIFICATIONMETRICS, _MODEL_MULTICLASSCLASSIFICATIONMETRICS, + _MODEL_CLUSTERINGMETRICS, _MODEL_EVALUATIONMETRICS, _MODEL_TRAININGRUN, _MODEL_LABELSENTRY, @@ -1806,6 +2039,7 @@ enum_types=[ _MODEL_MODELTYPE, _MODEL_LOSSTYPE, + _MODEL_DISTANCETYPE, _MODEL_DATASPLITMETHOD, _MODEL_LEARNRATESTRATEGY, ], @@ -1814,8 +2048,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=303, - serialized_end=4960, + serialized_start=302, + serialized_end=5626, ) @@ -1889,8 +2123,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=4962, - serialized_end=5037, + serialized_start=5628, + serialized_end=5703, ) @@ -1982,8 +2216,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=5039, - serialized_end=5164, + serialized_start=5705, + serialized_end=5830, ) @@ -2057,8 +2291,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=5166, - serialized_end=5244, + serialized_start=5832, + serialized_end=5910, ) @@ -2150,8 +2384,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=5247, - serialized_end=5377, + serialized_start=5913, + serialized_end=6043, ) @@ -2207,8 +2441,8 @@ syntax="proto3", extension_ranges=[], oneofs=[], - serialized_start=5379, - serialized_end=5473, + serialized_start=6045, + serialized_end=6139, ) _MODEL_REGRESSIONMETRICS.fields_by_name[ @@ -2308,6 +2542,13 @@ "confusion_matrix_list" ].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS_CONFUSIONMATRIX _MODEL_MULTICLASSCLASSIFICATIONMETRICS.containing_type = _MODEL +_MODEL_CLUSTERINGMETRICS.fields_by_name[ + "davies_bouldin_index" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_CLUSTERINGMETRICS.fields_by_name[ + "mean_squared_distance" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_CLUSTERINGMETRICS.containing_type = _MODEL _MODEL_EVALUATIONMETRICS.fields_by_name[ "regression_metrics" ].message_type = _MODEL_REGRESSIONMETRICS @@ -2317,6 +2558,9 @@ _MODEL_EVALUATIONMETRICS.fields_by_name[ "multi_class_classification_metrics" ].message_type = _MODEL_MULTICLASSCLASSIFICATIONMETRICS +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "clustering_metrics" +].message_type = _MODEL_CLUSTERINGMETRICS _MODEL_EVALUATIONMETRICS.containing_type = _MODEL _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"].fields.append( _MODEL_EVALUATIONMETRICS.fields_by_name["regression_metrics"] @@ -2336,6 +2580,12 @@ _MODEL_EVALUATIONMETRICS.fields_by_name[ "multi_class_classification_metrics" ].containing_oneof = _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"] +_MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"].fields.append( + _MODEL_EVALUATIONMETRICS.fields_by_name["clustering_metrics"] +) +_MODEL_EVALUATIONMETRICS.fields_by_name[ + "clustering_metrics" +].containing_oneof = _MODEL_EVALUATIONMETRICS.oneofs_by_name["metrics"] _MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY.containing_type = ( _MODEL_TRAININGRUN_TRAININGOPTIONS ) @@ -2366,7 +2616,19 @@ _MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ "label_class_weights" ].message_type = _MODEL_TRAININGRUN_TRAININGOPTIONS_LABELCLASSWEIGHTSENTRY +_MODEL_TRAININGRUN_TRAININGOPTIONS.fields_by_name[ + "distance_type" +].enum_type = _MODEL_DISTANCETYPE _MODEL_TRAININGRUN_TRAININGOPTIONS.containing_type = _MODEL_TRAININGRUN +_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO.fields_by_name[ + "cluster_radius" +].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO.fields_by_name[ + "cluster_size" +].message_type = google_dot_protobuf_dot_wrappers__pb2._INT64VALUE +_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO.containing_type = ( + _MODEL_TRAININGRUN_ITERATIONRESULT +) _MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ "index" ].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE @@ -2379,10 +2641,16 @@ _MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ "eval_loss" ].message_type = google_dot_protobuf_dot_wrappers__pb2._DOUBLEVALUE +_MODEL_TRAININGRUN_ITERATIONRESULT.fields_by_name[ + "cluster_infos" +].message_type = _MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO _MODEL_TRAININGRUN_ITERATIONRESULT.containing_type = _MODEL_TRAININGRUN _MODEL_TRAININGRUN.fields_by_name[ "training_options" ].message_type = _MODEL_TRAININGRUN_TRAININGOPTIONS +_MODEL_TRAININGRUN.fields_by_name[ + "start_time" +].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP _MODEL_TRAININGRUN.fields_by_name[ "results" ].message_type = _MODEL_TRAININGRUN_ITERATIONRESULT @@ -2411,6 +2679,7 @@ ) _MODEL_MODELTYPE.containing_type = _MODEL _MODEL_LOSSTYPE.containing_type = _MODEL +_MODEL_DISTANCETYPE.containing_type = _MODEL _MODEL_DATASPLITMETHOD.containing_type = _MODEL _MODEL_LEARNRATESTRATEGY.containing_type = _MODEL _PATCHMODELREQUEST.fields_by_name["model"].message_type = _MODEL @@ -2619,6 +2888,25 @@ # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.MultiClassClassificationMetrics) ), ), + ClusteringMetrics=_reflection.GeneratedProtocolMessageType( + "ClusteringMetrics", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_CLUSTERINGMETRICS, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Evaluation metrics for clustering models. + + + Attributes: + davies_bouldin_index: + Davies-Bouldin index. + mean_squared_distance: + Mean of squared distances between each sample to its cluster + centroid. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.ClusteringMetrics) + ), + ), EvaluationMetrics=_reflection.GeneratedProtocolMessageType( "EvaluationMetrics", (_message.Message,), @@ -2637,6 +2925,8 @@ Populated for binary classification models. multi_class_classification_metrics: Populated for multi-class classification models. + clustering_metrics: + [Beta] Populated for clustering models. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.EvaluationMetrics) ), @@ -2710,6 +3000,10 @@ label_class_weights: Weights associated with each label class, for rebalancing the training data. + distance_type: + [Beta] Distance type for clustering models. + num_clusters: + [Beta] Number of clusters for clustering models. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.TrainingOptions) ), @@ -2718,6 +3012,28 @@ "IterationResult", (_message.Message,), dict( + ClusterInfo=_reflection.GeneratedProtocolMessageType( + "ClusterInfo", + (_message.Message,), + dict( + DESCRIPTOR=_MODEL_TRAININGRUN_ITERATIONRESULT_CLUSTERINFO, + __module__="google.cloud.bigquery_v2.proto.model_pb2", + __doc__="""Information about a single cluster for clustering model. + + + Attributes: + centroid_id: + Centroid id. + cluster_radius: + Cluster radius, the average distance from centroid to each + point assigned to the cluster. + cluster_size: + Cluster size, the total number of points assigned to the + cluster. + """, + # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.IterationResult.ClusterInfo) + ), + ), DESCRIPTOR=_MODEL_TRAININGRUN_ITERATIONRESULT, __module__="google.cloud.bigquery_v2.proto.model_pb2", __doc__="""Information about a single iteration of the training run. @@ -2734,6 +3050,8 @@ Loss computed on the eval data at the end of iteration. learn_rate: Learn rate used for this iteration. + cluster_infos: + [Beta] Information about top clusters for clustering models. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.Model.TrainingRun.IterationResult) ), @@ -2748,8 +3066,7 @@ Options that were used for this training run, includes user specified and default options that were used. start_time: - The start time of this training run, in milliseconds since - epoch. + The start time of this training run. results: Output of each iteration run, results.size() <= max\_iterations. @@ -2835,11 +3152,13 @@ _sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix) _sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry) _sym_db.RegisterMessage(Model.MultiClassClassificationMetrics.ConfusionMatrix.Row) +_sym_db.RegisterMessage(Model.ClusteringMetrics) _sym_db.RegisterMessage(Model.EvaluationMetrics) _sym_db.RegisterMessage(Model.TrainingRun) _sym_db.RegisterMessage(Model.TrainingRun.TrainingOptions) _sym_db.RegisterMessage(Model.TrainingRun.TrainingOptions.LabelClassWeightsEntry) _sym_db.RegisterMessage(Model.TrainingRun.IterationResult) +_sym_db.RegisterMessage(Model.TrainingRun.IterationResult.ClusterInfo) _sym_db.RegisterMessage(Model.LabelsEntry) GetModelRequest = _reflection.GeneratedProtocolMessageType( @@ -2873,11 +3192,11 @@ Attributes: project_id: - Project ID of the model to patch + Project ID of the model to patch. dataset_id: - Dataset ID of the model to patch + Dataset ID of the model to patch. model_id: - Model ID of the model to patch + Model ID of the model to patch. model: Patched model. Follows patch semantics. Missing fields are not updated. To clear a field, explicitly set to default value. @@ -2897,11 +3216,11 @@ Attributes: project_id: - Project ID of the requested model. + Project ID of the model to delete. dataset_id: - Dataset ID of the requested model. + Dataset ID of the model to delete. model_id: - Model ID of the requested model. + Model ID of the model to delete. """, # @@protoc_insertion_point(class_scope:google.cloud.bigquery.v2.DeleteModelRequest) ), @@ -2964,8 +3283,8 @@ file=DESCRIPTOR, index=0, serialized_options=None, - serialized_start=5476, - serialized_end=5868, + serialized_start=6142, + serialized_end=6534, methods=[ _descriptor.MethodDescriptor( name="GetModel", diff --git a/bigquery/google/cloud/bigquery_v2/types.py b/bigquery/google/cloud/bigquery_v2/types.py index 3a0be08718ae..939fa8b58b6e 100644 --- a/bigquery/google/cloud/bigquery_v2/types.py +++ b/bigquery/google/cloud/bigquery_v2/types.py @@ -24,9 +24,10 @@ from google.cloud.bigquery_v2.proto import model_reference_pb2 from google.cloud.bigquery_v2.proto import standard_sql_pb2 from google.protobuf import empty_pb2 +from google.protobuf import timestamp_pb2 from google.protobuf import wrappers_pb2 -_shared_modules = [empty_pb2, wrappers_pb2] +_shared_modules = [empty_pb2, timestamp_pb2, wrappers_pb2] _local_modules = [ location_metadata_pb2, diff --git a/bigquery/synth.metadata b/bigquery/synth.metadata index 4fc1eea2ab89..ee179d1f093b 100644 --- a/bigquery/synth.metadata +++ b/bigquery/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-03-13T16:39:59.875284Z", + "updateTime": "2019-03-18T17:05:16.055644Z", "sources": [ { "generator": { diff --git a/bigquery/tests/unit/model/test_model.py b/bigquery/tests/unit/model/test_model.py index 26008453e64e..87da266a76bc 100644 --- a/bigquery/tests/unit/model/test_model.py +++ b/bigquery/tests/unit/model/test_model.py @@ -81,11 +81,15 @@ def test_from_api_repr(target_class): "trainingRuns": [ { "trainingOptions": {"initialLearnRate": 1.0}, - "startTime": str(google.cloud._helpers._millis(creation_time)), + "startTime": str( + google.cloud._helpers._datetime_to_rfc3339(creation_time) + ), }, { "trainingOptions": {"initialLearnRate": 0.5}, - "startTime": str(google.cloud._helpers._millis(modified_time)), + "startTime": str( + google.cloud._helpers._datetime_to_rfc3339(modified_time) + ), }, ], "featureColumns": [], @@ -103,12 +107,18 @@ def test_from_api_repr(target_class): assert got.model_type == enums.Model.ModelType.LOGISTIC_REGRESSION assert got.labels == {"greeting": u"こんにちは"} assert got.training_runs[0].training_options.initial_learn_rate == 1.0 - assert got.training_runs[0].start_time == google.cloud._helpers._millis( - creation_time + assert ( + got.training_runs[0] + .start_time.ToDatetime() + .replace(tzinfo=google.cloud._helpers.UTC) + == creation_time ) assert got.training_runs[1].training_options.initial_learn_rate == 0.5 - assert got.training_runs[1].start_time == google.cloud._helpers._millis( - modified_time + assert ( + got.training_runs[1] + .start_time.ToDatetime() + .replace(tzinfo=google.cloud._helpers.UTC) + == modified_time ) From 8d29dcd8050d202db2e96a4ab9a29560b6889137 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 21 Mar 2019 10:18:10 -0700 Subject: [PATCH 5/8] Add client methods for Models API. (#494) * Add client methods for Models API. * Adds hack to workaround milliseconds format for model.trainingRun.startTime. * Adds code samples for Models API, which double as system tests. --- bigquery/google/cloud/bigquery/client.py | 171 ++++++++++++ bigquery/google/cloud/bigquery/model.py | 45 +++- bigquery/noxfile.py | 3 + bigquery/samples/__init__.py | 0 bigquery/samples/delete_model.py | 31 +++ bigquery/samples/get_model.py | 35 +++ bigquery/samples/list_models.py | 38 +++ bigquery/samples/tests/__init__.py | 0 bigquery/samples/tests/conftest.py | 62 +++++ bigquery/samples/tests/test_model_samples.py | 39 +++ bigquery/samples/update_model.py | 38 +++ bigquery/tests/unit/model/test_model.py | 17 ++ .../tests/unit/model/test_model_reference.py | 4 + bigquery/tests/unit/test_client.py | 244 ++++++++++++++++++ 14 files changed, 725 insertions(+), 2 deletions(-) create mode 100644 bigquery/samples/__init__.py create mode 100644 bigquery/samples/delete_model.py create mode 100644 bigquery/samples/get_model.py create mode 100644 bigquery/samples/list_models.py create mode 100644 bigquery/samples/tests/__init__.py create mode 100644 bigquery/samples/tests/conftest.py create mode 100644 bigquery/samples/tests/test_model_samples.py create mode 100644 bigquery/samples/update_model.py diff --git a/bigquery/google/cloud/bigquery/client.py b/bigquery/google/cloud/bigquery/client.py index 7fe412478bfa..6ad3227a226b 100644 --- a/bigquery/google/cloud/bigquery/client.py +++ b/bigquery/google/cloud/bigquery/client.py @@ -46,6 +46,8 @@ from google.cloud.bigquery.dataset import DatasetListItem from google.cloud.bigquery.dataset import DatasetReference from google.cloud.bigquery import job +from google.cloud.bigquery.model import Model +from google.cloud.bigquery.model import ModelReference from google.cloud.bigquery.query import _QueryResults from google.cloud.bigquery.retry import DEFAULT_RETRY from google.cloud.bigquery.table import Table @@ -427,6 +429,33 @@ def get_dataset(self, dataset_ref, retry=DEFAULT_RETRY): api_response = self._call_api(retry, method="GET", path=dataset_ref.path) return Dataset.from_api_repr(api_response) + def get_model(self, model_ref, retry=DEFAULT_RETRY): + """Fetch the model referenced by ``model_ref``. + + Args: + model_ref (Union[ \ + :class:`~google.cloud.bigquery.model.ModelReference`, \ + str, \ + ]): + A reference to the model to fetch from the BigQuery API. + If a string is passed in, this method attempts to create a + model reference from a string using + :func:`google.cloud.bigquery.model.ModelReference.from_string`. + retry (:class:`google.api_core.retry.Retry`): + (Optional) How to retry the RPC. + + Returns: + google.cloud.bigquery.model.Model: + A ``Model`` instance. + """ + if isinstance(model_ref, str): + model_ref = ModelReference.from_string( + model_ref, default_project=self.project + ) + + api_response = self._call_api(retry, method="GET", path=model_ref.path) + return Model.from_api_repr(api_response) + def get_table(self, table_ref, retry=DEFAULT_RETRY): """Fetch the table referenced by ``table_ref``. @@ -490,6 +519,41 @@ def update_dataset(self, dataset, fields, retry=DEFAULT_RETRY): ) return Dataset.from_api_repr(api_response) + def update_model(self, model, fields, retry=DEFAULT_RETRY): + """Change some fields of a model. + + Use ``fields`` to specify which fields to update. At least one field + must be provided. If a field is listed in ``fields`` and is ``None`` + in ``model``, it will be deleted. + + If ``model.etag`` is not ``None``, the update will only succeed if + the model on the server has the same ETag. Thus reading a model with + ``get_model``, changing its fields, and then passing it to + ``update_model`` will ensure that the changes will only be saved if + no modifications to the model occurred since the read. + + Args: + model (google.cloud.bigquery.model.Model): The model to update. + fields (Sequence[str]): + The fields of ``model`` to change, spelled as the Model + properties (e.g. "friendly_name"). + retry (google.api_core.retry.Retry): + (Optional) A description of how to retry the API call. + + Returns: + google.cloud.bigquery.model.Model: + The model resource returned from the API call. + """ + partial = model._build_resource(fields) + if model.etag: + headers = {"If-Match": model.etag} + else: + headers = None + api_response = self._call_api( + retry, method="PATCH", path=model.path, data=partial, headers=headers + ) + return Model.from_api_repr(api_response) + def update_table(self, table, fields, retry=DEFAULT_RETRY): """Change some fields of a table. @@ -525,6 +589,64 @@ def update_table(self, table, fields, retry=DEFAULT_RETRY): ) return Table.from_api_repr(api_response) + def list_models( + self, dataset, max_results=None, page_token=None, retry=DEFAULT_RETRY + ): + """List models in the dataset. + + See + https://cloud.google.com/bigquery/docs/reference/rest/v2/models/list + + Args: + dataset (Union[ \ + :class:`~google.cloud.bigquery.dataset.Dataset`, \ + :class:`~google.cloud.bigquery.dataset.DatasetReference`, \ + str, \ + ]): + A reference to the dataset whose models to list from the + BigQuery API. If a string is passed in, this method attempts + to create a dataset reference from a string using + :func:`google.cloud.bigquery.dataset.DatasetReference.from_string`. + max_results (int): + (Optional) Maximum number of models to return. If not passed, + defaults to a value set by the API. + page_token (str): + (Optional) Token representing a cursor into the models. If + not passed, the API will return the first page of models. The + token marks the beginning of the iterator to be returned and + the value of the ``page_token`` can be accessed at + ``next_page_token`` of the + :class:`~google.api_core.page_iterator.HTTPIterator`. + retry (:class:`google.api_core.retry.Retry`): + (Optional) How to retry the RPC. + + Returns: + google.api_core.page_iterator.Iterator: + Iterator of + :class:`~google.cloud.bigquery.model.Model` contained + within the requested dataset. + """ + if isinstance(dataset, str): + dataset = DatasetReference.from_string( + dataset, default_project=self.project + ) + + if not isinstance(dataset, (Dataset, DatasetReference)): + raise TypeError("dataset must be a Dataset, DatasetReference, or string") + + path = "%s/models" % dataset.path + result = page_iterator.HTTPIterator( + client=self, + api_request=functools.partial(self._call_api, retry), + path=path, + item_to_value=_item_to_model, + items_key="models", + page_token=page_token, + max_results=max_results, + ) + result.dataset = dataset + return result + def list_tables( self, dataset, max_results=None, page_token=None, retry=DEFAULT_RETRY ): @@ -631,6 +753,40 @@ def delete_dataset( if not not_found_ok: raise + def delete_model(self, model, retry=DEFAULT_RETRY, not_found_ok=False): + """Delete a model + + See + https://cloud.google.com/bigquery/docs/reference/rest/v2/models/delete + + Args: + model (Union[ \ + :class:`~google.cloud.bigquery.model.Model`, \ + :class:`~google.cloud.bigquery.model.ModelReference`, \ + str, \ + ]): + A reference to the model to delete. If a string is passed in, + this method attempts to create a model reference from a + string using + :func:`google.cloud.bigquery.model.ModelReference.from_string`. + retry (:class:`google.api_core.retry.Retry`): + (Optional) How to retry the RPC. + not_found_ok (bool): + Defaults to ``False``. If ``True``, ignore "not found" errors + when deleting the model. + """ + if isinstance(model, str): + model = ModelReference.from_string(model, default_project=self.project) + + if not isinstance(model, (Model, ModelReference)): + raise TypeError("model must be a Model or a ModelReference") + + try: + self._call_api(retry, method="DELETE", path=model.path) + except google.api_core.exceptions.NotFound: + if not not_found_ok: + raise + def delete_table(self, table, retry=DEFAULT_RETRY, not_found_ok=False): """Delete a table @@ -1810,6 +1966,21 @@ def _item_to_job(iterator, resource): return iterator.client.job_from_resource(resource) +def _item_to_model(iterator, resource): + """Convert a JSON model to the native object. + + Args: + iterator (google.api_core.page_iterator.Iterator): + The iterator that is currently in use. + resource (dict): + An item to be converted to a model. + + Returns: + google.cloud.bigquery.model.Model: The next model in the page. + """ + return Model.from_api_repr(resource) + + def _item_to_table(iterator, resource): """Convert a JSON table to the native object. diff --git a/bigquery/google/cloud/bigquery/model.py b/bigquery/google/cloud/bigquery/model.py index 5d9ec810b2d0..c89727cf1fb5 100644 --- a/bigquery/google/cloud/bigquery/model.py +++ b/bigquery/google/cloud/bigquery/model.py @@ -16,12 +16,13 @@ """Define resources for the BigQuery ML Models API.""" -import datetime +import copy from google.protobuf import json_format import six import google.cloud._helpers +from google.api_core import datetime_helpers from google.cloud.bigquery import _helpers from google.cloud.bigquery_v2 import types @@ -83,6 +84,26 @@ def reference(self): ref._proto = self._proto.model_reference return ref + @property + def project(self): + """str: Project bound to the model""" + return self.reference.project + + @property + def dataset_id(self): + """str: ID of dataset containing the model.""" + return self.reference.dataset_id + + @property + def model_id(self): + """str: The model ID.""" + return self.reference.model_id + + @property + def path(self): + """str: URL path for the model's APIs.""" + return self.reference.path + @property def location(self): """str: The geographic location where the model resides. This value @@ -192,7 +213,7 @@ def expires(self): @expires.setter def expires(self, value): if value is not None: - value = google.cloud._helpers._millis_from_datetime(value) + value = str(google.cloud._helpers._millis_from_datetime(value)) self._properties["expirationTime"] = value @property @@ -247,6 +268,17 @@ def from_api_repr(cls, resource): google.cloud.bigquery.model.Model: Model parsed from ``resource``. """ this = cls(None) + + # Convert from millis-from-epoch to timestamp well-known type. + # TODO: Remove this hack once CL 238585470 hits prod. + resource = copy.deepcopy(resource) + for training_run in resource.get("trainingRuns", ()): + start_time = training_run.get("startTime") + if not start_time or "-" in start_time: # Already right format? + continue + start_time = datetime_helpers.from_microseconds(1e3 * float(start_time)) + training_run["startTime"] = datetime_helpers.to_rfc3339(start_time) + this._proto = json_format.ParseDict(resource, types.Model()) for key in six.itervalues(cls._PROPERTY_TO_API_FIELD): # Leave missing keys unset. This allows us to use setdefault in the @@ -288,6 +320,15 @@ def model_id(self): """str: The model ID.""" return self._proto.model_id + @property + def path(self): + """str: URL path for the model's APIs.""" + return "/projects/%s/datasets/%s/models/%s" % ( + self._proto.project_id, + self._proto.dataset_id, + self._proto.model_id, + ) + @classmethod def from_api_repr(cls, resource): """Factory: construct a model reference given its API representation diff --git a/bigquery/noxfile.py b/bigquery/noxfile.py index 82846604306e..cb784eae9fa3 100644 --- a/bigquery/noxfile.py +++ b/bigquery/noxfile.py @@ -129,6 +129,8 @@ def snippets(session): # Run py.test against the snippets tests. session.run( 'py.test', os.path.join('docs', 'snippets.py'), *session.posargs) + session.run( + 'py.test', os.path.join('samples'), *session.posargs) @nox.session(python='3.6') @@ -178,6 +180,7 @@ def blacken(session): session.run( "black", "google", + "samples", "tests", "docs", ) diff --git a/bigquery/samples/__init__.py b/bigquery/samples/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/bigquery/samples/delete_model.py b/bigquery/samples/delete_model.py new file mode 100644 index 000000000000..dfe23cd7ef29 --- /dev/null +++ b/bigquery/samples/delete_model.py @@ -0,0 +1,31 @@ +# Copyright 2019 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. + + +def delete_model(client, model_id): + """Sample ID: go/samples-tracker/1534""" + + # [START bigquery_delete_model] + from google.cloud import bigquery + + # TODO(developer): Construct a BigQuery client object. + # client = bigquery.Client() + + # TODO(developer): Set model_id to the ID of the model to fetch. + # model_id = 'your-project.your_dataset.your_model' + + client.delete_model(model_id) + # [END bigquery_delete_model] + + print("Deleted model '{}'.".format(model_id)) diff --git a/bigquery/samples/get_model.py b/bigquery/samples/get_model.py new file mode 100644 index 000000000000..8e43e53ec450 --- /dev/null +++ b/bigquery/samples/get_model.py @@ -0,0 +1,35 @@ +# Copyright 2019 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. + + +def get_model(client, model_id): + """Sample ID: go/samples-tracker/1510""" + + # [START bigquery_get_model] + from google.cloud import bigquery + + # TODO(developer): Construct a BigQuery client object. + # client = bigquery.Client() + + # TODO(developer): Set model_id to the ID of the model to fetch. + # model_id = 'your-project.your_dataset.your_model' + + model = client.get_model(model_id) + + full_model_id = "{}.{}.{}".format(model.project, model.dataset_id, model.model_id) + friendly_name = model.friendly_name + print( + "Got model '{}' with friendly_name '{}'.".format(full_model_id, friendly_name) + ) + # [END bigquery_get_model] diff --git a/bigquery/samples/list_models.py b/bigquery/samples/list_models.py new file mode 100644 index 000000000000..cb6e4fb5569f --- /dev/null +++ b/bigquery/samples/list_models.py @@ -0,0 +1,38 @@ +# Copyright 2019 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. + + +def list_models(client, dataset_id): + """Sample ID: go/samples-tracker/1512""" + + # [START bigquery_list_models] + from google.cloud import bigquery + + # TODO(developer): Construct a BigQuery client object. + # client = bigquery.Client() + + # TODO(developer): Set dataset_id to the ID of the dataset that contains + # the models you are listing. + # dataset_id = 'your-project.your_dataset' + + models = client.list_models(dataset_id) + + print("Models contained in '{}':".format(dataset_id)) + for model in models: + full_model_id = "{}.{}.{}".format( + model.project, model.dataset_id, model.model_id + ) + friendly_name = model.friendly_name + print("{}: friendly_name='{}'".format(full_model_id, friendly_name)) + # [END bigquery_list_models] diff --git a/bigquery/samples/tests/__init__.py b/bigquery/samples/tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/bigquery/samples/tests/conftest.py b/bigquery/samples/tests/conftest.py new file mode 100644 index 000000000000..1543e1fdcd0a --- /dev/null +++ b/bigquery/samples/tests/conftest.py @@ -0,0 +1,62 @@ +# Copyright 2019 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. + +import datetime +import uuid + +import pytest + +from google.cloud import bigquery + + +@pytest.fixture(scope="module") +def client(): + return bigquery.Client() + + +@pytest.fixture +def dataset_id(client): + now = datetime.datetime.now() + dataset_id = "python_samples_{}_{}".format( + now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8] + ) + dataset = client.create_dataset(dataset_id) + yield "{}.{}".format(dataset.project, dataset.dataset_id) + client.delete_dataset(dataset, delete_contents=True) + + +@pytest.fixture +def model_id(client, dataset_id): + model_id = "{}.{}".format(dataset_id, uuid.uuid4().hex) + + # The only way to create a model resource is via SQL. + # Use a very small dataset (2 points), to train a model quickly. + sql = """ + CREATE MODEL `{}` + OPTIONS ( + model_type='linear_reg', + max_iteration=1, + learn_rate=0.4, + learn_rate_strategy='constant' + ) AS ( + SELECT 'a' AS f1, 2.0 AS label + UNION ALL + SELECT 'b' AS f1, 3.8 AS label + ) + """.format( + model_id + ) + + client.query(sql).result() + return model_id diff --git a/bigquery/samples/tests/test_model_samples.py b/bigquery/samples/tests/test_model_samples.py new file mode 100644 index 000000000000..d7b06a92a3e1 --- /dev/null +++ b/bigquery/samples/tests/test_model_samples.py @@ -0,0 +1,39 @@ +# Copyright 2019 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. + +from .. import delete_model +from .. import get_model +from .. import list_models +from .. import update_model + + +def test_model_samples(capsys, client, dataset_id, model_id): + """Since creating a model is a long operation, test all model samples in + the same test, following a typical end-to-end flow. + """ + get_model.get_model(client, model_id) + out, err = capsys.readouterr() + assert model_id in out + + list_models.list_models(client, dataset_id) + out, err = capsys.readouterr() + assert "Models contained in '{}':".format(dataset_id) in out + + update_model.update_model(client, model_id) + out, err = capsys.readouterr() + assert "This model was modified from a Python program." in out + + delete_model.delete_model(client, model_id) + out, err = capsys.readouterr() + assert "Deleted model '{}'.".format(model_id) in out diff --git a/bigquery/samples/update_model.py b/bigquery/samples/update_model.py new file mode 100644 index 000000000000..2440066ae1ec --- /dev/null +++ b/bigquery/samples/update_model.py @@ -0,0 +1,38 @@ +# Copyright 2019 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. + + +def update_model(client, model_id): + """Sample ID: go/samples-tracker/1533""" + + # [START bigquery_update_model_description] + from google.cloud import bigquery + + # TODO(developer): Construct a BigQuery client object. + # client = bigquery.Client() + + # TODO(developer): Set model_id to the ID of the model to fetch. + # model_id = 'your-project.your_dataset.your_model' + + model = client.get_model(model_id) + model.description = "This model was modified from a Python program." + model = client.update_model(model, ["description"]) + + full_model_id = "{}.{}.{}".format(model.project, model.dataset_id, model.model_id) + print( + "Updated model '{}' with description '{}'.".format( + full_model_id, model.description + ) + ) + # [END bigquery_update_model_description] diff --git a/bigquery/tests/unit/model/test_model.py b/bigquery/tests/unit/model/test_model.py index 87da266a76bc..2086c333486d 100644 --- a/bigquery/tests/unit/model/test_model.py +++ b/bigquery/tests/unit/model/test_model.py @@ -91,12 +91,22 @@ def test_from_api_repr(target_class): google.cloud._helpers._datetime_to_rfc3339(modified_time) ), }, + { + "trainingOptions": {"initialLearnRate": 0.25}, + # Allow milliseconds since epoch format. + # TODO: Remove this hack once CL 238585470 hits prod. + "startTime": str(google.cloud._helpers._millis(expiration_time)), + }, ], "featureColumns": [], } got = target_class.from_api_repr(resource) + assert got.project == "my-project" + assert got.dataset_id == "my_dataset" + assert got.model_id == "my_model" assert got.reference == ModelReference.from_string("my-project.my_dataset.my_model") + assert got.path == "/projects/my-project/datasets/my_dataset/models/my_model" assert got.location == "US" assert got.etag == "abcdefg" assert got.created == creation_time @@ -120,6 +130,13 @@ def test_from_api_repr(target_class): .replace(tzinfo=google.cloud._helpers.UTC) == modified_time ) + assert got.training_runs[2].training_options.initial_learn_rate == 0.25 + assert ( + got.training_runs[2] + .start_time.ToDatetime() + .replace(tzinfo=google.cloud._helpers.UTC) + == expiration_time + ) def test_from_api_repr_w_minimal_resource(target_class): diff --git a/bigquery/tests/unit/model/test_model_reference.py b/bigquery/tests/unit/model/test_model_reference.py index ea8a76fb14b6..0145c76f6ad0 100644 --- a/bigquery/tests/unit/model/test_model_reference.py +++ b/bigquery/tests/unit/model/test_model_reference.py @@ -34,6 +34,7 @@ def test_from_api_repr(target_class): assert got.project == "my-project" assert got.dataset_id == "my_dataset" assert got.model_id == "my_model" + assert got.path == "/projects/my-project/datasets/my_dataset/models/my_model" def test_to_api_repr(target_class): @@ -51,6 +52,9 @@ def test_from_string(target_class): assert got.project == "string-project" assert got.dataset_id == "string_dataset" assert got.model_id == "string_model" + assert got.path == ( + "/projects/string-project/datasets/string_dataset/models/string_model" + ) def test_from_string_legacy_string(target_class): diff --git a/bigquery/tests/unit/test_client.py b/bigquery/tests/unit/test_client.py index 794b76a0a9f4..08648419393b 100644 --- a/bigquery/tests/unit/test_client.py +++ b/bigquery/tests/unit/test_client.py @@ -37,6 +37,7 @@ pyarrow = None import google.api_core.exceptions +import google.cloud._helpers from google.cloud.bigquery.dataset import DatasetReference @@ -81,6 +82,7 @@ class TestClient(unittest.TestCase): PROJECT = "PROJECT" DS_ID = "DATASET_ID" TABLE_ID = "TABLE_ID" + MODEL_ID = "MODEL_ID" TABLE_REF = DatasetReference(PROJECT, DS_ID).table(TABLE_ID) KMS_KEY_NAME = "projects/1/locations/global/keyRings/1/cryptoKeys/1" LOCATION = "us-central" @@ -1306,6 +1308,54 @@ def test_create_table_alreadyexists_w_exists_ok_true(self): ] ) + def test_get_model(self): + path = "projects/%s/datasets/%s/models/%s" % ( + self.PROJECT, + self.DS_ID, + self.MODEL_ID, + ) + creds = _make_credentials() + http = object() + client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) + resource = { + "modelReference": { + "projectId": self.PROJECT, + "datasetId": self.DS_ID, + "modelId": self.MODEL_ID, + } + } + conn = client._connection = _make_connection(resource) + + model_ref = client.dataset(self.DS_ID).model(self.MODEL_ID) + got = client.get_model(model_ref) + + conn.api_request.assert_called_once_with(method="GET", path="/%s" % path) + self.assertEqual(got.model_id, self.MODEL_ID) + + def test_get_model_w_string(self): + path = "projects/%s/datasets/%s/models/%s" % ( + self.PROJECT, + self.DS_ID, + self.MODEL_ID, + ) + creds = _make_credentials() + http = object() + client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) + resource = { + "modelReference": { + "projectId": self.PROJECT, + "datasetId": self.DS_ID, + "modelId": self.MODEL_ID, + } + } + conn = client._connection = _make_connection(resource) + + model_id = "{}.{}.{}".format(self.PROJECT, self.DS_ID, self.MODEL_ID) + got = client.get_model(model_id) + + conn.api_request.assert_called_once_with(method="GET", path="/%s" % path) + self.assertEqual(got.model_id, self.MODEL_ID) + def test_get_table(self): path = "projects/%s/datasets/%s/tables/%s" % ( self.PROJECT, @@ -1422,6 +1472,66 @@ def test_update_dataset_w_custom_property(self): self.assertEqual(dataset.project, self.PROJECT) self.assertEqual(dataset._properties["newAlphaProperty"], "unreleased property") + def test_update_model(self): + from google.cloud.bigquery.model import Model + + path = "projects/%s/datasets/%s/models/%s" % ( + self.PROJECT, + self.DS_ID, + self.MODEL_ID, + ) + description = "description" + title = "title" + expires = datetime.datetime( + 2012, 12, 21, 16, 0, 0, tzinfo=google.cloud._helpers.UTC + ) + resource = { + "modelReference": { + "projectId": self.PROJECT, + "datasetId": self.DS_ID, + "modelId": self.MODEL_ID, + }, + "description": description, + "etag": "etag", + "expirationTime": str(google.cloud._helpers._millis(expires)), + "friendlyName": title, + "labels": {"x": "y"}, + } + creds = _make_credentials() + client = self._make_one(project=self.PROJECT, credentials=creds) + conn = client._connection = _make_connection(resource, resource) + model_id = "{}.{}.{}".format(self.PROJECT, self.DS_ID, self.MODEL_ID) + model = Model(model_id) + model.description = description + model.friendly_name = title + model.expires = expires + model.labels = {"x": "y"} + + updated_model = client.update_model( + model, ["description", "friendly_name", "labels", "expires"] + ) + + sent = { + "description": description, + "expirationTime": str(google.cloud._helpers._millis(expires)), + "friendlyName": title, + "labels": {"x": "y"}, + } + conn.api_request.assert_called_once_with( + method="PATCH", data=sent, path="/" + path, headers=None + ) + self.assertEqual(updated_model.model_id, model.model_id) + self.assertEqual(updated_model.description, model.description) + self.assertEqual(updated_model.friendly_name, model.friendly_name) + self.assertEqual(updated_model.labels, model.labels) + self.assertEqual(updated_model.expires, model.expires) + + # ETag becomes If-Match header. + model._proto.etag = "etag" + client.update_model(model, []) + req = conn.api_request.call_args + self.assertEqual(req[1]["headers"]["If-Match"], "etag") + def test_update_table(self): from google.cloud.bigquery.table import Table, SchemaField @@ -1773,6 +1883,78 @@ def test_list_tables_empty(self): method="GET", path=path, query_params={} ) + def test_list_models_empty(self): + path = "/projects/{}/datasets/{}/models".format(self.PROJECT, self.DS_ID) + creds = _make_credentials() + client = self._make_one(project=self.PROJECT, credentials=creds) + conn = client._connection = _make_connection({}) + + dataset_id = "{}.{}".format(self.PROJECT, self.DS_ID) + iterator = client.list_models(dataset_id) + page = six.next(iterator.pages) + models = list(page) + token = iterator.next_page_token + + self.assertEqual(models, []) + self.assertIsNone(token) + conn.api_request.assert_called_once_with( + method="GET", path=path, query_params={} + ) + + def test_list_models_defaults(self): + from google.cloud.bigquery.model import Model + + MODEL_1 = "model_one" + MODEL_2 = "model_two" + PATH = "projects/%s/datasets/%s/models" % (self.PROJECT, self.DS_ID) + TOKEN = "TOKEN" + DATA = { + "nextPageToken": TOKEN, + "models": [ + { + "modelReference": { + "modelId": MODEL_1, + "datasetId": self.DS_ID, + "projectId": self.PROJECT, + } + }, + { + "modelReference": { + "modelId": MODEL_2, + "datasetId": self.DS_ID, + "projectId": self.PROJECT, + } + }, + ], + } + + creds = _make_credentials() + client = self._make_one(project=self.PROJECT, credentials=creds) + conn = client._connection = _make_connection(DATA) + dataset = client.dataset(self.DS_ID) + + iterator = client.list_models(dataset) + self.assertIs(iterator.dataset, dataset) + page = six.next(iterator.pages) + models = list(page) + token = iterator.next_page_token + + self.assertEqual(len(models), len(DATA["models"])) + for found, expected in zip(models, DATA["models"]): + self.assertIsInstance(found, Model) + self.assertEqual(found.model_id, expected["modelReference"]["modelId"]) + self.assertEqual(token, TOKEN) + + conn.api_request.assert_called_once_with( + method="GET", path="/%s" % PATH, query_params={} + ) + + def test_list_models_wrong_type(self): + creds = _make_credentials() + client = self._make_one(project=self.PROJECT, credentials=creds) + with self.assertRaises(TypeError): + client.list_models(client.dataset(self.DS_ID).model("foo")) + def test_list_tables_defaults(self): from google.cloud.bigquery.table import TableListItem @@ -1960,6 +2142,68 @@ def test_delete_dataset_w_not_found_ok_true(self): conn.api_request.assert_called_with(method="DELETE", path=path, query_params={}) + def test_delete_model(self): + from google.cloud.bigquery.model import Model + + path = "projects/%s/datasets/%s/models/%s" % ( + self.PROJECT, + self.DS_ID, + self.MODEL_ID, + ) + creds = _make_credentials() + http = object() + client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) + model_id = "{}.{}.{}".format(self.PROJECT, self.DS_ID, self.MODEL_ID) + models = ( + model_id, + client.dataset(self.DS_ID).model(self.MODEL_ID), + Model(model_id), + ) + conn = client._connection = _make_connection(*([{}] * len(models))) + + for arg in models: + client.delete_model(arg) + conn.api_request.assert_called_with(method="DELETE", path="/%s" % path) + + def test_delete_model_w_wrong_type(self): + creds = _make_credentials() + client = self._make_one(project=self.PROJECT, credentials=creds) + with self.assertRaises(TypeError): + client.delete_model(client.dataset(self.DS_ID)) + + def test_delete_model_w_not_found_ok_false(self): + path = "/projects/{}/datasets/{}/models/{}".format( + self.PROJECT, self.DS_ID, self.MODEL_ID + ) + creds = _make_credentials() + http = object() + client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) + conn = client._connection = _make_connection( + google.api_core.exceptions.NotFound("model not found") + ) + + with self.assertRaises(google.api_core.exceptions.NotFound): + client.delete_model("{}.{}".format(self.DS_ID, self.MODEL_ID)) + + conn.api_request.assert_called_with(method="DELETE", path=path) + + def test_delete_model_w_not_found_ok_true(self): + path = "/projects/{}/datasets/{}/models/{}".format( + self.PROJECT, self.DS_ID, self.MODEL_ID + ) + creds = _make_credentials() + http = object() + client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) + conn = client._connection = _make_connection( + google.api_core.exceptions.NotFound("model not found") + ) + + client.delete_model( + "{}.{}".format(self.DS_ID, self.MODEL_ID), not_found_ok=True + ) + + conn.api_request.assert_called_with(method="DELETE", path=path) + def test_delete_table(self): from google.cloud.bigquery.table import Table From 5d036f7e4673ef1753b9568c5c92079b7c631b06 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Mon, 25 Mar 2019 14:03:56 -0700 Subject: [PATCH 6/8] Document enum classes (#495) --- bigquery/docs/gapic/v2/enums.rst | 7 +++++-- bigquery/google/cloud/bigquery/model.py | 3 ++- bigquery/setup.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bigquery/docs/gapic/v2/enums.rst b/bigquery/docs/gapic/v2/enums.rst index 9f47e3941904..0e0f05adaea5 100644 --- a/bigquery/docs/gapic/v2/enums.rst +++ b/bigquery/docs/gapic/v2/enums.rst @@ -1,5 +1,8 @@ Enums for BigQuery API Client ============================= -.. automodule:: google.cloud.bigquery_v2.gapic.enums - :members: \ No newline at end of file +.. autoclass:: google.cloud.bigquery_v2.gapic.enums.Model + :members: + +.. autoclass:: google.cloud.bigquery_v2.gapic.enums.StandardSqlDataType + :members: diff --git a/bigquery/google/cloud/bigquery/model.py b/bigquery/google/cloud/bigquery/model.py index c89727cf1fb5..8b29e4008558 100644 --- a/bigquery/google/cloud/bigquery/model.py +++ b/bigquery/google/cloud/bigquery/model.py @@ -359,7 +359,8 @@ def from_string(cls, model_id, default_project=None): include a project ID. Returns: - ModelReference: Model reference parsed from ``model_id``. + google.cloud.bigquery.model.ModelReference: + Model reference parsed from ``model_id``. Raises: ValueError: diff --git a/bigquery/setup.py b/bigquery/setup.py index 6b4edaf561c0..3be7874bf994 100644 --- a/bigquery/setup.py +++ b/bigquery/setup.py @@ -32,6 +32,7 @@ 'google-api-core >= 1.6.0, < 2.0.0dev', 'google-cloud-core >= 0.29.0, < 0.30dev', 'google-resumable-media >= 0.3.1', + 'enum34; python_version < "3.4"', ] extras = { 'bqstorage': 'google-cloud-bigquery-storage >= 0.2.0dev1, <2.0.0dev', From 9a71095772da854cdbcf1b17e970a3c573925985 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Tue, 26 Mar 2019 10:46:29 -0700 Subject: [PATCH 7/8] Add Beta client status to Models API methods. (#498) Even if the Models API itself is considered GA, I'd like to mark the client methods as Beta for a time to give us some more ability to make breaking changes until we're sure of the public interface we want to expose. --- bigquery/google/cloud/bigquery/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bigquery/google/cloud/bigquery/client.py b/bigquery/google/cloud/bigquery/client.py index 6ad3227a226b..23f19587c4b7 100644 --- a/bigquery/google/cloud/bigquery/client.py +++ b/bigquery/google/cloud/bigquery/client.py @@ -430,7 +430,7 @@ def get_dataset(self, dataset_ref, retry=DEFAULT_RETRY): return Dataset.from_api_repr(api_response) def get_model(self, model_ref, retry=DEFAULT_RETRY): - """Fetch the model referenced by ``model_ref``. + """[Beta] Fetch the model referenced by ``model_ref``. Args: model_ref (Union[ \ @@ -520,7 +520,7 @@ def update_dataset(self, dataset, fields, retry=DEFAULT_RETRY): return Dataset.from_api_repr(api_response) def update_model(self, model, fields, retry=DEFAULT_RETRY): - """Change some fields of a model. + """[Beta] Change some fields of a model. Use ``fields`` to specify which fields to update. At least one field must be provided. If a field is listed in ``fields`` and is ``None`` @@ -592,7 +592,7 @@ def update_table(self, table, fields, retry=DEFAULT_RETRY): def list_models( self, dataset, max_results=None, page_token=None, retry=DEFAULT_RETRY ): - """List models in the dataset. + """[Beta] List models in the dataset. See https://cloud.google.com/bigquery/docs/reference/rest/v2/models/list @@ -754,7 +754,7 @@ def delete_dataset( raise def delete_model(self, model, retry=DEFAULT_RETRY, not_found_ok=False): - """Delete a model + """[Beta] Delete a model See https://cloud.google.com/bigquery/docs/reference/rest/v2/models/delete From f294331fa2c40d2bbd07daddb1efda1b40f01454 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Wed, 3 Apr 2019 16:39:24 -0700 Subject: [PATCH 8/8] Re-gen based on public protos --- bigquery/google/cloud/bigquery_v2/types.py | 8 +------- bigquery/synth.metadata | 14 +++++++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bigquery/google/cloud/bigquery_v2/types.py b/bigquery/google/cloud/bigquery_v2/types.py index 939fa8b58b6e..0d228e88abac 100644 --- a/bigquery/google/cloud/bigquery_v2/types.py +++ b/bigquery/google/cloud/bigquery_v2/types.py @@ -19,7 +19,6 @@ from google.api_core.protobuf_helpers import get_messages -from google.cloud.bigquery_v2.proto import location_metadata_pb2 from google.cloud.bigquery_v2.proto import model_pb2 from google.cloud.bigquery_v2.proto import model_reference_pb2 from google.cloud.bigquery_v2.proto import standard_sql_pb2 @@ -29,12 +28,7 @@ _shared_modules = [empty_pb2, timestamp_pb2, wrappers_pb2] -_local_modules = [ - location_metadata_pb2, - model_pb2, - model_reference_pb2, - standard_sql_pb2, -] +_local_modules = [model_pb2, model_reference_pb2, standard_sql_pb2] names = [] diff --git a/bigquery/synth.metadata b/bigquery/synth.metadata index ee179d1f093b..4320d1d271bf 100644 --- a/bigquery/synth.metadata +++ b/bigquery/synth.metadata @@ -1,11 +1,19 @@ { - "updateTime": "2019-03-18T17:05:16.055644Z", + "updateTime": "2019-04-03T23:38:10.307198Z", "sources": [ { "generator": { "name": "artman", - "version": "0.16.17", - "dockerImage": "googleapis/artman@sha256:7231f27272231a884e09edb5953148c85ecd8467780d33c4a35c3e507885715b" + "version": "0.16.23", + "dockerImage": "googleapis/artman@sha256:f3a3f88000dc1cd1b4826104c5574aa5c534f6793fbf66e888d11c0d7ef5762e" + } + }, + { + "git": { + "name": "googleapis", + "remote": "git@github.com:googleapis/googleapis.git", + "sha": "04193ea2f8121388c998ab49c382f2c03417dcce", + "internalRef": "241828309" } } ],