Package com.google.cloud.bigquery
Class Dataset
- java.lang.Object
-
- com.google.cloud.bigquery.DatasetInfo
-
- com.google.cloud.bigquery.Dataset
-
- All Implemented Interfaces:
Serializable
public class Dataset extends DatasetInfo
A Google BigQuery Dataset.Objects of this class are immutable. Operations that modify the dataset like
update(com.google.cloud.bigquery.BigQuery.DatasetOption...)
return a new object. To get aDataset
object with the most recent information usereload(com.google.cloud.bigquery.BigQuery.DatasetOption...)
.Dataset
adds a layer of service-related functionality overDatasetInfo
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Dataset.Builder
A builder forDataset
objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Table
create(String tableId, TableDefinition definition, BigQuery.TableOption... options)
Creates a new table in this dataset.boolean
delete(BigQuery.DatasetDeleteOption... options)
Deletes this dataset.boolean
equals(Object obj)
boolean
exists()
Checks if this dataset exists.Table
get(String tableId, BigQuery.TableOption... options)
Returns the requested table in this dataset ornull
if not found.BigQuery
getBigQuery()
Returns the dataset'sBigQuery
object used to issue requests.int
hashCode()
com.google.api.gax.paging.Page<Table>
list(BigQuery.TableListOption... options)
Returns the paginated list of tables in this dataset.Dataset
reload(BigQuery.DatasetOption... options)
Fetches current dataset's latest information.Dataset.Builder
toBuilder()
Returns a builder for the dataset object.Dataset
update(BigQuery.DatasetOption... options)
Updates the dataset's information with this dataset's information.-
Methods inherited from class com.google.cloud.bigquery.DatasetInfo
getAcl, getCreationTime, getDatasetId, getDefaultCollation, getDefaultEncryptionConfiguration, getDefaultPartitionExpirationMs, getDefaultTableLifetime, getDescription, getEtag, getExternalDatasetReference, getFriendlyName, getGeneratedId, getLabels, getLastModified, getLocation, getSelfLink, newBuilder, newBuilder, newBuilder, of, of, toString
-
-
-
-
Method Detail
-
exists
public boolean exists()
Checks if this dataset exists.Example of checking whether a dataset exists.
boolean exists = dataset.exists(); if (exists) { // the dataset exists } else { // the dataset was not found }
- Returns:
true
if this dataset exists,false
otherwise- Throws:
BigQueryException
- upon failure
-
reload
public Dataset reload(BigQuery.DatasetOption... options)
Fetches current dataset's latest information. Returnsnull
if the dataset does not exist.Example of reloading a dataset.
Dataset latestDataset = dataset.reload(); if (latestDataset == null) { // The dataset was not found }
- Parameters:
options
- dataset options- Returns:
- a
Dataset
object with latest information ornull
if not found - Throws:
BigQueryException
- upon failure
-
update
public Dataset update(BigQuery.DatasetOption... options)
Updates the dataset's information with this dataset's information. Dataset's user-defined id cannot be changed. A newDataset
object is returned.Example of updating a dataset.
String friendlyName = "my_friendly_name"; Builder builder = dataset.toBuilder(); builder.setFriendlyName(friendlyName); Dataset updatedDataset = builder.build().update();
- Parameters:
options
- dataset options- Returns:
- a
Dataset
object with updated information - Throws:
BigQueryException
- upon failure
-
delete
public boolean delete(BigQuery.DatasetDeleteOption... options)
Deletes this dataset.Example of deleting a dataset.
boolean deleted = dataset.delete(); if (deleted) { // The dataset was deleted } else { // The dataset was not found }
- Returns:
true
if dataset was deleted,false
if it was not found- Throws:
BigQueryException
- upon failure
-
list
public com.google.api.gax.paging.Page<Table> list(BigQuery.TableListOption... options)
Returns the paginated list of tables in this dataset.Example of listing tables in the dataset.
Page<Table> tables = dataset.list(); for (Table table : tables.iterateAll()) { // do something with the table }
- Parameters:
options
- options for listing tables- Throws:
BigQueryException
- upon failure
-
get
public Table get(String tableId, BigQuery.TableOption... options)
Returns the requested table in this dataset ornull
if not found.Example of getting a table in the dataset.
String tableName = “my_table”; Table table = dataset.get(tableName);
- Parameters:
tableId
- user-defined id of the requested tableoptions
- table options- Throws:
BigQueryException
- upon failure
-
create
public Table create(String tableId, TableDefinition definition, BigQuery.TableOption... options)
Creates a new table in this dataset.Example of creating a table in the dataset with schema and time partitioning.
String tableName = “my_table”; String fieldName = “my_field”; Schema schema = Schema.of(Field.of(fieldName, LegacySQLTypeName.STRING)); StandardTableDefinition definition = StandardTableDefinition.newBuilder() .setSchema(schema) .setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY)) .build(); Table table = dataset.create(tableName, definition);
- Parameters:
tableId
- the table's user-defined iddefinition
- the table's definitionoptions
- options for table creation- Returns:
- a
Table
object for the created table - Throws:
BigQueryException
- upon failure
-
getBigQuery
public BigQuery getBigQuery()
Returns the dataset'sBigQuery
object used to issue requests.
-
toBuilder
public Dataset.Builder toBuilder()
Description copied from class:DatasetInfo
Returns a builder for the dataset object.- Overrides:
toBuilder
in classDatasetInfo
-
equals
public final boolean equals(Object obj)
- Overrides:
equals
in classDatasetInfo
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classDatasetInfo
-
-