Create a database structured loading task¶
Read structured data from a table, collection, or other supporting object in a database connector and write it to the target data table. This request uses config_type: 3 and structured_load_config; cannot be mixed with source_config or volume_id from file imports, nor is a target directory field provided.
POST https://moi.matrixorigin.cn/newmoi/task
Before you call¶
Prepare a database connector, source object, target database or target table that supports structured loading, and mapping of source fields to target columns. The creation page will first read the fields and capabilities of the source object, and then generate the mapping and consistency contract in the request; please use proof_hash and capability_profile_hash obtained from the same source detection.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: The workspace ID of the task to be created, passed through theX-Workspace-IDHeader.$IDEMPOTENCY_KEY: The unique key for this creation request. Reuse this value when retrying the same request to avoid duplicate creation.$CONNECTOR_ID: Database source connector ID.$DATABASE_ID: Target database ID.$TARGET_TABLE_ID: Target table ID already exists.$PROOF_HASH: The proof-of-consistency hash returned by the origin probe.$CAPABILITY_PROFILE_HASH: The capability configuration hash returned by the source probe.
Request example¶
The following example loads data from MySQL’s sales.orders into an existing target table in one go. proof_hash and capability_profile_hash must use the source probe to actually return the value.
curl -X POST "https://moi.matrixorigin.cn/newmoi/task" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-H 'Content-Type: application/json' \
-d '{
"config_type":3,
"name":"orders-once",
"structured_load_config":{
"version":1,
"source":{"connector_id":"'"$CONNECTOR_ID"'","source_type":"SOURCE_TYPE_MYSQL","database":"sales","table":"orders"},
"target":{"mode":"existing","database_id":"'"$DATABASE_ID"'","table_id":"'"$TARGET_TABLE_ID"'"},
"mapping":[
{"source":{"kind":"column","column":"order_id"},"target_column":"order_id","target_type":"BIGINT","nullable":false,"primary_key":true,"allow_duplicate_source":false}
],
"load_policy":{"run_mode":"once","initial_load_rule":"append","conflict_policy":"fail","max_rows_per_batch":10000},
"compute":{"task_compute_resource_id":"default","query_compute_resource_id":"default","priority":"normal"},
"consistency_contract":{"contract_kind":"worker_proved_persistent_watermark","proof_kind":"db_metadata","proof_hash":"'"$PROOF_HASH"'","capability_profile_hash":"'"$CAPABILITY_PROFILE_HASH"'"}
}
}'
Request body¶
Field |
Type |
Is it required |
Description |
|---|---|---|---|
|
integer |
Yes |
Fixed to |
|
string |
No |
Task name. |
|
object |
Yes |
Structured load configuration. |
|
integer |
Yes |
Fixed to |
|
object |
Yes |
Source object. Includes |
|
object |
Yes |
Target table. Includes |
|
object |
Condition required |
Create a new target table definition containing the same |
|
object[] |
Yes |
At least one field mapping. Each item contains the sources |
|
object |
Yes |
Load policy. Contains |
|
object |
Condition required |
Required when |
|
object |
No |
Partition filtering for Hive sources; contains |
|
object |
No |
Inference and flattening settings for MongoDB sources. |
|
object |
Yes |
Compute resource settings, consisting of |
|
object |
Yes |
Source consistency contract, including |
[] after a type denotes an array. [] in a field path denotes each item in an array.
load_policy constraints¶
Field |
Allowed values |
Condition |
|---|---|---|
|
|
With |
|
|
|
|
|
With |
Successful response¶
The task has been accepted when the code in the response is OK. If the same request is retried with the same idempotent key, the response can contain the Idempotency-Replayed: true header.
{
"code": "OK",
"msg": "OK",
"data": {
"task_id": "task_01"
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
string |
New task ID. |
Error response¶
{
"code": "STRUCTURED_LOAD_CONFIG_INVALID",
"msg": "invalid structured load configuration",
"data": {
"path": "structured_load_config.target"
}
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
The caller does not have permission to read from the source connector or write to the target table. |
Check workspace, connector and target resource authorizations. |
|
|
Configuration fields are missing, target types do not match, or policy combinations are invalid. |
Correct the corresponding fields according to |
|
|
An idempotent key is passed repeatedly, or different requests are submitted using the same key. |
Use a unique key for each new request; only reuse the original key when retrying the same request. |
|
|
The service failed to create or schedule the task. |
Check the HTTP status and |
Follow-up operations¶
Log data.task_id. Confirm the source, target table, running status and structured load summary through Query task details; use Query run record to view a single run.