Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
BigQuery: adds models API implementation.#5021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ecd1703
initial model
shollyman 2b55784
Merge branch 'models' of https://github.com/shollyman/google-cloud-java
shollyman b890c81
more impl
shollyman 2a01f8d
more modelling
shollyman 6d9aa15
Merge branch 'master' of https://github.com/googleapis/google-cloud-java
shollyman 7cb0247
Merge branch 'master' into models
shollyman b4cd4e6
more modelling
shollyman cb8961f
model testing
shollyman 506d44c
more tests and comments
shollyman f100375
more tests, mark bigquery.delete(string, string, string) deprecated
shollyman 3caef2c
Merge branch 'master' of https://github.com/googleapis/google-cloud-java
shollyman b5a6569
Merge branch 'master' into models
shollyman 715a99a
typo
shollyman ca1f0e0
Merge branch 'master' of https://github.com/googleapis/google-cloud-java
shollyman 7896589
Merge branch 'master' of https://github.com/googleapis/google-cloud-java
shollyman bf6fa35
Merge branch 'master' into models and unpin
shollyman 16d3ab8
address review comments
shollyman 83769ce
formatter + typo
shollyman 47c1fca
update pinning of bigquery in google-cloud-clients to v2-rev20190423-…
shollyman ae12428
step down from 1.28.0 to 1.27.0 due to bounding on deps
shollyman dc0cc2c
backout local pin, will pick up new pin from master
shollyman 09913dd
Merge branch 'master' of https://github.com/googleapis/google-cloud-java
shollyman 47957b6
Merge branch 'master' into models
shollyman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162 ...cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -116,6 +116,39 @@ public String getSelector() { | ||
| } | ||
| } | ||
| /** | ||
| * Fields of a BigQuery Model resource. | ||
| * | ||
| * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/models#resource">Model | ||
| * Resource</a> | ||
| */ | ||
| enum ModelField implements FieldSelector { | ||
| CREATION_TIME("creationTime"), | ||
| DESCRIPTION("description"), | ||
| ETAG("etag"), | ||
| EXPIRATION_TIME("expirationTime"), | ||
| FRIENDLY_NAME("friendlyName"), | ||
| LABELS("labels"), | ||
| LAST_MODIFIED_TIME("lastModifiedTime"), | ||
| LOCATION("location"), | ||
| MODEL_REFERENCE("modelReference"), | ||
| TIME_PARTITIONING("timePartitioning"), | ||
| TYPE("modelType"); | ||
| static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(MODEL_REFERENCE); | ||
| private final String selector; | ||
| ModelField(String selector) { | ||
| this.selector = selector; | ||
| } | ||
| @Override | ||
| public String getSelector() { | ||
| return selector; | ||
| } | ||
| } | ||
| /** | ||
| * Fields of a BigQuery Job resource. | ||
| * | ||
| @@ -211,6 +244,27 @@ public static DatasetDeleteOption deleteContents() { | ||
| } | ||
| } | ||
| /** Class for specifying table list options. */ | ||
| class ModelListOption extends Option { | ||
| private static final long serialVersionUID = 8660294969063322498L; | ||
| private ModelListOption(BigQueryRpc.Option option, Object value) { | ||
| super(option, value); | ||
| } | ||
| /** Returns an option to specify the maximum number of models returned per page. */ | ||
| public static ModelListOption pageSize(long pageSize) { | ||
| checkArgument(pageSize >= 0); | ||
| return new ModelListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize); | ||
| } | ||
| /** Returns an option to specify the page token from which to start listing models. */ | ||
| public static ModelListOption pageToken(String pageToken) { | ||
| return new ModelListOption(BigQueryRpc.Option.PAGE_TOKEN, pageToken); | ||
| } | ||
| } | ||
| /** Class for specifying table list options. */ | ||
| class TableListOption extends Option { | ||
| @@ -253,6 +307,26 @@ public static TableOption fields(TableField... fields) { | ||
| } | ||
| } | ||
| /** Class for specifying table get, create and update options. */ | ||
| class ModelOption extends Option { | ||
| private static final long serialVersionUID = -1723870134095226772L; | ||
| private ModelOption(BigQueryRpc.Option option, Object value) { | ||
| super(option, value); | ||
| } | ||
| /** | ||
| * Returns an option to specify the model's fields to be returned by the RPC call. If this | ||
| * option is not provided all model's fields are returned. {@code ModelOption.fields} can be | ||
| * used to specify only the fields of interest. | ||
| */ | ||
| public static ModelOption fields(ModelField... fields) { | ||
| return new ModelOption( | ||
| BigQueryRpc.Option.FIELDS, Helper.selector(ModelField.REQUIRED_FIELDS, fields)); | ||
| } | ||
| } | ||
| /** Class for specifying table data list options. */ | ||
| class TableDataListOption extends Option { | ||
| @@ -705,6 +779,29 @@ public int hashCode() { | ||
| */ | ||
| boolean delete(TableId tableId); | ||
| /** | ||
| * Deletes the requested model. | ||
| * | ||
| * <p>Example of deleting a model. | ||
| * | ||
| * <pre>{@code | ||
| * String projectId = "my_project_id"; | ||
| * String datasetName = "my_dataset_name"; | ||
| * String tableName = "my_model_name"; | ||
| * ModelId modelId = ModelId.of(projectId, datasetName, modelName); | ||
| * boolean deleted = bigquery.delete(modelId); | ||
| * if (deleted) { | ||
| * // the model was deleted | ||
| * } else { | ||
| * // the model was not found | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * @return {@code true} if model was deleted, {@code false} if it was not found | ||
| * @throws BigQueryException upon failure | ||
| */ | ||
| boolean delete(ModelId modelId); | ||
| /** | ||
| * Updates dataset information. | ||
| * | ||
| @@ -765,6 +862,41 @@ public int hashCode() { | ||
| */ | ||
| Table update(TableInfo tableInfo, TableOption... options); | ||
| /** | ||
| * Updates model information. | ||
| * | ||
| * <p>Example of updating a model by changing its description. | ||
| * | ||
| * <pre>{@code | ||
| * String datasetName = "my_dataset_name"; | ||
| * String modelName = "my_model_name"; | ||
| * String newDescription = "new_description"; | ||
| * Model beforeModel = bigquery.getModel(datasetName, modelName); | ||
| * ModelInfo modelInfo = beforeModel.toBuilder() | ||
| * .setDescription(newDescription) | ||
| * .build(); | ||
| * Model afterModel = bigquery.update(modelInfo); | ||
| * }</pre> | ||
| * | ||
| * <p>Example of updating a model by changing its expiration. | ||
| * | ||
| * <pre>{@code | ||
| * String datasetName = "my_dataset_name"; | ||
| * String modelName = "my_model_name"; | ||
| * Model beforeModel = bigquery.getModel(datasetName, modelName); | ||
| * | ||
| * // Set model to expire 5 days from now. | ||
| * long expirationMillis = DateTime.now().plusDays(5).getMillis(); | ||
| * ModelInfo modelInfo = beforeModel.toBuilder() | ||
| * .setExpirationTime(expirationMillis) | ||
| * .build(); | ||
| * Model afterModel = bigquery.update(modelInfo); | ||
| * }</pre> | ||
| * | ||
| * @throws BigQueryException upon failure | ||
| */ | ||
| Model update(ModelInfo modelInfo, ModelOption... options); | ||
shollyman marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Returns the requested table or {@code null} if not found. | ||
| * | ||
| @@ -797,6 +929,30 @@ public int hashCode() { | ||
| */ | ||
| Table getTable(TableId tableId, TableOption... options); | ||
| /** | ||
| * Returns the requested model or {@code null} if not found. | ||
| * | ||
| * @throws BigQueryException upon failure | ||
| */ | ||
| Model getModel(String datasetId, String modelId, ModelOption... options); | ||
| /** | ||
| * Returns the requested model or {@code null} if not found. | ||
| * | ||
| * <p>Example of getting a model. | ||
| * | ||
| * <pre>{@code | ||
| * String projectId = "my_project_id"; | ||
| * String datasetName = "my_dataset_name"; | ||
| * String modelName = "my_model_name"; | ||
| * ModelId modelId = ModelId.of(projectId, datasetName, tableName); | ||
| * Model model = bigquery.getModel(modelId); | ||
| * }</pre> | ||
| * | ||
| * @throws BigQueryException upon failure | ||
| */ | ||
| Model getModel(ModelId tableId, ModelOption... options); | ||
| /** | ||
| * Lists the tables in the dataset. This method returns partial information on each table: ({@link | ||
| * Table#getTableId()}, {@link Table#getFriendlyName()}, {@link Table#getGeneratedId()} and type, | ||
| @@ -839,6 +995,12 @@ public int hashCode() { | ||
| */ | ||
| Page<Table> listTables(DatasetId datasetId, TableListOption... options); | ||
| /** Lists the models in the dataset. */ | ||
| Page<Model> listModels(String datasetId, ModelListOption... options); | ||
| /** Lists the models in the dataset. */ | ||
| Page<Model> listModels(DatasetId datasetId, ModelListOption... options); | ||
| /** | ||
| * @param tableId | ||
| * @return A list of the partition ids present in the partitioned table | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see model type in the Model class, but not here. At first I thought you were waiting for the enum from Apiary, but I guess not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it TYPE, but perhaps MODEL_TYPE is better for the enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right.
TYPEseems fine. Less redundant.