Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,39 @@ public String getSelector() {
}
}

/**
* Fields of a BigQuery Routine resource.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/routines#resource">Routine
* Resource</a>
*/
enum RoutineField implements FieldSelector {
ARGUMENTS("arguments"),
CREATION_TIME("creationTime"),
DEFINITION_BODY("definitionBody"),
ETAG("etag"),
IMPORTED_LIBRARIES("importedLibraries"),
LANGUAGE("language"),
LAST_MODIFIED_TIME("lastModifiedTime"),
RETURN_TYPE("returnType"),
ROUTINE_REFERENCE("routineReference"),
ROUTINE_TYPE("routineType");

static final List<? extends FieldSelector> REQUIRED_FIELDS =
ImmutableList.of(ROUTINE_REFERENCE);

private final String selector;

RoutineField(String selector) {
this.selector = selector;
}

@Override
public String getSelector() {
return selector;
}
}

/**
* Fields of a BigQuery Job resource.
*
Expand Down Expand Up @@ -267,6 +300,27 @@ public static ModelListOption pageToken(String pageToken) {
}
}

/** Class for specifying routine list options. */
class RoutineListOption extends Option {

private static final long serialVersionUID = 8660294969063312498L;

private RoutineListOption(BigQueryRpc.Option option, Object value) {
super(option, value);
}

/** Returns an option to specify the maximum number of routines returned per page. */
public static RoutineListOption pageSize(long pageSize) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be package private? (Same with other public methods in package private classes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably reasonable, we extend Option but don't appear to extend each of the various typed options beyond that. Filed https://github.com/googleapis/google-cloud-java/issues/5728 to followup on visibility more generally.

checkArgument(pageSize >= 0);
return new RoutineListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/** Returns an option to specify the page token from which to start listing routines. */
public static RoutineListOption pageToken(String pageToken) {
return new RoutineListOption(BigQueryRpc.Option.PAGE_TOKEN, pageToken);
}
}

/** Class for specifying table list options. */
class TableListOption extends Option {

Expand Down Expand Up @@ -309,7 +363,7 @@ public static TableOption fields(TableField... fields) {
}
}

/** Class for specifying table get, create and update options. */
/** Class for specifying model get, create and update options. */
class ModelOption extends Option {

private static final long serialVersionUID = -1723870134095226772L;
Expand All @@ -329,6 +383,26 @@ public static ModelOption fields(ModelField... fields) {
}
}

/** Class for specifying table get, create and update options. */
class RoutineOption extends Option {

private static final long serialVersionUID = -1723870122095226772L;

private RoutineOption(BigQueryRpc.Option option, Object value) {
super(option, value);
}

/**
* Returns an option to specify the routines's fields to be returned by the RPC call. If this
* option is not provided all model's fields are returned. {@code RoutineOption.fields} can be
* used to specify only the fields of interest.
*/
public static RoutineOption fields(RoutineField... fields) {
return new RoutineOption(
BigQueryRpc.Option.FIELDS, Helper.selector(RoutineField.REQUIRED_FIELDS, fields));
}
}

/** Class for specifying table data list options. */
class TableDataListOption extends Option {

Expand Down Expand Up @@ -583,6 +657,13 @@ public int hashCode() {
*/
Table create(TableInfo tableInfo, TableOption... options);

/**
* Creates a new routine.
*
* @throws BigQueryException upon failure
*/
Routine create(RoutineInfo routineInfo, RoutineOption... options);

/**
* Creates a new job.
*
Expand Down Expand Up @@ -804,6 +885,29 @@ public int hashCode() {
*/
boolean delete(ModelId modelId);

/**
* Deletes the requested routine.
*
* <p>Example of deleting a routine.
*
* <pre>{@code
* String projectId = "my_project_id";
* String datasetId = "my_dataset_id";
* String routineId = "my_routine_id";
* RoutineId routineId = RoutineId.of(projectId, datasetId, routineId);
* boolean deleted = bigquery.delete(routineId);
* if (deleted) {
* // the routine was deleted
* } else {
* // the routine was not found
* }
* </pre>
*
* @return {@code true} if routine was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
*/
boolean delete(RoutineId routineId);

/**
* Updates dataset information.
*
Expand Down Expand Up @@ -899,6 +1003,13 @@ public int hashCode() {
*/
Model update(ModelInfo modelInfo, ModelOption... options);

/**
* Updates routine information.
*
* @throws BigQueryException upon failure
*/
Routine update(RoutineInfo routineInfo, RoutineOption... options);

/**
* Returns the requested table or {@code null} if not found.
*
Expand Down Expand Up @@ -955,6 +1066,26 @@ public int hashCode() {
*/
Model getModel(ModelId tableId, ModelOption... options);

/**
* Returns the requested routine or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
Routine getRoutine(String datasetId, String routineId, RoutineOption... options);

/**
* Returns the requested routine or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
Routine getRoutine(RoutineId routineId, RoutineOption... options);

/** Lists the routines in the specified dataset. */
Page<Routine> listRoutines(String datasetId, RoutineListOption... options);

/** Lists the routines in the specified dataset. */
Page<Routine> listRoutines(DatasetId datasetId, RoutineListOption... 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,
Expand Down
Loading