重要事項
僅淘汰 Microsoft Purview 資料控管功能
Microsoft Purview 統一目錄和傳統 Microsoft Purview 資料控管功能 (先前的 Azure Purview) 即將淘汰。 整個 Microsoft Purview 並未淘汰。 Microsoft Purview 資料安全性與合規性功能不受此公告影響,且 Microsoft 會繼續投資於此功能。
Microsoft 正在 Microsoft Fabric 中合併 其資料控管 功能。 無法再建立新的 Microsoft Purview 資料控管帳戶,而且現有的資料控管功能將維持在維護模式,直到 2027 年 11 月 12 日為止。
如需淘汰時間表、轉換指引,以及建議的後續步驟,請參閱 Microsoft Purview 資料控管淘汰公告。
在本教學課程中,您將了解如何使用 Microsoft Purview REST API 來:
- 在資料資產之間建立資產和沿襲關係。
- 查詢沿襲關係/路徑。
本文參考的 API:
必要條件
使用這些 API 需要 資料管理者和資料讀取者角色。 如需如何取得存取權杖的詳細資訊,請查看 本教學課程 。
概念
資產
在 Microsoft Purview 中,有兩種類型的基礎資產:DataSet 和程序。
- 包含 Azure SQL 資料表、Oracle 資料表等資料的資料集資產應從 DataSet 繼承。
- 處理資料的處理程序資產,例如資料管道、查詢、函式等,應從處理程序繼承。
請參閱 資產和型別 ,以瞭解資料集和流程的型別定義。
關聯和沿襲
在 Microsoft Purview 中,沿襲有三種關聯性:
- dataset_process_inputs:將 DataSet 連線至流程,這表示 DataSet 是流程的輸入
- process_dataset_outputs:將程序連線至 DataSet,這表示程序會產生 DataSet
- direct_lineage_dataset_dataset: 將 DataSet1 連線至 DataSet2,這表示 DataSet1 是 DataSet2 的上游,雖然我們並不知道它們之間的確切處理序是哪一個
範例 1:以下是具有 2 個資料集、一個處理序和兩個沿襲關係的沿襲範例:
資料集--->dataset_process_inputs ---> --- process_dataset_outputs --->> DataSet
範例 2:具有 2 個資料集和一個沿襲關係的沿襲的另一個範例:
資料集---> direct_lineage_dataset_dataset ---> DataSet
在資料資產之間建立資產和沿襲關係
在下列各節中,讓我們以 hive_table 做為 DataSet 的範例類型,並將 hive_query_process 做為流程的範例類型。 我們將使用這兩種類型建立資產,並在它們之間建立沿襲。 您可以使用繼承自 DataSet 或 Process 的任何其他類型來建立沿襲。
範例 1
透過 API 建立資產
如果您想要建立沿襲的資產尚未在 Microsoft Purview 中建立,您可以呼叫下列 API 來建立它們。
API: 大量建立資產
工作:建立兩個hive_tables為資料集 - table1 和 table2,每個資料有 2 個hive_columns - column1 和 column2。
POST {endpoint}/datamap/api/atlas/v2/entity/bulk
與身體:
{
"entities": [
{
"typeName": "hive_table",
"attributes": {
"qualifiedName": "test_lineage.table1",
"name": "table1"
},
"relationshipAttributes": {
"columns": [
{
"guid": "-11",
"typeName": "hive_column"
},{
"guid": "-12",
"typeName": "hive_column"
}
]
},
"guid": "-1"
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table1#column1",
"name": "column1",
"type": "int"
},
"guid": "-11",
"relationshipAttributes": {
"table": {
"guid": "-1",
"typeName": "hive_table"
}
}
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table1#column2",
"name": "column2",
"type": "int"
},
"guid": "-12",
"relationshipAttributes": {
"table": {
"guid": "-1",
"typeName": "hive_table"
}
}
},
{
"typeName": "hive_table",
"attributes": {
"qualifiedName": "test_lineage.table2",
"name": "table2"
},
"relationshipAttributes": {
"columns": [
{
"guid": "-21",
"typeName": "hive_column"
},{
"guid": "-22",
"typeName": "hive_column"
}
]
},
"guid": "-2"
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table2#column1",
"name": "column1",
"type": "int"
},
"guid": "-21",
"relationshipAttributes": {
"table": {
"guid": "-2",
"typeName": "hive_table"
}
}
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table2#column2",
"name": "column2",
"type": "int"
},
"guid": "-22",
"relationshipAttributes": {
"table": {
"guid": "-2",
"typeName": "hive_table"
}
}
}
]
}
工作:建立程序資產 'hive_view_query'
POST {endpoint}/datamap/api/atlas/v2/entity/bulk
與身體:
{
"entities": [
{
"typeName": "hive_view_query",
"attributes": {
"qualifiedName": "test_lineage.HiveQuery1",
"name": "HiveQuery1",
"columnMapping": "[{\"DatasetMapping\":{\"Source\":\"test_lineage.table1\",\"Sink\":\"test_lineage.table2\"},\"ColumnMapping\":[{\"Source\":\"column1\",\"Sink\":\"column1\"},{\"Source\":\"column2\",\"Sink\":\"column2\"}]}]"
},
"guid": "-1"
}
]
}
上述 API 呼叫會導致建立兩個 hive_tables (資料集) 和一個hive_view_query (處理程序) 。
在資料集與流程之間建立沿襲關係
API: 建立關聯
工作:從 table1 建立沿襲 -> HiveQuery1 (,也就是資料集 -> 處理程序)
POST {endpoint}/datamap/api/atlas/v2/relationship
與身體:
{
"typeName": "dataset_process_inputs",
"guid": "-1",
"end1": {
"typeName": "hive_table",
"uniqueAttributes": {
"qualifiedName": "test_lineage.table1"
}
},
"end2": {
"typeName": "Process",
"uniqueAttributes": {
"qualifiedName": "test_lineage.HiveQuery1"
}
}
}
工作:從 HiveQuery1 建立沿襲 -> 資料表 2 (也就是程序 -> 資料集)
POST {endpoint}/datamap/api/atlas/v2/relationship
與身體:
{
"typeName": "process_dataset_outputs",
"guid": "-2",
"end1": {
"typeName": "Process",
"uniqueAttributes": {
"qualifiedName": "test_lineage.HiveQuery1"
}
},
"end2": {
"typeName": "hive_table",
"uniqueAttributes": {
"qualifiedName": "test_lineage.table2"
}
}
}
檢視沿襲
建立資產和沿襲關聯性之後,您可以在 Microsoft Purview 中查看沿襲圖表:
範例 2
建立含兩欄的登錄區資料表 table3
API: 大量建立資產
工作:建立具有 2 個hive_columns、column1 和 column2 的 table3
POST {endpoint}/datamap/api/atlas/v2/entity/bulk
與身體:
{
"entities": [
{
"typeName": "hive_table",
"attributes": {
"qualifiedName": "test_lineage.table3",
"name": "table3"
},
"relationshipAttributes": {
"columns": [
{
"guid": "-31",
"typeName": "hive_column"
},{
"guid": "-32",
"typeName": "hive_column"
}
]
},
"guid": "-3"
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table3#column1",
"name": "column1",
"type": "int"
},
"guid": "-31",
"relationshipAttributes": {
"table": {
"guid": "-3",
"typeName": "hive_table"
}
}
},
{
"typeName": "hive_column",
"attributes": {
"qualifiedName": "test_lineage.table3#column2",
"name": "column2",
"type": "int"
},
"guid": "-32",
"relationshipAttributes": {
"table": {
"guid": "-3",
"typeName": "hive_table"
}
}
}
]
}
使用欄對應建立資料表 2 和資料表 3 之間的直接沿襲
API: 建立關聯
工作:從 table2 -> table3 建立沿襲 (亦即,資料集 -> 具有欄對應的資料集)
POST {endpoint}/datamap/api/atlas/v2/relationship
與身體:
{
"typeName": "direct_lineage_dataset_dataset",
"guid": "-1",
"end1": {
"typeName": "hive_table",
"uniqueAttributes": {
"qualifiedName": "test_lineage.table2"
}
},
"end2": {
"typeName": " hive_table ",
"uniqueAttributes": {
"qualifiedName": "test_lineage.table3"
}
},
"attributes": {
"columnMapping": "[{\"Source\":\"column1\",\"Sink\":\"column1\"},{\"Source\":\"column2\",\"Sink\":\"column2\"}]"
}
}
檢視沿襲
現在,由上述範例 1 & 範例 2 (的沿襲圖) 變成:
請注意,table2 會直接連結到 table3,兩者之間沒有 HiveQuery。
查詢沿襲關係/路徑
API: 依 GUID 取得沿襲
工作:透過 REST API 取得 table2 的沿襲
GET {{endpoint}}/api/atlas/v2/lineage/{{guid_of_table2}}?direction=BOTH
下方您可以 JSON 回應承載:
{
"baseEntityGuid": "2a12b3ff-5816-4222-833a-035bf82e06e0",
"lineageDirection": "BOTH",
"lineageDepth": 3,
"lineageWidth": -1,
"childrenCount": -1,
"guidEntityMap": {
"16b93b78-8683-4f88-9651-24c4a9d797b0": {
"typeName": "hive_table",
"attributes": {
"temporary": false,
"lastAccessTime": 0,
"createTime": 0,
"qualifiedName": "test_lineage.table3",
"name": "table3",
"retention": 0
},
"lastModifiedTS": "1",
"guid": "16b93b78-8683-4f88-9651-24c4a9d797b0",
"status": "ACTIVE",
"displayText": "table3",
"classificationNames": [],
"meaningNames": [],
"meanings": [],
"isIncomplete": false,
"labels": [],
"isIndexed": true
},
"cb22ba23-47a2-4149-ade6-e3d9642fe592": {
"typeName": "hive_table",
"attributes": {
"temporary": false,
"lastAccessTime": 0,
"createTime": 0,
"qualifiedName": "test_lineage.table1",
"name": "table1",
"retention": 0
},
"lastModifiedTS": "1",
"guid": "cb22ba23-47a2-4149-ade6-e3d9642fe592",
"status": "ACTIVE",
"displayText": "table1",
"classificationNames": [],
"meaningNames": [],
"meanings": [],
"isIncomplete": false,
"labels": [],
"isIndexed": true
},
"bbeacce6-5bde-46f7-8fe4-689cbb36ba51": {
"typeName": "hive_view_query",
"attributes": {
"qualifiedName": "test_lineage.HiveQuery1",
"name": "HiveQuery1",
"columnMapping": "[{\"DatasetMapping\":{\"Source\":\"test_lineage.table1\",\"Sink\":\"test_lineage.table2\"},\"ColumnMapping\":[{\"Source\":\"column1\",\"Sink\":\"column1\"},{\"Source\":\"column2\",\"Sink\":\"column2\"}]}]"
},
"lastModifiedTS": "1",
"guid": "bbeacce6-5bde-46f7-8fe4-689cbb36ba51",
"status": "ACTIVE",
"displayText": "HiveQuery1",
"classificationNames": [],
"meaningNames": [],
"meanings": [],
"isIncomplete": false,
"labels": [],
"isIndexed": true
},
"2a12b3ff-5816-4222-833a-035bf82e06e0": {
"typeName": "hive_table",
"attributes": {
"temporary": false,
"lastAccessTime": 0,
"createTime": 0,
"qualifiedName": "test_lineage.table2",
"name": "table2",
"retention": 0
},
"lastModifiedTS": "1",
"guid": "2a12b3ff-5816-4222-833a-035bf82e06e0",
"status": "ACTIVE",
"displayText": "table2",
"classificationNames": [],
"meaningNames": [],
"meanings": [],
"isIncomplete": false,
"labels": [],
"isIndexed": true
}
},
"includeParent": false,
"relations": [
{
"fromEntityId": "2a12b3ff-5816-4222-833a-035bf82e06e0",
"toEntityId": "16b93b78-8683-4f88-9651-24c4a9d797b0",
"relationshipId": "23df8e3e-b066-40b2-be29-9fd90693c51b",
"columnMapping": "[{\"Source\":\"column1\",\"Sink\":\"column1\"},{\"Source\":\"column2\",\"Sink\":\"column2\"}]"
},
{
"fromEntityId": "bbeacce6-5bde-46f7-8fe4-689cbb36ba51",
"toEntityId": "2a12b3ff-5816-4222-833a-035bf82e06e0",
"relationshipId": "5fe8d378-39cd-4c6b-8ced-91b0152d3014"
},
{
"fromEntityId": "cb22ba23-47a2-4149-ade6-e3d9642fe592",
"toEntityId": "bbeacce6-5bde-46f7-8fe4-689cbb36ba51",
"relationshipId": "73e084bf-98a3-45fb-a1e4-c56cc40661b8"
}
],
"parentRelations": [],
"widthCounts": {
"INPUT": {
"cb22ba23-47a2-4149-ade6-e3d9642fe592": 0,
"bbeacce6-5bde-46f7-8fe4-689cbb36ba51": 1,
"2a12b3ff-5816-4222-833a-035bf82e06e0": 1
},
"OUTPUT": {
"16b93b78-8683-4f88-9651-24c4a9d797b0": 0,
"2a12b3ff-5816-4222-833a-035bf82e06e0": 1
}
}
}
其他資源
類型定義
所有資產/實體和關係都在類型系統中定義。
呼叫 清單所有類型定義 API,以取得 Microsoft Purview 執行個體中目前的類型定義。 如果您不確定要在所述的 API 呼叫中使用哪個 typeName,您可以檢查類型定義 API 以找到適當的資產/實體類型。
以下是此 API 的範例回應:
您可以看到,在上述回應的 entityDefs 中,定義了資產類型 (例如 oracle_table、oracle_view 等 ) 。 進一步查看此範例中 (的資產定義,oracle_view) 顯示資產是繼承的 DataSet 類型。
同樣地,您可以發現處理程序 (例如,Oracle_function) 繼承自「處理程序」類型,如下所示:
建立新的自訂類型
如果您想要建立自訂資產或流程,可以使用下列 API。
API: 建立 Typedef API
工作:建立自訂處理程序類型
POST {endpoint}/datamap/api/atlas/v2/types/typedefs
與身體:
{
"enumDefs": [],
"structDefs": [],
"classificationDefs": [],
"entityDefs": [
{
"name": "MyCustomServiceProcess",
"superTypes": [
"Process"
],
"typeVersion": "1.0",
"attributeDefs": []
}
],
"relationshipDefs": []
}
工作:建立自訂資料集類型
POST {endpoint}/datamap/api/atlas/v2/types/typedefs
與身體:
{
"enumDefs": [],
"structDefs": [],
"classificationDefs": [],
"entityDefs": [
{
"name": "MyCustomDataSet",
"superTypes": [
"DataSet"
],
"typeVersion": "1.0",
"attributeDefs": []
}
],
"relationshipDefs": []
}