-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDataSet.java
More file actions
27 lines (25 loc) · 1.21 KB
/
Copy pathCreateDataSet.java
File metadata and controls
27 lines (25 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Dataset;
import com.google.cloud.bigquery.DatasetInfo;
public class CreateDataSet {
public static void main(String[] args) {
// TODO(developer): Replace these variables before running the sample.
String datasetName = "MY_FAV_DATASET_NAME";
createDataset(datasetName);
}
public static void createDataset(String datasetName) {
try {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
Dataset newDataset = bigquery.create(datasetInfo);
String newDatasetName = newDataset.getDatasetId().getDataset();
System.out.println(newDatasetName + " created successfully");
} catch (BigQueryException e) {
System.out.println("Dataset was not created. \n" + e.toString());
}
}
}