@@ -116,6 +116,39 @@ public String getSelector() {
116116 }
117117 }
118118
119+ /**
120+ * Fields of a BigQuery Model resource.
121+ *
122+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/models#resource">Model
123+ * Resource</a>
124+ */
125+ enum ModelField implements FieldSelector {
126+ CREATION_TIME ("creationTime" ),
127+ DESCRIPTION ("description" ),
128+ ETAG ("etag" ),
129+ EXPIRATION_TIME ("expirationTime" ),
130+ FRIENDLY_NAME ("friendlyName" ),
131+ LABELS ("labels" ),
132+ LAST_MODIFIED_TIME ("lastModifiedTime" ),
133+ LOCATION ("location" ),
134+ MODEL_REFERENCE ("modelReference" ),
135+ TIME_PARTITIONING ("timePartitioning" ),
136+ TYPE ("modelType" );
137+
138+ static final List <? extends FieldSelector > REQUIRED_FIELDS = ImmutableList .of (MODEL_REFERENCE );
139+
140+ private final String selector ;
141+
142+ ModelField (String selector ) {
143+ this .selector = selector ;
144+ }
145+
146+ @ Override
147+ public String getSelector () {
148+ return selector ;
149+ }
150+ }
151+
119152 /**
120153 * Fields of a BigQuery Job resource.
121154 *
@@ -211,6 +244,27 @@ public static DatasetDeleteOption deleteContents() {
211244 }
212245 }
213246
247+ /** Class for specifying table list options. */
248+ class ModelListOption extends Option {
249+
250+ private static final long serialVersionUID = 8660294969063322498L ;
251+
252+ private ModelListOption (BigQueryRpc .Option option , Object value ) {
253+ super (option , value );
254+ }
255+
256+ /** Returns an option to specify the maximum number of models returned per page. */
257+ public static ModelListOption pageSize (long pageSize ) {
258+ checkArgument (pageSize >= 0 );
259+ return new ModelListOption (BigQueryRpc .Option .MAX_RESULTS , pageSize );
260+ }
261+
262+ /** Returns an option to specify the page token from which to start listing models. */
263+ public static ModelListOption pageToken (String pageToken ) {
264+ return new ModelListOption (BigQueryRpc .Option .PAGE_TOKEN , pageToken );
265+ }
266+ }
267+
214268 /** Class for specifying table list options. */
215269 class TableListOption extends Option {
216270
@@ -253,6 +307,26 @@ public static TableOption fields(TableField... fields) {
253307 }
254308 }
255309
310+ /** Class for specifying table get, create and update options. */
311+ class ModelOption extends Option {
312+
313+ private static final long serialVersionUID = -1723870134095226772L ;
314+
315+ private ModelOption (BigQueryRpc .Option option , Object value ) {
316+ super (option , value );
317+ }
318+
319+ /**
320+ * Returns an option to specify the model's fields to be returned by the RPC call. If this
321+ * option is not provided all model's fields are returned. {@code ModelOption.fields} can be
322+ * used to specify only the fields of interest.
323+ */
324+ public static ModelOption fields (ModelField ... fields ) {
325+ return new ModelOption (
326+ BigQueryRpc .Option .FIELDS , Helper .selector (ModelField .REQUIRED_FIELDS , fields ));
327+ }
328+ }
329+
256330 /** Class for specifying table data list options. */
257331 class TableDataListOption extends Option {
258332
@@ -705,6 +779,29 @@ public int hashCode() {
705779 */
706780 boolean delete (TableId tableId );
707781
782+ /**
783+ * Deletes the requested model.
784+ *
785+ * <p>Example of deleting a model.
786+ *
787+ * <pre>{@code
788+ * String projectId = "my_project_id";
789+ * String datasetName = "my_dataset_name";
790+ * String tableName = "my_model_name";
791+ * ModelId modelId = ModelId.of(projectId, datasetName, modelName);
792+ * boolean deleted = bigquery.delete(modelId);
793+ * if (deleted) {
794+ * // the model was deleted
795+ * } else {
796+ * // the model was not found
797+ * }
798+ * }</pre>
799+ *
800+ * @return {@code true} if model was deleted, {@code false} if it was not found
801+ * @throws BigQueryException upon failure
802+ */
803+ boolean delete (ModelId modelId );
804+
708805 /**
709806 * Updates dataset information.
710807 *
@@ -765,6 +862,41 @@ public int hashCode() {
765862 */
766863 Table update (TableInfo tableInfo , TableOption ... options );
767864
865+ /**
866+ * Updates model information.
867+ *
868+ * <p>Example of updating a model by changing its description.
869+ *
870+ * <pre>{@code
871+ * String datasetName = "my_dataset_name";
872+ * String modelName = "my_model_name";
873+ * String newDescription = "new_description";
874+ * Model beforeModel = bigquery.getModel(datasetName, modelName);
875+ * ModelInfo modelInfo = beforeModel.toBuilder()
876+ * .setDescription(newDescription)
877+ * .build();
878+ * Model afterModel = bigquery.update(modelInfo);
879+ * }</pre>
880+ *
881+ * <p>Example of updating a model by changing its expiration.
882+ *
883+ * <pre>{@code
884+ * String datasetName = "my_dataset_name";
885+ * String modelName = "my_model_name";
886+ * Model beforeModel = bigquery.getModel(datasetName, modelName);
887+ *
888+ * // Set model to expire 5 days from now.
889+ * long expirationMillis = DateTime.now().plusDays(5).getMillis();
890+ * ModelInfo modelInfo = beforeModel.toBuilder()
891+ * .setExpirationTime(expirationMillis)
892+ * .build();
893+ * Model afterModel = bigquery.update(modelInfo);
894+ * }</pre>
895+ *
896+ * @throws BigQueryException upon failure
897+ */
898+ Model update (ModelInfo modelInfo , ModelOption ... options );
899+
768900 /**
769901 * Returns the requested table or {@code null} if not found.
770902 *
@@ -797,6 +929,30 @@ public int hashCode() {
797929 */
798930 Table getTable (TableId tableId , TableOption ... options );
799931
932+ /**
933+ * Returns the requested model or {@code null} if not found.
934+ *
935+ * @throws BigQueryException upon failure
936+ */
937+ Model getModel (String datasetId , String modelId , ModelOption ... options );
938+
939+ /**
940+ * Returns the requested model or {@code null} if not found.
941+ *
942+ * <p>Example of getting a model.
943+ *
944+ * <pre>{@code
945+ * String projectId = "my_project_id";
946+ * String datasetName = "my_dataset_name";
947+ * String modelName = "my_model_name";
948+ * ModelId modelId = ModelId.of(projectId, datasetName, tableName);
949+ * Model model = bigquery.getModel(modelId);
950+ * }</pre>
951+ *
952+ * @throws BigQueryException upon failure
953+ */
954+ Model getModel (ModelId tableId , ModelOption ... options );
955+
800956 /**
801957 * Lists the tables in the dataset. This method returns partial information on each table: ({@link
802958 * Table#getTableId()}, {@link Table#getFriendlyName()}, {@link Table#getGeneratedId()} and type,
@@ -839,6 +995,12 @@ public int hashCode() {
839995 */
840996 Page <Table > listTables (DatasetId datasetId , TableListOption ... options );
841997
998+ /** Lists the models in the dataset. */
999+ Page <Model > listModels (String datasetId , ModelListOption ... options );
1000+
1001+ /** Lists the models in the dataset. */
1002+ Page <Model > listModels (DatasetId datasetId , ModelListOption ... options );
1003+
8421004 /**
8431005 * @param tableId
8441006 * @return A list of the partition ids present in the partitioned table
0 commit comments