public class Dataset extends DatasetInfo
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 a Dataset
object with the most recent information use reload(com.google.cloud.bigquery.BigQuery.DatasetOption...)
. Dataset
adds a layer of service-related functionality over DatasetInfo
.
Modifier and Type | Class and Description |
---|---|
static class |
Dataset.Builder
A builder for
Dataset objects. |
Modifier and Type | Method and 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 or
null if not found. |
BigQuery |
getBigQuery()
Returns the dataset's
BigQuery object used to issue requests. |
int |
hashCode() |
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.
|
getAcl, getCreationTime, getDatasetId, getDefaultTableLifetime, getDescription, getEtag, getFriendlyName, getGeneratedId, getLabels, getLastModified, getLocation, getSelfLink, newBuilder, newBuilder, newBuilder, of, of, toString
public boolean exists()
Example of checking whether a dataset exists.
boolean exists = dataset.exists();
if (exists) {
// the dataset exists
} else {
// the dataset was not found
}
true
if this dataset exists, false
otherwiseBigQueryException
- upon failurepublic Dataset reload(BigQuery.DatasetOption... options)
null
if the dataset does not
exist.
Example of reloading a dataset.
Dataset latestDataset = dataset.reload();
if (latestDataset == null) {
// The dataset was not found
}
options
- dataset optionsDataset
object with latest information or null
if not foundBigQueryException
- upon failurepublic Dataset update(BigQuery.DatasetOption... options)
Dataset
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();
options
- dataset optionsDataset
object with updated informationBigQueryException
- upon failurepublic boolean delete(BigQuery.DatasetDeleteOption... options)
Example of deleting a dataset.
boolean deleted = dataset.delete();
if (deleted) {
// The dataset was deleted
} else {
// The dataset was not found
}
true
if dataset was deleted, false
if it was not foundBigQueryException
- upon failurepublic Page<Table> list(BigQuery.TableListOption... options)
Example of listing tables in the dataset.
Page<Table> tables = dataset.list();
for (Table table : tables.iterateAll()) {
// do something with the table
}
options
- options for listing tablesBigQueryException
- upon failurepublic Table get(String tableId, BigQuery.TableOption... options)
null
if not found.
Example of getting a table in the dataset.
String tableName = “my_table”;
Table table = dataset.get(tableName);
tableId
- user-defined id of the requested tableoptions
- table optionsBigQueryException
- upon failurepublic Table create(String tableId, TableDefinition definition, BigQuery.TableOption... options)
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);
tableId
- the table's user-defined iddefinition
- the table's definitionoptions
- options for table creationTable
object for the created tableBigQueryException
- upon failurepublic BigQuery getBigQuery()
BigQuery
object used to issue requests.public Dataset.Builder toBuilder()
DatasetInfo
toBuilder
in class DatasetInfo
public final boolean equals(Object obj)
equals
in class DatasetInfo
public final int hashCode()
hashCode
in class DatasetInfo
Copyright © 2019 Google LLC. All rights reserved.