EXPORT

Updated at:
Copy as MD

EXPORT is the asynchronous data-export command in ApsaraDB for SelectDB. After submission it returns immediately and the engine writes whole tables, selected partitions, or external-table data to OSS or HDFS in the background. This topic walks through the supported scope, common examples, and operational guidance.

Scenarios

EXPORT is intended for these two needs:

  • Off-loading a whole table or specific partitions to object storage or HDFS, where the filter logic is simple and no heavy computation is required.

  • Workflows that prefer asynchronous queueing: the export runs in the background while clients only need to poll for status, without keeping a long-lived connection.

Limitations

  • Output files in text formats cannot be compressed.

  • Arbitrary SELECT result sets cannot be used as the source. Use SELECT INTO OUTFILE if you need to materialize an arbitrary query.

  • A single job can cover at most 2,000 partitions. To raise this cap you must adjust the FE parameter maximum_number_of_export_partitions; open a support ticket to request the change.

  • delete_existing_files is disabled by default. To turn it on, open a support ticket.

EXPORT vs. SELECT INTO OUTFILE / MySQL Dump

Dimension

SELECT INTO OUTFILE

EXPORT

MySQL Dump

Execution model

Synchronous, blocking

Asynchronous queue; returns immediately and is tracked with SHOW EXPORT

Synchronous, blocking

Source

Any SELECT result set

A specific table, partition, or external table

A specific database or table

Specify partitions

Yes (expressed inside the SELECT)

Yes (PARTITION clause)

No

Specify tablets

Yes

No

No

Concurrency

Depends on whether the SQL has single-node operators such as ORDER BY

Reaches tablet-level parallelism

Single-threaded

Output formats

Parquet, ORC, CSV

Parquet, ORC, CSV (including the csv_with_names variants)

MySQL Dump proprietary format

External tables

Yes

Yes, via External Catalog

No

Views

Yes

Yes (logical views)

Yes

Destinations

Object storage, HDFS

Object storage, HDFS

Local filesystem

Export reference

Supported source objects

  • SelectDB internal tables (any of DUPLICATE, UNIQUE, AGGREGATE data models).

  • SelectDB logical views.

  • External tables registered in an External Catalog (for example, Hive Metastore Catalog).

Supported destinations

  • Object storage: Alibaba Cloud OSS, Amazon S3, Tencent Cloud COS, Huawei Cloud OBS, Google GCS. All declared with WITH S3 and s3.* properties.

  • HDFS, including HA-enabled and Kerberos-authenticated clusters. Declared with WITH HDFS.

Supported file formats

  • Parquet

  • ORC

  • csv (default)

  • csv_with_names (header row carries column names)

  • csv_with_names_and_types (header row carries names; second row carries column types)

Quick start

Create a table and load data

CREATE TABLE IF NOT EXISTS demo.tbl (
    `c1` INT NULL,
    `c2` STRING NULL,
    `c3` BIGINT NULL
)
DISTRIBUTED BY HASH(c1) BUCKETS 4;

INSERT INTO demo.tbl VALUES
    (1, 'doris', 18),
    (2, 'nereids', 20),
    (3, 'pipeline', 99999),
    (4, 'Apache', 122123455),
    (5, NULL, NULL);

Export to Alibaba Cloud OSS

Write the entire demo.tbl to an OSS bucket in default csv format:

EXPORT TABLE demo.tbl TO "oss://<your_bucket>/export/tbl_"
PROPERTIES (
    "line_delimiter" = ","
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);
  • Path scheme: prefer oss:// for Alibaba Cloud OSS; s3:// is also accepted.

  • Credentials clause: regardless of the path scheme, use WITH S3 with the property keys s3.endpoint, s3.region, s3.access_key, and s3.secret_key. SelectDB v4 does not yet expose a WITH OSS keyword.

  • Endpoint: when the SelectDB instance and OSS bucket are in the same region, use the internal endpoint (for example, oss-cn-hangzhou-internal.aliyuncs.com) to skip public-network charges and improve throughput.

Export to HDFS

Write demo.tbl to HDFS with a custom column delimiter. The host:port in fs.defaultFS and the target path must point to a reachable NameNode (for example, the FQDN of an EMR cluster master node in the same VPC):

EXPORT TABLE demo.tbl TO "hdfs://<namenode_host>:9000/path/to/tbl_"
PROPERTIES (
    "format" = "csv",
    "column_separator" = ","
)
WITH HDFS (
    "fs.defaultFS" = "hdfs://<namenode_host>:9000",
    "hadoop.username" = "hadoop"
);
  • The SelectDB instance and the HDFS cluster must share the same VPC. With Alibaba Cloud EMR, get the NameNode FQDN from the EMR cluster's Access Links and Ports page.

  • hadoop.username must have write permission on the target HDFS path; common values are hadoop or hdfs.

  • After the export finishes, validate the result by reading it back with SELECT * FROM HDFS("uri"="hdfs://<namenode_host>:9000/path/to/tbl_*", ...).

Inspect export jobs

EXPORT returns immediately, so subsequent state must be tracked with SHOW EXPORT:

SHOW EXPORT FROM demo ORDER BY CreateTime DESC LIMIT 10;

Important columns:

  • State: jobs progress through PENDING (queued) → EXPORTING (in flight) → FINISHED (done) or CANCELLED (manually cancelled or failed).

  • Progress: percentage progress.

  • Path: the target prefix you submitted.

  • OutfileInfo: populated after FINISHED, listing each output file's row count, byte size, and final URL.

  • ErrorMsg: error detail when the job fails; useful for debugging permissions, paths, and network issues.

Cancel a job

Jobs in PENDING or EXPORTING state can be revoked. The common pattern is to match by Label:

CANCEL EXPORT FROM demo WHERE LABEL like "%export_%";

Examples

Export to an HA-enabled HDFS cluster

In HA mode, declare the nameservices and each NameNode's RPC address inside WITH HDFS. The value of dfs.nameservices must match the logical name in fs.defaultFS; otherwise the parser raises Missing property: dfs.namenode.rpc-address.* (expected format: host:port):

EXPORT TABLE demo.tbl TO "hdfs://my-ns/path/to/tbl_"
PROPERTIES (
    "line_delimiter" = ","
)
WITH HDFS (
    "fs.defaultFS" = "hdfs://my-ns",
    "hadoop.username" = "hadoop",
    "dfs.nameservices" = "my-ns",
    "dfs.ha.namenodes.my-ns" = "nn1,nn2",
    "dfs.namenode.rpc-address.my-ns.nn1" = "nn1-host:8020",
    "dfs.namenode.rpc-address.my-ns.nn2" = "nn2-host:8020",
    "dfs.client.failover.proxy.provider.my-ns" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"
);

Export to an HA + Kerberos HDFS cluster

EXPORT TABLE demo.tbl TO "hdfs://hacluster/path/to/tbl_"
PROPERTIES (
    "line_delimiter" = ","
)
WITH HDFS (
    "fs.defaultFS" = "hdfs://hacluster/",
    "hadoop.username" = "hadoop",
    "dfs.nameservices" = "hacluster",
    "dfs.ha.namenodes.hacluster" = "n1,n2",
    "dfs.namenode.rpc-address.hacluster.n1" = "192.168.0.1:8020",
    "dfs.namenode.rpc-address.hacluster.n2" = "192.168.0.2:8020",
    "dfs.client.failover.proxy.provider.hacluster" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider",
    "dfs.namenode.kerberos.principal" = "hadoop/_HOST@REALM.COM",
    "hadoop.security.authentication" = "kerberos",
    "hadoop.kerberos.principal" = "doris_test@REALM.COM",
    "hadoop.kerberos.keytab" = "/path/to/doris_test.keytab"
);

Export selected partitions

Export only partitions p1 and p2 of the test table, and use columns to limit the output columns:

EXPORT TABLE demo.test
PARTITION (p1, p2)
TO "oss://<your_bucket>/export/test_"
PROPERTIES (
    "columns" = "k1,k2"
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);

Filter data during export

Export only rows that satisfy k1 < 50 with a custom column delimiter:

EXPORT TABLE demo.test
WHERE k1 < 50
TO "oss://<your_bucket>/export/test_"
PROPERTIES (
    "columns" = "k1,k2",
    "column_separator" = ","
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);

Export an external table

Register a Hive Catalog first, then submit the export with the three-part name catalog.db.table:

-- 1. Create a Hive Catalog
CREATE CATALOG hive_catalog PROPERTIES (
    'type' = 'hms',
    'hive.metastore.uris' = 'thrift://hms_host:9083'
);

-- 2. Export a Hive table from the Catalog
EXPORT TABLE hive_catalog.sf1.lineitem TO "oss://<your_bucket>/export/lineitem_"
PROPERTIES (
    "format" = "csv",
    "max_file_size" = "1024MB"
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);

Set the export file size

Use max_file_size to cap each output file. Files exceeding the cap are split automatically:

EXPORT TABLE demo.test TO "oss://<your_bucket>/export/test_"
PROPERTIES (
    "format" = "parquet",
    "max_file_size" = "512MB"
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);

max_file_size accepts values from 5 MB to 2 GB. Downstream processors such as Spark or Flink usually struggle with very large files, so 256 MB to 1 GB is a safer choice.

Clear the export directory before writing

Setting delete_existing_files to true tells the engine to delete every file and subdirectory under the target prefix before writing new data:

EXPORT TABLE demo.test TO "oss://<your_bucket>/export/test_"
PROPERTIES (
    "format" = "parquet",
    "max_file_size" = "512MB",
    "delete_existing_files" = "true"
)
WITH S3 (
    "s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com",
    "s3.region" = "oss-cn-hangzhou",
    "s3.access_key" = "<your_access_key_id>",
    "s3.secret_key" = "<your_access_key_secret>"
);
Warning

This option physically removes data on the external storage. ApsaraDB for SelectDB disables it by default; running it without enabling first raises Deleting existing files is not allowed. To enable this feature, you need to add `enable_delete_existing_files=true` in fe.conf. To enable it, open a support ticket and confirm you accept the data-loss risk.

Operational notes

  • Job size

    Keep each EXPORT job within tens of GB. Bigger jobs leave more orphan files behind on retry, and the scan itself adds IO load that can squeeze online queries. For very large tables, split the work across partitions.

  • Intermediate files on failure

    When EXPORT fails, intermediate files already written to the target are not cleaned up. Remove them on the storage side to avoid confusion on the next run.

  • Timeout

    Each job has a timeout window. Very large datasets may hit it and be marked as failed; raise the timeout value inside PROPERTIES and resubmit.

  • FE restarts and master failover

    A running EXPORT job that hits an FE restart or master failover is marked as failed and must be resubmitted.

  • Post-export validation

    After the job completes, compare the total row count of the output files against the source table to confirm there were no partial writes or missing files.