建立項目類型
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples in Java and Python demonstrating how to create an entry type within Google Cloud Dataplex.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up authentication using Application Default Credentials and following the Dataplex quickstart for either Java or Python.\u003c/p\u003e\n"],["\u003cp\u003eCreating an entry type requires specifying a project ID, location, and entry type ID, along with a description and required aspects.\u003c/p\u003e\n"],["\u003cp\u003eThe required aspects, which are specified during creation, will need to be attached to each entry created within that entry type and cannot be altered after creation.\u003c/p\u003e\n"],["\u003cp\u003eThe samples utilize the Dataplex CatalogServiceClient to facilitate the creation of the entry type asynchronously.\u003c/p\u003e\n"]]],[],null,["# Create entry type\n\nCreate an entry 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.CatalogServiceClient.html;\n import com.google.cloud.dataplex.v1.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html;\n import com.google.cloud.dataplex.v1.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.LocationName.html;\n\n public class CreateEntryType {\n\n public static void main(String[] args) throws Exception {\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 entryTypeId = \"MY_ENTRY_TYPE_ID\";\n\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html createdEntryType = createEntryType(projectId, location, entryTypeId);\n System.out.println(\"Successfully created entry type: \" + createdEntryType.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html#com_google_cloud_dataplex_v1_EntryType_getName__());\n }\n\n // Method to create Entry Type located in projectId, location and with entryTypeId\n public static https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html createEntryType(String projectId, String location, String entryTypeId)\n throws Exception {\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.LocationName.html locationName = https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.LocationName.html.of(projectId, location);\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html entryType =\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html.newBuilder()\n .setDescription(\"description of the entry type\")\n // Required aspects will need to be attached to every entry created for this entry\n // type.\n // You cannot change required aspects for entry type once it is created.\n .https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.Builder.html#com_google_cloud_dataplex_v1_EntryType_Builder_addRequiredAspects_com_google_cloud_dataplex_v1_EntryType_AspectInfo_(\n https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.EntryType.html.AspectInfo.newBuilder()\n // Example of system aspect type.\n // It is also possible to specify custom aspect type.\n .setType(\"projects/dataplex-types/locations/global/aspectTypes/schema\")\n .build())\n .build();\n return client.https://cloud.google.com/java/docs/reference/google-cloud-dataplex/latest/com.google.cloud.dataplex.v1.CatalogServiceClient.html#com_google_cloud_dataplex_v1_CatalogServiceClient_createEntryTypeAsync_com_google_cloud_dataplex_v1_CreateEntryTypeRequest_(locationName, entryType, entryTypeId).get();\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 create_entry_type(\n project_id: str, location: str, entry_type_id: str\n ) -\u003e dataplex_v1.EntryType:\n \"\"\"Method to create Entry Type located in project_id, location and with entry_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 Entry Type location\n parent = f\"projects/{project_id}/locations/{location}\"\n entry_type = https://cloud.google.com/python/docs/reference/dataplex/latest/.https://cloud.google.com/python/docs/reference/dataplex/latest/google.cloud.dataplex_v1.types.EntryType.html(\n description=\"description of the entry type\",\n # Required aspects will need to be attached to every entry created for this entry type.\n # You cannot change required aspects for entry type once it is created.\n required_aspects=[\n https://cloud.google.com/python/docs/reference/dataplex/latest/.https://cloud.google.com/python/docs/reference/dataplex/latest/google.cloud.dataplex_v1.types.EntryType.html.https://cloud.google.com/python/docs/reference/dataplex/latest/google.cloud.dataplex_v1.types.EntryType.AspectInfo.html(\n # Example of system aspect type.\n # It is also possible to specify custom aspect type.\n type=\"projects/dataplex-types/locations/global/aspectTypes/generic\"\n )\n ],\n )\n create_operation = client.create_entry_type(\n parent=parent, entry_type=entry_type, entry_type_id=entry_type_id\n )\n return create_operation.result(60)\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 entry_type_id = \"MY_ENTRY_TYPE_ID\"\n\n created_entry_type = create_entry_type(project_id, location, entry_type_id)\n print(f\"Successfully created entry type: {created_entry_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)."]]