Import and Export Tasks¶
The official SDKs currently cover local-file import and task lookup by ID. General Connector import-task management, task listing and runtime controls, and export-task creation, rerun, file listing, and deletion are not yet present in the public clients of moi-python-sdk or moi-go-sdk.
This page therefore documents only implemented calls. For complete console workflows, see Data loading and Data export.
Choose the import target¶
Data |
Target |
Recommended Python call |
|---|---|---|
Documents, images, audio, video, and other unstructured files |
Volume |
|
CSV or another file that should become structured records |
New or existing Table |
Stage and preview, then call |
Upload requiring filtering, decompression, deduplication, or explicit Table configuration |
Target selected by Volume and Table configuration |
|
A file extension does not determine the business outcome. A CSV can be retained as a raw File in a Volume or parsed into a Table; those choices produce different assets.
Import a local file into an existing Table¶
First stage and preview the file:
from moi import SDKClient
sdk = SDKClient(client)
upload = client.upload_local_file_from_path(
"/data/orders.csv",
[{"filename": "orders.csv", "path": "/"}],
)
conn_file_id = upload["conn_file_ids"][0]
preview = client.preview_connector_file({"conn_file_id": conn_file_id})
After reviewing headers, column order, and inferred types, submit the import. An existing Table requires new_table=False, database_id, table_id, conn_file_ids, and optional existed_table column mappings:
result = sdk.import_local_file_to_table(
{
"new_table": False,
"database_id": 201,
"table_id": 301,
"conn_file_ids": [conn_file_id],
"existed_table": [],
"existed_table_opts": {"method": "append"},
}
)
existed_table_opts.method accepts append or overwrite; an empty value behaves as append. Because overwrite replaces existing data, verify the Table ID and its references first.
Row-conflict behavior is a separate setting:
Value |
Go constant |
Behavior |
|---|---|---|
|
|
Fail the import |
|
|
Skip conflicting rows |
|
|
Replace conflicting rows |
Do not treat the row-conflict policy and whole-table append / overwrite mode as interchangeable.
Create a new Table¶
Set new_table to True and provide the name, description, and column definitions under create_table. Preview output can inform those definitions, but the application should still validate them:
result = sdk.import_local_file_to_table(
{
"new_table": True,
"database_id": 201,
"conn_file_ids": [conn_file_id],
"create_table": {
"name": "orders",
"description": "Imported orders",
"tableColumn": [
{
"number": 1,
"columnName": "id",
"dataType": "int",
"isKey": True,
"col_num_in_file": 1,
}
],
},
"isColumnName": True,
"columnNameRow": 1,
"rowStart": 2,
}
)
Field spelling follows the public SDK type. Confirm supported data types from the actual preview and service contract.
Submit an advanced file import in Go¶
Go’s UploadConnectorFile accepts UploadFileRequest. It can upload file content directly or reuse staged ConnFileIDs:
resp, err := client.UploadConnectorFile(ctx, &sdk.UploadFileRequest{
VolumeID: "vol-1",
Meta: []sdk.FileMeta{
{Filename: "orders.csv", Path: "/"},
},
TableConfig: &sdk.TableConfig{
NewTable: false,
DatabaseID: 201,
TableID: 301,
ConnFileIDs: []string{"conn-file-id"},
ExistedTableOpts: sdk.ExistedTableOptions{
Method: sdk.ExistedTableOptionAppend,
},
},
})
The request requires VolumeID and either at least one directly uploaded File or a staged File in TableConfig.ConnFileIDs. The response contains TaskId and per-file results.
Read task state¶
Python uses get_task({"task_id": ...}); Go uses GetTask(ctx, &TaskInfoRequest{TaskID: ...}):
task = client.get_task({"task_id": result["task_id"]})
print(task["status"])
The SDK provides a single read, not a general waiter. A polling loop should have an overall timeout and jittered backoff, and should use the status returned by the service rather than a status enum guessed by the application. Once a terminal state is reported, read the destination Table or Volume to verify the result.
Cleanup and retry¶
Persist the
task_id, destination ID, input checksums, and request identifier for failure and duplicate diagnosis.Read task details before retrying. A network timeout alone is not sufficient reason to resubmit an overwrite import.
Remove staged files with
delete_connector_filewhen they are no longer needed.Before importing into an existing Table, use
get_tableandget_table_ref_listto verify the destination.
Export boundary¶
Neither official SDK currently exposes Export Task methods. Do not use Catalog File downloads or Table CSV downloads as a substitute for an export task: a download returns content to the current client and provides no destination Connector, schedule, rerun, or task governance. Use the AI Studio Data Export interface until a public SDK method is released.