Search in sources :

Example 1 with Entry

use of com.google.cloud.datacatalog.v1.Entry in project beam by apache.

the class DataCatalogTableProvider method setSchemaIfNotPresent.

@Internal
public boolean setSchemaIfNotPresent(String resource, Schema schema) {
    com.google.cloud.datacatalog.v1beta1.Schema dcSchema = SchemaUtils.toDataCatalog(schema);
    Entry entry = dataCatalog.lookupEntry(LookupEntryRequest.newBuilder().setSqlResource(resource).build());
    if (entry.getSchema().getColumnsCount() == 0) {
        dataCatalog.updateEntry(UpdateEntryRequest.newBuilder().setEntry(entry.toBuilder().setSchema(dcSchema).build()).setUpdateMask(FieldMask.newBuilder().addPaths("schema").build()).build());
        return true;
    } else {
        LOG.info(String.format("Not updating schema for '%s' since it already has one.", resource));
        return false;
    }
}
Also used : Entry(com.google.cloud.datacatalog.v1beta1.Entry) Internal(org.apache.beam.sdk.annotations.Internal)

Example 2 with Entry

use of com.google.cloud.datacatalog.v1.Entry in project xtext-core by eclipse.

the class ActionTestLanguage3SemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ActionLang3Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ActionLang3Package.ENTRY:
                sequence_ProductionRule2(context, (Entry) semanticObject);
                return;
            case ActionLang3Package.P1:
                sequence_ProductionRule1_P2_2(context, (P1) semanticObject);
                return;
            case ActionLang3Package.P2:
                sequence_ProductionRule1_P3_4(context, (P2) semanticObject);
                return;
            case ActionLang3Package.P3:
                sequence_ProductionRule1(context, (P3) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) P1(org.eclipse.xtext.testlanguages.actionLang3.P1) Action(org.eclipse.xtext.Action) Entry(org.eclipse.xtext.testlanguages.actionLang3.Entry) P2(org.eclipse.xtext.testlanguages.actionLang3.P2) P3(org.eclipse.xtext.testlanguages.actionLang3.P3) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with Entry

use of com.google.cloud.datacatalog.v1.Entry in project DataflowTemplates by GoogleCloudPlatform.

the class DataCatalogSchemaUtils method getSchemasForEntryGroup.

/**
 * Retrieve all of the {@link Schema}s associated to {@link Entry}s in an {@link EntryGroup}.
 */
public static Map<String, Schema> getSchemasForEntryGroup(String gcpProject, String entryGroupId) {
    DataCatalogClient client = null;
    try {
        client = DataCatalogClient.create();
    } catch (IOException e) {
        throw new RuntimeException("Unable to create a DataCatalogClient", e);
    }
    if (client == null) {
        return null;
    }
    String formattedParent = DataCatalogClient.formatEntryGroupName(gcpProject, DEFAULT_LOCATION, entryGroupId);
    List<Entry> entries = new ArrayList<>();
    ListEntriesRequest request = ListEntriesRequest.newBuilder().setParent(formattedParent).build();
    while (true) {
        ListEntriesResponse response = client.listEntriesCallable().call(request);
        entries.addAll(response.getEntriesList());
        String nextPageToken = response.getNextPageToken();
        if (!Strings.isNullOrEmpty(nextPageToken)) {
            request = request.toBuilder().setPageToken(nextPageToken).build();
        } else {
            break;
        }
    }
    LOG.debug("Fetched entries: {}", entries);
    return entries.stream().collect(Collectors.toMap(Entry::getDescription, e -> SchemaUtils.toBeamSchema(e.getSchema())));
}
Also used : ListEntriesResponse(com.google.cloud.datacatalog.v1beta1.ListEntriesResponse) Logger(org.slf4j.Logger) DataCatalogClient(com.google.cloud.datacatalog.v1beta1.DataCatalogClient) CreateEntryRequest(com.google.cloud.datacatalog.v1beta1.CreateEntryRequest) LocationName(com.google.cloud.datacatalog.v1beta1.LocationName) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) UpdateEntryRequest(com.google.cloud.datacatalog.v1beta1.UpdateEntryRequest) EntryGroupName(com.google.cloud.datacatalog.v1.EntryGroupName) Collectors(java.util.stream.Collectors) Schema(org.apache.beam.sdk.schemas.Schema) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) ApiException(com.google.api.gax.rpc.ApiException) LookupEntryRequest(com.google.cloud.datacatalog.v1beta1.LookupEntryRequest) ArrayList(java.util.ArrayList) EntryGroup(com.google.cloud.datacatalog.v1beta1.EntryGroup) ListEntriesResponse(com.google.cloud.datacatalog.v1beta1.ListEntriesResponse) Strings(com.google.common.base.Strings) List(java.util.List) Entry(com.google.cloud.datacatalog.v1beta1.Entry) Map(java.util.Map) ListEntriesRequest(com.google.cloud.datacatalog.v1beta1.ListEntriesRequest) CreateEntryGroupRequest(com.google.cloud.datacatalog.v1beta1.CreateEntryGroupRequest) Entry(com.google.cloud.datacatalog.v1beta1.Entry) ArrayList(java.util.ArrayList) DataCatalogClient(com.google.cloud.datacatalog.v1beta1.DataCatalogClient) IOException(java.io.IOException) ListEntriesRequest(com.google.cloud.datacatalog.v1beta1.ListEntriesRequest)

Example 4 with Entry

use of com.google.cloud.datacatalog.v1.Entry in project DataflowTemplates by GoogleCloudPlatform.

the class DataCatalogSchemaUtils method getSchemaFromPubSubTopic.

/**
 * Retrieve the {@link Schema} associated to a Pub/Sub topics in an.
 *
 * <p>This method is to be used in multi-topic mode, where a single {@link Schema} is associated
 * to a single Pub/Sub topic.
 */
public static Schema getSchemaFromPubSubTopic(String gcpProject, String pubsubTopic) {
    DataCatalogClient client = null;
    try {
        client = DataCatalogClient.create();
    } catch (IOException e) {
        throw new RuntimeException("Unable to create a DataCatalogClient", e);
    }
    if (client == null) {
        return null;
    }
    Entry entry = lookupPubSubEntry(client, pubsubTopic, gcpProject);
    if (entry == null) {
        // TODO(pabloem) Handle a failed entry lookup
        return null;
    }
    return SchemaUtils.toBeamSchema(entry.getSchema());
}
Also used : Entry(com.google.cloud.datacatalog.v1beta1.Entry) DataCatalogClient(com.google.cloud.datacatalog.v1beta1.DataCatalogClient) IOException(java.io.IOException)

Example 5 with Entry

use of com.google.cloud.datacatalog.v1.Entry in project java-docs-samples by GoogleCloudPlatform.

the class CreateFilesetEntry method createEntry.

// Create Fileset Entry.
public static void createEntry(String projectId, String entryGroupId, String entryId) {
    // Currently, Data Catalog stores metadata in the us-central1 region.
    String location = "us-central1";
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) {
        // that will be used in step 3.
        try {
            dataCatalogClient.deleteEntry(EntryName.of(projectId, location, entryGroupId, entryId).toString());
        } catch (PermissionDeniedException | NotFoundException e) {
            // PermissionDeniedException or NotFoundException are thrown if
            // Entry does not exist.
            System.out.println("Entry does not exist.");
        }
        // that will be used in step 2.
        try {
            dataCatalogClient.deleteEntryGroup(EntryGroupName.of(projectId, location, entryGroupId).toString());
        } catch (PermissionDeniedException | NotFoundException e) {
            // PermissionDeniedException or NotFoundException are thrown if
            // Entry Group does not exist.
            System.out.println("Entry Group does not exist.");
        }
        // 2. Create an Entry Group.
        // Construct the EntryGroup for the EntryGroup request.
        EntryGroup entryGroup = EntryGroup.newBuilder().setDisplayName("My Fileset Entry Group").setDescription("This Entry Group consists of ....").build();
        // Construct the EntryGroup request to be sent by the client.
        CreateEntryGroupRequest entryGroupRequest = CreateEntryGroupRequest.newBuilder().setParent(LocationName.of(projectId, location).toString()).setEntryGroupId(entryGroupId).setEntryGroup(entryGroup).build();
        // Use the client to send the API request.
        EntryGroup entryGroupResponse = dataCatalogClient.createEntryGroup(entryGroupRequest);
        System.out.printf("\nEntry Group created with name: %s\n", entryGroupResponse.getName());
        // 3. Create a Fileset Entry.
        // Construct the Entry for the Entry request.
        Entry entry = Entry.newBuilder().setDisplayName("My Fileset").setDescription("This fileset consists of ....").setGcsFilesetSpec(GcsFilesetSpec.newBuilder().addFilePatterns("gs://cloud-samples-data/*").build()).setSchema(Schema.newBuilder().addColumns(ColumnSchema.newBuilder().setColumn("first_name").setDescription("First name").setMode("REQUIRED").setType("STRING").build()).addColumns(ColumnSchema.newBuilder().setColumn("last_name").setDescription("Last name").setMode("REQUIRED").setType("STRING").build()).addColumns(ColumnSchema.newBuilder().setColumn("addresses").setDescription("Addresses").setMode("REPEATED").setType("RECORD").addSubcolumns(ColumnSchema.newBuilder().setColumn("city").setDescription("City").setMode("NULLABLE").setType("STRING").build()).addSubcolumns(ColumnSchema.newBuilder().setColumn("state").setDescription("State").setMode("NULLABLE").setType("STRING").build()).build()).build()).setType(EntryType.FILESET).build();
        // Construct the Entry request to be sent by the client.
        CreateEntryRequest entryRequest = CreateEntryRequest.newBuilder().setParent(entryGroupResponse.getName()).setEntryId(entryId).setEntry(entry).build();
        // Use the client to send the API request.
        Entry entryResponse = dataCatalogClient.createEntry(entryRequest);
        System.out.printf("\nEntry created with name: %s\n", entryResponse.getName());
    } catch (AlreadyExistsException | IOException e) {
        // AlreadyExistsException's are thrown if EntryGroup or Entry already exists.
        // IOException's are thrown when unable to create the DataCatalogClient,
        // for example an invalid Service Account path.
        System.out.println("Error in create entry process:\n" + e.toString());
    }
}
Also used : Entry(com.google.cloud.datacatalog.v1.Entry) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) CreateEntryGroupRequest(com.google.cloud.datacatalog.v1.CreateEntryGroupRequest) EntryGroup(com.google.cloud.datacatalog.v1.EntryGroup) DataCatalogClient(com.google.cloud.datacatalog.v1.DataCatalogClient) NotFoundException(com.google.api.gax.rpc.NotFoundException) CreateEntryRequest(com.google.cloud.datacatalog.v1.CreateEntryRequest) PermissionDeniedException(com.google.api.gax.rpc.PermissionDeniedException) IOException(java.io.IOException)

Aggregations

Entry (com.google.cloud.datacatalog.v1beta1.Entry)5 IOException (java.io.IOException)4 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)2 ApiException (com.google.api.gax.rpc.ApiException)2 DataCatalogClient (com.google.cloud.datacatalog.v1beta1.DataCatalogClient)2 LookupEntryRequest (com.google.cloud.datacatalog.v1beta1.LookupEntryRequest)2 ApiFuture (com.google.api.core.ApiFuture)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 PermissionDeniedException (com.google.api.gax.rpc.PermissionDeniedException)1 CreateEntryGroupRequest (com.google.cloud.datacatalog.v1.CreateEntryGroupRequest)1 CreateEntryRequest (com.google.cloud.datacatalog.v1.CreateEntryRequest)1 DataCatalogClient (com.google.cloud.datacatalog.v1.DataCatalogClient)1 Entry (com.google.cloud.datacatalog.v1.Entry)1 EntryGroup (com.google.cloud.datacatalog.v1.EntryGroup)1 EntryGroupName (com.google.cloud.datacatalog.v1.EntryGroupName)1 CreateEntryGroupRequest (com.google.cloud.datacatalog.v1beta1.CreateEntryGroupRequest)1 CreateEntryRequest (com.google.cloud.datacatalog.v1beta1.CreateEntryRequest)1 EntryGroup (com.google.cloud.datacatalog.v1beta1.EntryGroup)1 ListEntriesRequest (com.google.cloud.datacatalog.v1beta1.ListEntriesRequest)1 ListEntriesResponse (com.google.cloud.datacatalog.v1beta1.ListEntriesResponse)1