Get aspect type
Stay organized with collections
Save and categorize content based on your preferences.
Retrieve an existing aspect type.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code samples in Java and Python for retrieving an existing aspect type within Google Cloud Dataplex.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples demonstrate how to initialize the \u003ccode\u003eCatalogServiceClient\u003c/code\u003e and use the \u003ccode\u003egetAspectType\u003c/code\u003e method to retrieve an aspect type by its project ID, location, and aspect type ID.\u003c/p\u003e\n"],["\u003cp\u003eThe provided samples require setting up Application Default Credentials for authentication and provide links for setting up authentication and getting started with Dataplex using client libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAspectTypeName\u003c/code\u003e in Java and \u003ccode\u003ename\u003c/code\u003e variable in Python represent the full resource name of the aspect type, which is a composition of the project ID, location, and aspect type ID.\u003c/p\u003e\n"]]],[],null,["# Get aspect type\n\nRetrieve an existing aspect type.\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Dataplex Universal Catalog quickstart using\nclient libraries](/dataplex/docs/reference/libraries).\n\n\nFor more information, see the\n[Dataplex Universal Catalog Java API\nreference documentation](/java/docs/reference/google-cloud-dataplex/latest/overview).\n\n\nTo authenticate to Dataplex Universal Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.dataplex.v1.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectType.html;\n import com.google.cloud.dataplex.v1.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectTypeName.html;\n import com.google.cloud.dataplex.v1.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.CatalogServiceClient.html;\n import java.io.IOException;\n\n public class GetAspectType {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"MY_PROJECT_ID\";\n // Available locations: https://cloud.google.com/dataplex/docs/locations\n String location = \"MY_LOCATION\";\n String aspectTypeId = \"MY_ASPECT_TYPE_ID\";\n\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectType.html aspectType = getAspectType(projectId, location, aspectTypeId);\n System.out.println(\"Aspect type retrieved successfully: \" + aspectType.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectType.html#com_google_cloud_dataplex_v1_AspectType_getName__());\n }\n\n // Method to retrieve Aspect Type located in projectId, location and with aspectTypeId\n public static https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectType.html getAspectType(String projectId, String location, String aspectTypeId)\n throws IOException {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n try (https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.CatalogServiceClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.CatalogServiceClient.html.create()) {\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectTypeName.html aspectTypeName = https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.AspectTypeName.html.of(projectId, location, aspectTypeId);\n return client.getAspectType(aspectTypeName);\n }\n }\n }\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Dataplex Universal Catalog quickstart using\nclient libraries](/dataplex/docs/reference/libraries).\n\n\nFor more information, see the\n[Dataplex Universal Catalog Python API\nreference documentation](/python/docs/reference/dataplex/latest).\n\n\nTo authenticate to Dataplex Universal Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/dataplex/latest/\n\n\n def get_aspect_type(\n project_id: str, location: str, aspect_type_id: str\n ) -\u003e dataplex_v1.AspectType:\n \"\"\"Method to retrieve Aspect Type located in project_id, location and with aspect_type_id\"\"\"\n\n # Initialize client that will be used to send requests across threads. This\n # client only needs to be created once, and can be reused for multiple requests.\n # After completing all of your requests, call the \"__exit__()\" method to safely\n # clean up any remaining background resources. Alternatively, use the client as\n # a context manager.\n with https://cloud.google.com/python/docs/reference/dataplex/latest/.https://cloud.google.com/python/docs/reference/dataplex/latest/google.cloud.dataplex_v1.services.catalog_service.CatalogServiceClient.html() as client:\n # The resource name of the Aspect Type\n name = (\n f\"projects/{project_id}/locations/{location}/aspectTypes/{aspect_type_id}\"\n )\n return client.get_aspect_type(name=name)\n\n\n if __name__ == \"__main__\":\n # TODO(developer): Replace these variables before running the sample.\n project_id = \"MY_PROJECT_ID\"\n # Available locations: https://cloud.google.com/dataplex/docs/locations\n location = \"MY_LOCATION\"\n aspect_type_id = \"MY_ASPECT_TYPE_ID\"\n\n aspect_type = get_aspect_type(project_id, location, aspect_type_id)\n print(f\"Aspect type retrieved successfully: {aspect_type.name}\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=dataplex)."]]