转换逻辑模型为物理模型
功能介绍
转换逻辑模型为物理模型,转换成功则显示转换后的目标模型信息。
异常:目标模型信息的“id”等属性为null时,则需要调用《获取操作结果》接口查看具体报错信息:GET https://{endpoint}/v1/{project_id}/design/operation-results?operation_type=TRANSFORM_LOGIC_MODEL&operation_id={model_id},其中{model_id}为本接口的路径参数。
约束与限制:
1、target_model_id与target_model_name不对应时,target_model_id优先级高于target_model_name。
2、target_model_id与dw_type不对应时,会找不到模型,提示:模型不存在。
调用方法
请参见如何调用API。
URI
PUT /v1/{project_id}/design/workspaces/{model_id}/transform
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
IAM Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值) 使用Token认证时必选。 |
workspace |
是 |
String |
工作空间ID,获取方法请参见实例ID和工作空间ID。 |
X-Project-Id |
否 |
String |
项目ID,获取方法请参见项目ID和账号ID。 多project场景采用AK/SK认证的接口请求,则该字段必选。 |
Content-Type |
否 |
String |
默认值:application/json;charset=UTF-8 可选,有Body体的情况下必选,没有Body体则无需填写和校验。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
target_model_id |
否 |
String |
关系建模的目标模型ID,ID字符串。 注意:当使用已经存在的target_model_name时,该值为必填项,且要与已存在的模型ID保持一致。 |
target_model_name |
是 |
String |
工作区名字。 |
description |
否 |
String |
描述。 |
update_exist_tables |
否 |
Boolean |
是否更新已有表。 |
ids |
否 |
Array of strings |
需要物化的逻辑实体的ID列表,ID字符串。 |
dw_type |
是 |
String |
数据连接类型,对应表所在的数仓类型,取值可以为DWS、MRS_HIVE、POSTGRESQL、MRS_SPARK、CLICKHOUSE、MYSQL、ORACLE和DORIS等。 |
connection_id |
否 |
String |
转化后物理表所属的数据连接ID。 |
database |
否 |
String |
转化后物理表所属的数据库。 |
queue |
否 |
String |
转化后物理表所属的队列(仅DLI)。 |
schema |
否 |
String |
转化后物理表所属的schema(仅DWS和PostgreSQL)。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
data |
data object |
data,统一的返回结果的最外层数据结构。 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
编号,ID字符串。 |
name |
String |
工作区名字。 |
description |
String |
描述。 |
is_physical |
Boolean |
是否为物理表。 |
frequent |
Boolean |
是否为常用。 |
top |
Boolean |
分层治理。 |
level |
String |
数据治理分层。 枚举值:
|
dw_type |
String |
数据连接类型,对应表所在的数仓类型,取值可以为DWS、MRS_HIVE、POSTGRESQL、MRS_SPARK、CLICKHOUSE、MYSQL、ORACLE和DORIS等。 |
create_time |
String |
创建时间,只读,格式遵循RFC3339,精确到秒,UTC时区,即yyyy-mm-ddTHH:MM:SSZ,如1970-01-01T00:00:00Z。 |
update_time |
String |
更新时间,只读,格式遵循RFC3339,精确到秒,UTC时区,即yyyy-mm-ddTHH:MM:SSZ,如1970-01-01T00:00:00Z。 |
create_by |
String |
创建人。 |
update_by |
String |
更新人。 |
type |
String |
工作区类型枚举。 枚举值:
|
biz_catalog_ids |
String |
关联的业务分层的ID列表 {"l1Ids":[],"l2Ids":[],"l3Ids":[]}。 |
databases |
Array of strings |
数据库名称数组。 |
table_model_prefix |
String |
模型校验前缀,长度不超过100,数字字母下划线组成,字母开头 |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码,如DS.6000,请求处理失败。 |
error_msg |
String |
错误信息。 |
data |
Object |
返回的数据信息。 |
状态码:401
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码,如DS.6000,请求处理失败。 |
error_msg |
String |
错误信息。 |
data |
Object |
返回的数据信息。 |
状态码:403
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码,如DS.6000,请求处理失败。 |
error_msg |
String |
错误信息。 |
data |
Object |
返回的数据信息。 |
请求示例
将model_id为1184439352260976640的逻辑模型转化为物理模型。
PUT https://{endpoint}/v1/{project_id}/design/workspaces/1184439352260976640/transform { "target_model_id" : "1234524753512017920", "target_model_name" : "dws0429", "update_exist_tables" : false, "description" : "", "dw_type" : "DWS", "connection_id" : "92558783022c4ac88965e045b7c7078c", "database" : "gaussdb", "schema" : "public", "ids" : [ "1238437092523188266" ] }
响应示例
状态码:200
Success,返回data数据是目标物理WorkspaceVO信息,最终的转换结果需要从获取批量操作结果的接口中获取。
{ "data" : { "value" : { "id" : "1234524753512017920", "name" : "dws0429", "description" : "", "is_physical" : true, "frequent" : false, "top" : true, "level" : null, "dw_type" : "DWS", "create_time" : "2024-04-29T15:20:38+08:00", "update_time" : "2024-04-29T15:20:38+08:00", "create_by" : "test_uesr", "update_by" : "test_uesr", "type" : "THIRD_NF", "biz_catalog_ids" : null, "databases" : null, "table_model_prefix" : "" } } }
状态码:400
BadRequest
{ "error_code" : "DS.60xx", "error_msg" : "The user request is illegal." }
状态码:401
Unauthorized
{ "error_code" : "DS.60xx", "error_msg" : "User authentication failed." }
状态码:403
Forbidden
{ "error_code" : "DS.60xx", "error_msg" : "The user does not have permission to call this API." }
SDK代码示例
SDK代码示例如下。
将model_id为1184439352260976640的逻辑模型转化为物理模型。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion; import com.huaweicloud.sdk.dataartsstudio.v1.*; import com.huaweicloud.sdk.dataartsstudio.v1.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateDesignTableModelsFromLogicSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); DataArtsStudioClient client = DataArtsStudioClient.newBuilder() .withCredential(auth) .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateDesignTableModelsFromLogicRequest request = new BatchCreateDesignTableModelsFromLogicRequest(); request.withModelId("{model_id}"); WorkspaceTransformVO body = new WorkspaceTransformVO(); List<String> listbodyIds = new ArrayList<>(); listbodyIds.add("1238437092523188266"); body.withSchema("public"); body.withDatabase("gaussdb"); body.withConnectionId("92558783022c4ac88965e045b7c7078c"); body.withDwType("DWS"); body.withIds(listbodyIds); body.withUpdateExistTables(false); body.withDescription(""); body.withTargetModelName("dws0429"); body.withTargetModelId("1234524753512017920"); request.withBody(body); try { BatchCreateDesignTableModelsFromLogicResponse response = client.batchCreateDesignTableModelsFromLogic(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
将model_id为1184439352260976640的逻辑模型转化为物理模型。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdataartsstudio.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = DataArtsStudioClient.new_builder() \ .with_credentials(credentials) \ .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateDesignTableModelsFromLogicRequest() request.model_id = "{model_id}" listIdsbody = [ "1238437092523188266" ] request.body = WorkspaceTransformVO( schema="public", database="gaussdb", connection_id="92558783022c4ac88965e045b7c7078c", dw_type="DWS", ids=listIdsbody, update_exist_tables=False, description="", target_model_name="dws0429", target_model_id="1234524753512017920" ) response = client.batch_create_design_table_models_from_logic(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
将model_id为1184439352260976640的逻辑模型转化为物理模型。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := dataartsstudio.NewDataArtsStudioClient( dataartsstudio.DataArtsStudioClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateDesignTableModelsFromLogicRequest{} request.ModelId = "{model_id}" var listIdsbody = []string{ "1238437092523188266", } schemaWorkspaceTransformVo:= "public" databaseWorkspaceTransformVo:= "gaussdb" connectionIdWorkspaceTransformVo:= "92558783022c4ac88965e045b7c7078c" updateExistTablesWorkspaceTransformVo:= false descriptionWorkspaceTransformVo:= "" targetModelNameWorkspaceTransformVo:= "dws0429" targetModelIdWorkspaceTransformVo:= "1234524753512017920" request.Body = &model.WorkspaceTransformVo{ Schema: &schemaWorkspaceTransformVo, Database: &databaseWorkspaceTransformVo, ConnectionId: &connectionIdWorkspaceTransformVo, DwType: "DWS", Ids: &listIdsbody, UpdateExistTables: &updateExistTablesWorkspaceTransformVo, Description: &descriptionWorkspaceTransformVo, TargetModelName: &targetModelNameWorkspaceTransformVo, TargetModelId: &targetModelIdWorkspaceTransformVo, } response, err := client.BatchCreateDesignTableModelsFromLogic(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
Success,返回data数据是目标物理WorkspaceVO信息,最终的转换结果需要从获取批量操作结果的接口中获取。 |
400 |
BadRequest |
401 |
Unauthorized |
403 |
Forbidden |