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.

HTTP
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

Shell
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.

Shell
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.

Shell
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

config_type

integer

Yes

Fixed to 3, indicating structured loading of the database. Fixed to 3.

name

string

No

Task name.

structured_load_config

object

Yes

Structured loading configuration.

structured_load_config.version

integer

Yes

Fixed to 1.

structured_load_config.source

object

Yes

Source table.

structured_load_config.source.connector_id

string

Yes

Source connector ID.

structured_load_config.source.source_type

string

Yes

Source type.

structured_load_config.source.database

string

Yes

Source database.

structured_load_config.source.table

string

Yes

Source table name. Source table.

structured_load_config.target

object

Yes

There is already a target table.

structured_load_config.target.mode

string

Yes

Fixed to existing. Fixed to new.

structured_load_config.target.database_id

string

Yes

Target database ID. The database ID where the new table is located.

structured_load_config.target.table_id

string

Yes

Target table ID already exists.

structured_load_config.mapping

array of object

Yes

Mapping of source fields to target columns. Field mapping.

structured_load_config.mapping[].source

object

Yes

Source column.

structured_load_config.mapping[].source.kind

string

Yes

Source field representation.

structured_load_config.mapping[].source.column

string

Yes

Source listing.

structured_load_config.mapping[].target_column

string

Yes

Target column name.

structured_load_config.mapping[].target_type

string

Yes

Target column type.

structured_load_config.mapping[].nullable

boolean

Yes

Whether the target column is nullable.

structured_load_config.mapping[].primary_key

boolean

Yes

Whether the target column is the primary key.

structured_load_config.mapping[].allow_duplicate_source

boolean

Yes

Whether to allow reuse of source columns.

structured_load_config.load_policy

object

Yes

One-time import strategy.

structured_load_config.load_policy.run_mode

string

Yes

Fixed to once. Fixed to periodic.

structured_load_config.load_policy.initial_load_rule

string

Yes

Write rules are loaded for the first time. Loading rules for the first time.

structured_load_config.load_policy.conflict_policy

string

Yes

Conflict handling rules. Conflict rules.

structured_load_config.load_policy.max_rows_per_batch

integer

No

Maximum number of rows per batch.

structured_load_config.compute

object

Yes

Compute resource settings.

structured_load_config.compute.task_compute_resource_id

string

Yes

Task compute resources.

structured_load_config.compute.query_compute_resource_id

string

Yes

Query compute resources.

structured_load_config.compute.priority

string

Yes

Task priority.

structured_load_config.consistency_contract

object

Yes

Data consistency configuration.

structured_load_config.consistency_contract.contract_kind

string

Yes

Data consistency type.

structured_load_config.consistency_contract.proof_kind

string

Yes

Proof type.

structured_load_config.consistency_contract.proof_hash

string

Yes

The field mapping generates the proof hash in the result.

structured_load_config.consistency_contract.capability_profile_hash

string

Yes

The field map generates the capability profile hash in the result.

structured_load_config.incremental

object

Required when incremental

Incremental read strategy.

structured_load_config.incremental.watermark

object

Required when incremental

Persistent water level strategy.

structured_load_config.incremental.watermark.field

object

Required when incremental

Water level source field, example select order_id column.

structured_load_config.incremental.watermark.field.kind

string

Yes

The column source uses column.

structured_load_config.incremental.watermark.field.column

string

Required when kind=column

Actual source column name.

structured_load_config.incremental.watermark.tie_breakers

array of object

No

Extra sort field reference used when water levels are equal.

structured_load_config.incremental.watermark.lookback

string

No

Incremental lookback range.

structured_load_config.target.table_name

string

Yes

New table name.

structured_load_config.target.create_table.name

string

Yes

New table name.

structured_load_config.target.create_table.columns

array of object

Yes

New table column definition.

structured_load_config.target.create_table.columns[].name

string

Yes

Column name.

structured_load_config.target.create_table.columns[].data_type

string

Yes

Column type.

structured_load_config.target.create_table.columns[].primary_key

boolean

Yes

Whether it is the primary key.

structured_load_config.target.create_table.columns[].nullable

boolean

Yes

Whether it can be null.

structured_load_config.load_policy.sync_strategy

string

Yes

Cycle introduction strategy. Can be incremental or full_refresh.

structured_load_config.schedule.kind

string

Yes

Cycle type. An example is hourly.

structured_load_config.schedule.interval

integer

Required when hourly

Execution interval.

structured_load_config.schedule.timezone

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

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "task_id": "task_01"
  }
}

Field

Type

Description

code

string

OK on success.

msg

string

OK on success.

data.task_id

string

Create a new task ID.

Error response

JSON
{
  "code": "STRUCTURED_LOAD_CONFIG_INVALID",
  "msg": "invalid structured load configuration",
  "data": {
    "path": "structured_load_config.target"
  }
}

Field

Type

Description

code

string

error code.

msg

string

Readable error message.

data.path

string

The field path corresponding to the configuration error.

Last updated on