Search in sources :

Example 1 with GoogleCloudDataplexV1ListPartitionsResponse

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method getPartitions.

@Override
public ImmutableList<GoogleCloudDataplexV1Partition> getPartitions(String entityName) throws IOException {
    ImmutableList.Builder<GoogleCloudDataplexV1Partition> result = ImmutableList.builder();
    Partitions partitions = client.projects().locations().lakes().zones().entities().partitions();
    GoogleCloudDataplexV1ListPartitionsResponse response = partitions.list(entityName).execute();
    if (response.getPartitions() == null) {
        return ImmutableList.of();
    }
    result.addAll(response.getPartitions());
    // the result of the list is paginated with the default page size being 10
    while (response.getNextPageToken() != null) {
        response = partitions.list(entityName).setPageToken(response.getNextPageToken()).execute();
        result.addAll(response.getPartitions());
    }
    return result.build();
}
Also used : Partitions(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) GoogleCloudDataplexV1ListPartitionsResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse) GoogleCloudDataplexV1Partition(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)

Example 2 with GoogleCloudDataplexV1ListPartitionsResponse

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClientTest method testGetPartitionsByEntityName.

@Test
public void testGetPartitionsByEntityName() throws IOException {
    CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
    Partitions partitions = mock(Partitions.class, Answers.RETURNS_DEEP_STUBS);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().partitions()).thenReturn(partitions);
    GoogleCloudDataplexV1Partition partition1 = new GoogleCloudDataplexV1Partition().setName("partition1");
    GoogleCloudDataplexV1Partition partition2 = new GoogleCloudDataplexV1Partition().setName("partition2");
    GoogleCloudDataplexV1Partition partition3 = new GoogleCloudDataplexV1Partition().setName("partition2");
    GoogleCloudDataplexV1ListPartitionsResponse response1 = new GoogleCloudDataplexV1ListPartitionsResponse().setPartitions(ImmutableList.of(partition1, partition2)).setNextPageToken(PAGE_TOKEN);
    GoogleCloudDataplexV1ListPartitionsResponse response2 = new GoogleCloudDataplexV1ListPartitionsResponse().setPartitions(ImmutableList.of(partition3));
    when(partitions.list("entity0").execute()).thenReturn(response1);
    when(partitions.list("entity0").setPageToken(eq(PAGE_TOKEN)).execute()).thenReturn(response2);
    assertEquals(ImmutableList.of(partition1, partition2, partition3), DefaultDataplexClient.withClient(cloudDataplexClient).getPartitions("entity0"));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) Partitions(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions) GoogleCloudDataplexV1ListPartitionsResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse) GoogleCloudDataplexV1Partition(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition) Test(org.junit.Test)

Aggregations

Partitions (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions)2 GoogleCloudDataplexV1ListPartitionsResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse)2 GoogleCloudDataplexV1Partition (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)2 CloudDataplex (com.google.api.services.dataplex.v1.CloudDataplex)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Test (org.junit.Test)1