All Products
Search
Document Center

ApsaraDB for SelectDB:Use Broker Load to import data

Last Updated:Apr 28, 2026

Broker Load is an asynchronous bulk import method that loads data from distributed storage systems — Hadoop Distributed File System (HDFS), Object Storage Service (OSS), and Amazon Simple Storage Service (Amazon S3) — directly into ApsaraDB for SelectDB. A single import job handles hundreds of GB without blocking your cluster.

How it works

  1. Submit a LOAD LABEL statement over the MySQL protocol. The job is accepted immediately and runs asynchronously.

  2. The broker connects to the remote storage system and reads the specified files.

  3. Data is loaded into the target table. If you load into multiple tables, all writes in the job are atomic.

  4. The label records the job's completion state, preventing duplicate imports if you resubmit the same request.

Performance

Data volume

Expected completion time

~100 MB

~10 seconds

~100 GB

~10 minutes

Prerequisites

Before you begin, make sure you have:

  • An ApsaraDB for SelectDB instance.

  • Network access to the source storage system (HDFS, OSS, or Amazon S3). If the remote storage system is deployed in a public network environment, your ApsaraDB for SelectDB instance must have public network access, see Resolve network issues with data sources.

  • The target table created in your SelectDB instance.

Submit a Broker Load job

Syntax

LOAD LABEL load_label
(
    data_desc1[, data_desc2, ...]
)
WITH broker_type
[broker_properties]
[load_properties];

Parameters

Parameter

Description

load_label

A unique identifier for the job, in the format [database.]label_name. If a previous job with this label is in the CANCELLED state, the label can be reused. Use the same label for the same batch of data to enforce at-most-once semantics — repeated submissions with the same label are accepted only once.

data_desc

Describes the files to import. See Data description parameters.

WITH broker_type

The broker type. Valid values: HDFS and S3. A job that uses the S3 broker is also called an OSS Load job. For OSS-specific instructions, see Import data by using OSS.

broker_properties

Connection parameters for the remote storage system, in the format ("key1" = "val1", "key2" = "val2", ...).

load_properties

Import behavior parameters. See Import properties.

Data description parameters

[MERGE|APPEND|DELETE]
DATA INFILE
(
    "file_path1"[, file_path2, ...]
)
[NEGATIVE]
INTO TABLE `table_name`
[PARTITION (p1, p2, ...)]
[COLUMNS TERMINATED BY "column_separator"]
[FORMAT AS "file_type"]
[(column_list)]
[COLUMNS FROM PATH AS (c1, c2, ...)]
[PRECEDING FILTER predicate]
[SET (column_mapping)]
[WHERE predicate]
[DELETE ON expr]
[ORDER BY source_sequence]
[PROPERTIES ("key1"="value1", ...)]

Parameter

Description

MERGE|APPEND|DELETE

The merge mode. Default: APPEND (standard append). MERGE and DELETE apply only to tables using the Unique Key model. With MERGE, use DELETE ON to specify the Delete Flag column. With DELETE, all imported rows are deleted from the table.

DATA INFILE

Paths to the files to import. Multiple paths and wildcards are supported. Each path must point to an actual file, not a directory.

NEGATIVE

Negates integer values aggregated by the SUM function. Use this to offset previously imported data that contains errors. Valid only for INTEGER columns aggregated with SUM.

PARTITION(p1, p2, ...)

Limits the import to specific partitions. Data outside the specified partitions is excluded.

COLUMNS TERMINATED BY

The column delimiter. Applies only to CSV files. Single-byte delimiters only.

FORMAT AS

The file format. Default: CSV. Valid values: CSV, PARQUET, ORC.

column_list

The column order in the source file.

COLUMNS FROM PATH AS

Extracts columns from the file path.

PRECEDING FILTER predicate

A pre-filter applied after columns are assembled from column_list and COLUMNS FROM PATH AS, before any column mapping.

SET (column_mapping)

Column transformation expressions applied during import.

WHERE predicate

Filters rows after column mapping. Only matching rows are imported.

DELETE ON expr

Required when using MERGE mode. Specifies the expression that marks rows for deletion. Valid only for Unique Key model tables.

ORDER BY source_sequence

Specifies the sequence column for maintaining data order. Valid only for Unique Key model tables.

PROPERTIES ("key1"="value1", ...)

Format-specific parameters, such as json_root, jsonpaths, and fuzzy_parse for JSON files.

Import properties

Parameter

Default

Description

timeout

14400 (4 hours)

Timeout in seconds. The timer starts when the job is submitted. If the job does not complete within this period, it fails.

max_filter_ratio

0

The maximum proportion of error rows to tolerate, from 0 to 1. The default 0 means the job fails if any row has a format error. Set this to a value greater than 0 to allow SelectDB to skip rows in incorrect formats.

exec_mem_limit

2147483648 (2 GB)

Maximum memory allocated to the job, in bytes.

strict_mode

false

When true, enables strict mode, which affects column mapping, type conversion, and filtering behavior.

timezone

Asia/Shanghai

Time zone for time zone-sensitive functions: strftime, alignment_timestamp, and from_unixtime.

load_parallelism

1

The degree of parallelism (DOP) for the import. Setting this to a value greater than 1 starts multiple execution plans concurrently, which speeds up large imports.

send_batch_parallelism

DOP for sending data batches. Capped by max_send_batch_parallelism_per_job in the backend (BE) configuration of the compute cluster.

load_to_single_tablet

false

When true, imports data into a single tablet per partition. Valid only for Duplicate Key model tables with random bucketing.

Examples

The following examples all use the same table structure. Run these statements first to create the tables and sample data files.

Create tables

CREATE TABLE test_table
(
    id      int,
    name    varchar(50),
    age     int,
    address varchar(50)
)
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(id) BUCKETS 4
PROPERTIES("replication_num" = "1");

CREATE TABLE test_table2
(
    id      int,
    name    varchar(50),
    age     int,
    address varchar(50)
)
DISTRIBUTED BY HASH(id) BUCKETS 4
PROPERTIES("replication_num" = "1");

Sample data files

file1.txt (comma-separated):

1,tomori,32,shanghai
2,anon,22,beijing
3,taki,23,shenzhen
4,rana,45,hangzhou
5,soyo,14,shanghai
6,saki,25,hangzhou
7,mutsumi,45,shanghai
8,uika,26,shanghai
9,umiri,27,shenzhen
10,nyamu,37,shanghai

file2.csv (comma-separated):

1,saki,25,hangzhou
2,mutsumi,45,shanghai
3,uika,26,shanghai
4,umiri,27,shenzhen
5,nyamu,37,shanghai

Example 1: Import a CSV file from HDFS

Imports file1.txt into test_table using comma as the column delimiter. The fs.defaultFS property is required to connect to the HDFS cluster.

LOAD LABEL example_db.label1
(
    DATA INFILE("hdfs://hdfs_host:hdfs_port/example/file1.txt")
    INTO TABLE `test_table`
    COLUMNS TERMINATED BY ","
)
WITH HDFS
(
    "fs.defaultFS" = "hdfs://hdfs_host:hdfs_port"
);

Example 2: Import multiple files into multiple tables in one job

Imports file2.csv into test_table and file1.txt into test_table2 in a single atomic job. The SET clause increments the age column by 1 using the temp_age column from the source file.

LOAD LABEL test_db.test_02
(
    DATA INFILE("hdfs://hdfs_host:hdfs_port/example/file2.csv")
    INTO TABLE `test_table`
    COLUMNS TERMINATED BY ","
    (id, name, temp_age, address)
    SET (
        age = temp_age + 1
    ),
    DATA INFILE("hdfs://hdfs_host:hdfs_port/example/file1.txt")
    INTO TABLE `test_table2`
    COLUMNS TERMINATED BY ","
)
WITH HDFS
(
    "fs.defaultFS" = "hdfs://hdfs_host:hdfs_port"
);

Example 3: Import from an HDFS cluster in high availability (HA) mode

Uses a wildcard to import all files in the /example/ directory. The \\x01 delimiter is the default Hive field separator.

LOAD LABEL test_db.test_03
(
    DATA INFILE("hdfs://hdfs_host:hdfs_port/example/*")
    INTO TABLE `test_table`
    COLUMNS TERMINATED BY "\\x01"
)
WITH HDFS
(
    "hadoop.username"                                          = "hive",
    "fs.defaultFS"                                            = "hdfs://my_ha",
    "dfs.nameservices"                                        = "my_ha",
    "dfs.ha.namenodes.my_ha"                                  = "my_namenode1, my_namenode2",
    "dfs.namenode.rpc-address.my_ha.my_namenode1"             = "nn1_host:rpc_port",
    "dfs.namenode.rpc-address.my_ha.my_namenode2"             = "nn2_host:rpc_port",
    "dfs.client.failover.proxy.provider.my_ha"                = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"
);

Example 4: Import with a row filter

Imports only rows where age < 20 from file1.txt.

LOAD LABEL test_db.test_04
(
    DATA INFILE("hdfs://host:port/example/file1.txt")
    INTO TABLE `test_table2`
    COLUMNS TERMINATED BY ","
    (id, name, age, address)
    WHERE age < 20
)
WITH HDFS
(
    "fs.defaultFS" = "hdfs://hdfs_host:hdfs_port"
);

Example 5: MERGE mode with timeout and error tolerance

Imports file1.txt in MERGE mode into test_table (which uses the Unique Key model). Rows where age < 20 are marked for deletion. The job allows up to 10% error rows and has a 1-hour timeout.

LOAD LABEL test_db.test_05
(
    MERGE DATA INFILE("hdfs://hdfs_host:hdfs_port/example/file1.txt")
    INTO TABLE `test_table`
    COLUMNS TERMINATED BY ","
    (id, name, age, address)
    DELETE ON age < 20
)
WITH HDFS
(
    "fs.defaultFS" = "hdfs://hdfs_host:hdfs_port"
)
PROPERTIES
(
    "timeout"          = "3600",
    "max_filter_ratio" = "0.1"
);

Check job status

Broker Load runs asynchronously. A successful LOAD LABEL submission confirms the job was accepted — not that data has finished loading. Use SHOW LOAD to track progress.

Syntax

SHOW LOAD
[FROM db_name]
[
    WHERE
    [LABEL [ = "your_label" | LIKE "label_matcher"]]
    [STATE = ["PENDING"|"ETL"|"LOADING"|"FINISHED"|"CANCELLED"]]
]
[ORDER BY ...]
[LIMIT limit][OFFSET offset];

Parameters

Parameter

Description

db_name

The database to query. Defaults to the current database.

LABEL

Filters by label. Supports exact match and LIKE pattern matching.

STATE

Filters by job state.

ORDER BY

Sorts the results.

LIMIT

Limits the number of results returned. Returns all results if omitted.

OFFSET

Skips the first N results. Default: 0.

Job states

State

Meaning

What to do

PENDING

Job is queued, waiting for execution.

Wait. Monitor queue depth if the job has been pending for a long time.

ETL

Data is being extracted and transformed.

Wait.

LOADING

Data is being written to the table.

Wait.

FINISHED

Import completed successfully.

No action needed.

CANCELLED

Job was cancelled or failed. The label can be reused for a new job.

Check the ErrorMsg and URL fields in the SHOW LOAD output for failure details.

Output columns

SHOW LOAD returns the following columns for each job:

Column

Description

JobId

Internal job ID assigned by SelectDB.

Label

The label you specified in LOAD LABEL.

State

Current job state. See Job states.

Progress

Import progress as a percentage.

Type

Import type, for example BROKER.

EtlInfo

ETL phase statistics, including row counts and filtered rows.

TaskInfo

Task-level details: cluster, timeout, and max_filter_ratio.

ErrorMsg

Error message if the job failed or was cancelled.

CreateTime

Time the job was created.

EtlStartTime

Time the ETL phase started.

EtlFinishTime

Time the ETL phase finished.

LoadStartTime

Time the loading phase started.

LoadFinishTime

Time the loading phase finished.

URL

URL to the error log. Open this URL to see the full list of rejected rows and their reasons when a job fails or has a non-zero max_filter_ratio.

JobDetails

JSON object with per-file statistics: scanned rows, filtered rows, and unselected rows.

When a job is in CANCELLED state, use the ErrorMsg and URL fields to diagnose the failure before resubmitting.

Examples

Query jobs by label pattern, return 10 oldest

SHOW LOAD FROM example_db WHERE LABEL LIKE "2014_01_02" LIMIT 10;

Query a specific job, sorted by start time

SHOW LOAD FROM example_db
WHERE LABEL = "load_example_db_20140102"
ORDER BY LoadStartTime DESC;

Query a job in the LOADING state

SHOW LOAD FROM example_db
WHERE LABEL = "load_example_db_20140102" AND STATE = "loading";

Paginate results: skip the first 5, return the next 10

SHOW LOAD FROM example_db ORDER BY LoadStartTime DESC LIMIT 10 OFFSET 5;

Cancel a job

Cancel a job that is in PENDING, ETL, or LOADING state using CANCEL LOAD. Data written by a cancelled job is rolled back automatically.

Syntax

CANCEL LOAD
[FROM db_name]
WHERE [LABEL = "load_label" | LABEL LIKE "label_pattern"];

Parameters

Parameter

Description

db_name

The database containing the job. Defaults to the current database.

load_label

The exact label of the job to cancel, or a pattern for LABEL LIKE.

Examples

Cancel a specific job

CANCEL LOAD
FROM example_db
WHERE LABEL = "example_db_test_load_label";

Cancel all jobs whose label starts with `example_`

CANCEL LOAD
FROM example_db
WHERE LABEL LIKE "example_";

Best practices

Keep individual jobs under 100 GB

The per-job data limit is the number of nodes multiplied by 3 GB. For large datasets, split the data into multiple jobs rather than a single large job. This reduces retry costs if a job fails and makes it easier to track progress.

Design labels for traceability

Use labels that encode metadata — for example, etl_orders_20260328_batch01. This makes it easy to identify failed jobs, rerun specific batches, and audit load history with SHOW LOAD.

Monitor the queue before submitting

SelectDB limits concurrent import jobs per cluster to between 3 and 10, with a queue limit of 100. Jobs beyond the queue limit are rejected immediately. Monitor active and queued jobs with SHOW LOAD before submitting new ones.

Queued time counts toward a job's timeout. If a job waits too long in the queue before executing, it may time out and be cancelled. Adjust the timeout property if your workload includes queue delays.

Choose max_filter_ratio based on data quality

Value

Behavior

When to use

0 (default)

The job fails if any row has a format error. No rows are skipped.

Trusted, validated source data.

0.010.1

SelectDB skips up to this proportion of malformed rows and completes the job.

Large imports where a small number of malformed rows is acceptable.

>0.1

Same as above, but a high ratio usually indicates a data quality problem upstream.

Investigate the source data before raising this threshold.

When a job fails or skips rows, open the URL from the URL field in SHOW LOAD to see exactly which rows were rejected and why.

Use load_parallelism for large imports

Setting load_parallelism to a value greater than 1 runs multiple execution plans concurrently. This accelerates imports for large files but increases memory usage. Start with 2 or 4 and adjust based on cluster capacity.

Ensure idempotency with labels

Broker Load enforces at-most-once semantics per label. If a job with a given label succeeds (FINISHED state), resubmitting the same label has no effect. If the job failed or was cancelled, the label is available for reuse. Always check SHOW LOAD before deciding whether to resubmit.

Limits

Limit

Value

Concurrent import jobs per cluster

3–10

Maximum queue length

100 (jobs beyond this limit are rejected)

Default timeout

4 hours (timer starts from job submission, including queue wait time)

Column delimiter

Single-byte delimiters only; CSV files only

MERGE and DELETE modes

Unique Key model tables only

NEGATIVE

INTEGER columns aggregated with SUM only

What's next