Create a database structured loading task¶
Select a table, collection, or other supported object from the database connector and write data from it to the target table.
POST $CLOUDSIGMA_API_BASE/task
Before you call¶
Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. Prepare personal access token and target workspace ID that can access the target workspace. Also prepare a database connector, source object and target table or target database that supports structured import.
After generating the field mapping, save the returned mapping proof hash and capability configuration hash.
Request body¶
Replace the resource ID, source object, hash value in $CLOUDSIGMA_API_KEY, $WORKSPACE_ID, $IDEMPOTENCY_KEY and examples with actual values.
Import into existing table at one time
curl -X POST "$CLOUDSIGMA_API_BASE/task" \
-H "X-API-Key: $CLOUDSIGMA_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"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"
}
}
}
EOF
Import into new table
Set mode to new in target, and fill in the database, name and column definition of the new table. The remaining source, mapping, policy, compute resource, and consistency configuration fields are the same as in the previous scenario.
curl -X POST "$CLOUDSIGMA_API_BASE/task" -H "X-API-Key: $CLOUDSIGMA_API_KEY" -H "X-Workspace-ID: $WORKSPACE_ID" -H "Idempotency-Key: $IDEMPOTENCY_KEY" -H "Content-Type: application/json" -d @- <<EOF
{
"config_type": 3,
"structured_load_config": {
"version": 1,
"source": {
"connector_id": "$CONNECTOR_ID",
"source_type": "SOURCE_TYPE_MYSQL",
"database": "sales",
"table": "orders"
},
"target": {
"mode": "new",
"database_id": "$DATABASE_ID",
"table_name": "orders_copy",
"create_table": {
"name": "orders_copy",
"columns": [
{
"name": "order_id",
"data_type": "BIGINT",
"primary_key": true,
"nullable": false
}
]
}
},
"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"
},
"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"
}
}
}
EOF
Create a periodic import task
Periodic tasks set load_policy.run_mode to periodic, fill in sync_strategy and schedule. The source, target, mapping, compute resources, and consistency configuration must also be completely filled out.
curl -X POST "$CLOUDSIGMA_API_BASE/task" -H "X-API-Key: $CLOUDSIGMA_API_KEY" -H "X-Workspace-ID: $WORKSPACE_ID" -H "Idempotency-Key: $IDEMPOTENCY_KEY" -H "Content-Type: application/json" -d @- <<EOF
{
"config_type": 3,
"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": "periodic",
"initial_load_rule": "append",
"sync_strategy": "incremental",
"conflict_policy": "fail"
},
"schedule": {
"kind": "hourly",
"interval": 6,
"timezone": "Asia/Shanghai"
},
"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"
},
"incremental": {
"watermark": {
"field": {
"kind": "column",
"column": "order_id"
}
}
}
}
}
EOF
Import into existing table at one time
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
integer |
Yes |
Fixed to |
|
string |
No |
Task name. |
|
object |
Yes |
Structured loading configuration. |
|
integer |
Yes |
Fixed to |
|
object |
Yes |
Source table. |
|
string |
Yes |
Source connector ID. |
|
string |
Yes |
Source type. |
|
string |
Yes |
Source database. |
|
string |
Yes |
Source table name. Source table. |
|
object |
Yes |
There is already a target table. |
|
string |
Yes |
Fixed to |
|
string |
Yes |
Target database ID. The database ID where the new table is located. |
|
string |
Yes |
Target table ID already exists. |
|
array of object |
Yes |
Mapping of source fields to target columns. Field mapping. |
|
object |
Yes |
Source column. |
|
string |
Yes |
Source field representation. |
|
string |
Yes |
Source listing. |
|
string |
Yes |
Target column name. |
|
string |
Yes |
Target column type. |
|
boolean |
Yes |
Whether the target column is nullable. |
|
boolean |
Yes |
Whether the target column is the primary key. |
|
boolean |
Yes |
Whether to allow reuse of source columns. |
|
object |
Yes |
One-time import strategy. |
|
string |
Yes |
Fixed to |
|
string |
Yes |
Write rules are loaded for the first time. Loading rules for the first time. |
|
string |
Yes |
Conflict handling rules. Conflict rules. |
|
integer |
No |
Maximum number of rows per batch. |
|
object |
Yes |
Compute resource settings. |
|
string |
Yes |
Task compute resources. |
|
string |
Yes |
Query compute resources. |
|
string |
Yes |
Task priority. |
|
object |
Yes |
Data consistency configuration. |
|
string |
Yes |
Data consistency type. |
|
string |
Yes |
Proof type. |
|
string |
Yes |
The field mapping generates the proof hash in the result. |
|
string |
Yes |
The field map generates the capability profile hash in the result. |
|
object |
Required when incremental |
Incremental read strategy. |
|
object |
Required when incremental |
Persistent water level strategy. |
|
object |
Required when incremental |
Water level source field, example select order_id column. |
|
string |
Yes |
The column source uses column. |
|
string |
Required when kind=column |
Actual source column name. |
|
array of object |
No |
Extra sort field reference used when water levels are equal. |
|
string |
No |
Incremental lookback range. |
|
string |
Yes |
New table name. |
|
string |
Yes |
New table name. |
|
array of object |
Yes |
New table column definition. |
|
string |
Yes |
Column name. |
|
string |
Yes |
Column type. |
|
boolean |
Yes |
Whether it is the primary key. |
|
boolean |
Yes |
Whether it can be null. |
|
string |
Yes |
Cycle introduction strategy. Can be |
|
string |
Yes |
Cycle type. An example is |
|
integer |
Required when hourly |
Execution interval. |
|
string |
Yes |
IANA time zone. |
Periodic incremental mode requires incremental.watermark.field, using a fully qualified field reference for the watermark column. Selecting incremental without this field does not create a valid task.
Successful response¶
{
"code": "OK",
"msg": "OK",
"data": {
"task_id": "task_01"
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
string |
Create a new task ID. |
Error response¶
{
"code": "STRUCTURED_LOAD_CONFIG_INVALID",
"msg": "invalid structured load configuration",
"data": {
"path": "structured_load_config.target"
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
error code. |
|
string |
Readable error message. |
|
string |
The field path corresponding to the configuration error. |