use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-aiplatform by googleapis.
the class CreateDatasetTabularBigquerySample method createDatasetTableBigquery.
static void createDatasetTableBigquery(String project, String bigqueryDisplayName, String bigqueryUri) throws IOException, ExecutionException, InterruptedException, TimeoutException {
DatasetServiceSettings settings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
// the "close" method on the client to safely clean up any remaining background resources.
try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(settings)) {
String location = "us-central1";
String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/tables_1.0.0.yaml";
LocationName locationName = LocationName.of(project, location);
String jsonString = "{\"input_config\": {\"bigquery_source\": {\"uri\": \"" + bigqueryUri + "\"}}}";
Value.Builder metaData = Value.newBuilder();
JsonFormat.parser().merge(jsonString, metaData);
Dataset dataset = Dataset.newBuilder().setDisplayName(bigqueryDisplayName).setMetadataSchemaUri(metadataSchemaUri).setMetadata(metaData).build();
OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
System.out.println("Create Dataset Table Bigquery sample");
System.out.format("Name: %s\n", datasetResponse.getName());
System.out.format("Display Name: %s\n", datasetResponse.getDisplayName());
System.out.format("Metadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
System.out.format("Metadata: %s\n", datasetResponse.getMetadata());
}
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-aiplatform by googleapis.
the class CreateDatasetTabularGcsSample method createDatasetTableGcs.
static void createDatasetTableGcs(String project, String datasetDisplayName, String gcsSourceUri) throws IOException, ExecutionException, InterruptedException, TimeoutException {
DatasetServiceSettings settings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
// the "close" method on the client to safely clean up any remaining background resources.
try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(settings)) {
String location = "us-central1";
String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/tables_1.0.0.yaml";
LocationName locationName = LocationName.of(project, location);
String jsonString = "{\"input_config\": {\"gcs_source\": {\"uri\": [\"" + gcsSourceUri + "\"]}}}";
Value.Builder metaData = Value.newBuilder();
JsonFormat.parser().merge(jsonString, metaData);
Dataset dataset = Dataset.newBuilder().setDisplayName(datasetDisplayName).setMetadataSchemaUri(metadataSchemaUri).setMetadata(metaData).build();
OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
System.out.println("Create Dataset Table GCS sample");
System.out.format("Name: %s\n", datasetResponse.getName());
System.out.format("Display Name: %s\n", datasetResponse.getDisplayName());
System.out.format("Metadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
System.out.format("Metadata: %s\n", datasetResponse.getMetadata());
}
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-aiplatform by googleapis.
the class DatasetServiceClientTest method listDataItemsTest.
@Test
public void listDataItemsTest() throws Exception {
DataItem responsesElement = DataItem.newBuilder().build();
ListDataItemsResponse expectedResponse = ListDataItemsResponse.newBuilder().setNextPageToken("").addAllDataItems(Arrays.asList(responsesElement)).build();
mockDatasetService.addResponse(expectedResponse);
DatasetName parent = DatasetName.of("[PROJECT]", "[LOCATION]", "[DATASET]");
ListDataItemsPagedResponse pagedListResponse = client.listDataItems(parent);
List<DataItem> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDataItemsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatasetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDataItemsRequest actualRequest = ((ListDataItemsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-aiplatform by googleapis.
the class DatasetServiceClientTest method listDatasetsTest.
@Test
public void listDatasetsTest() throws Exception {
Dataset responsesElement = Dataset.newBuilder().build();
ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
mockDatasetService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent);
List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatasetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project java-aiplatform by googleapis.
the class DatasetServiceClientTest method listAnnotationsTest.
@Test
public void listAnnotationsTest() throws Exception {
Annotation responsesElement = Annotation.newBuilder().build();
ListAnnotationsResponse expectedResponse = ListAnnotationsResponse.newBuilder().setNextPageToken("").addAllAnnotations(Arrays.asList(responsesElement)).build();
mockDatasetService.addResponse(expectedResponse);
DataItemName parent = DataItemName.of("[PROJECT]", "[LOCATION]", "[DATASET]", "[DATA_ITEM]");
ListAnnotationsPagedResponse pagedListResponse = client.listAnnotations(parent);
List<Annotation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAnnotationsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatasetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAnnotationsRequest actualRequest = ((ListAnnotationsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations