创建 AWS 数据集。
代码示例
Java
试用此示例之前,请按照《BigQuery 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 BigQuery Java API 参考文档。
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;
// Sample to create a aws dataset
public class CreateDatasetAws {
public static void main(String[] args) {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String datasetName = "MY_DATASET_NAME";
// Note: As of now location only supports aws-us-east-1
String location = "aws-us-east-1";
createDatasetAws(projectId, datasetName, location);
}
public static void createDatasetAws(String projectId, String datasetName, String location) {
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(projectId, datasetName).setLocation(location).build();
Dataset dataset = bigquery.create(datasetInfo);
System.out.println(
"Aws dataset created successfully :" + dataset.getDatasetId().getDataset());
} catch (BigQueryException e) {
System.out.println("Aws dataset was not created. \n" + e.toString());
}
}
}