How to retrieve tagged column using Google Data Catalog Java API

811 views Asked by At

I am able to search for tag templates using the Java Google Data Catalog library, and do sub search on the tag name to find the big query tables the tags are used, but I can't figure out how to find which columns are using the tags. Here is some sample Java code:

TagTemplate template = dataCatalogClient.getTagTemplate(result.getRelativeResourceName());
SearchCatalogRequest innerSearch = SearchCatalogRequest.newBuilder().setScope(scope).setQuery("tag=" + template.getDisplayName()).build();
              SearchCatalogPagedResponse innerResponse = dataCatalogClient.searchCatalog( innerSearch );
for (SearchCatalogResult innerResult : innerResponse.iterateAll()) {
 LookupEntryRequest request = 
 LookupEntryRequest.newBuilder().setLinkedResource(linkedResource).build();               
                                  
  com.google.cloud.datacatalog.v1.Entry entry = dataCatalogClient.lookupEntry(request);
                  Schema schema = entry.getSchema();
                  java.util.List<com.google.cloud.datacatalog.v1.ColumnSchema> columnSchemas = 
   schema.getColumnsList();
}

The code above returns al the tag templates and where the big query tables that are using the tags, but I can't figure out how to find which columns are using the tags. Thanks in advance.

1

There are 1 answers

0
Scott Nichols On

I was able to figure this out on my own. To get the tags at the column level you have to list all the tags at the table level and check if assigned to a column with this Google Data Catalog API call:

              ListTagsPagedResponse tagsResponse = dataCatalogClient.listTags(entry.getName());
              for(Tag tag : tagsResponse.iterateAll()) {
                  System.out.println(tag);
              }