Skip to main content

Export Data Asynchronously

Use EXPORT to write a table or selected partitions from a VeloDB Cloud warehouse to object storage or HDFS in Parquet, ORC, or CSV format. Submission returns immediately. Use SHOW EXPORT to check whether the job finishes successfully.

Applicable scenarios​

Scenario TypeRecommended for EXPORTDescription
Exporting a single large tableRecommendedOnly simple filter conditions are required
Asynchronous job submissionRecommendedThe command returns immediately and does not block the client
Exporting a SELECT result setNot supportedUse OUTFILE export instead
Compressed CSV exportSupported in Core 26.1.3Use compress_type with a supported CSV writer codec

For guidance on choosing between SELECT INTO OUTFILE and EXPORT, see Export Overview.

For the full syntax of the EXPORT command, see EXPORT.

Capability overview​

Supported data sources​

EXPORT supports exporting the following types of tables and views:

  • warehouse internal tables
  • logical views
  • Tables in External Catalogs (such as Hive external tables)

Supported storage locations​

Storage TypeSpecifically Supported
Object storageAmazon S3, Tencent Cloud COS, Alibaba Cloud OSS, Huawei Cloud OBS, Google GCS
Distributed file systemHDFS

Supported file formats​

  • Parquet
  • ORC
  • CSV
  • csv_with_names
  • csv_with_names_and_types

Prerequisites​

  • Connect to a database in your warehouse with a SQL user that has SELECT permission on the source tables. To create the example table, you also need permission to create tables and insert rows.
  • Use an object-storage bucket or HDFS destination that the warehouse can reach. This applies to both SaaS and BYOC warehouses. Private HDFS networks require access to the NameNode and the advertised DataNode addresses.
  • Grant the destination credentials permission to write the exported files. Use HTTPS for object-storage endpoints. Replace <bucket>, <region>, <access-key>, and <secret-key> with your destination settings. For HDFS, replace the NameNode host, port, and username placeholders with your HDFS settings. Keep credentials out of shared SQL files and query examples.
  • Use a new output prefix for each run. Replace <run-id>, where shown, with a unique run identifier. Export consumes warehouse compute and may incur external storage and network charges. After verifying the files, remove unneeded objects with your storage tools.

Quick start​

1. Create a table and load data​

CREATE TABLE IF NOT EXISTS tbl (
`c1` int(11) NULL,
`c2` string NULL,
`c3` bigint NULL
)
DISTRIBUTED BY HASH(c1) BUCKETS 20;

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

2. Create an export job​

Export to HDFS​

Export all data from the tbl table to HDFS, using the default CSV format with , as the column separator:

EXPORT TABLE tbl
TO "hdfs://<namenode-host>:<port>/path/to/export_"
PROPERTIES
(
"column_separator" = ","
)
WITH HDFS (
"fs.defaultFS"="hdfs://<namenode-host>:<port>",
"hadoop.username" = "<hdfs-user>"
);

Export to object storage (S3)​

Export all data from the tbl table to S3 object storage, using the default CSV format with , as the column separator:

EXPORT TABLE tbl TO "s3://<bucket>/export/export_"
PROPERTIES (
"column_separator" = ","
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

3. Check the export job status​

The following output is illustrative. Use the SHOW EXPORT command to query the progress and result of an export task:

mysql> SHOW EXPORT\G
*************************** 1. row ***************************
JobId: 143265
Label: export_0aa6c944-5a09-4d0b-80e1-cb09ea223f65
State: FINISHED
Progress: 100%
TaskInfo: {"partitions":[],"parallelism":5,"data_consistency":"partition","format":"csv","broker":"S3","column_separator":"\t","line_delimiter":"\n","max_file_size":"2048MB","delete_existing_files":"","with_bom":"false","db":"tpch1","tbl":"lineitem"}
Path: s3://<bucket>/export/export_
CreateTime: 2024-06-11 18:01:18
StartTime: 2024-06-11 18:01:18
FinishTime: 2024-06-11 18:01:31
Timeout: 7200
ErrorMsg: NULL
OutfileInfo: [
[
{
"fileNumber": "1",
"totalRows": "6001215",
"fileSize": "747503989",
"url": "s3://<bucket>/export/export_6555cd33e7447c1-baa9568b5c4eb0ac_*"
}
]
]
1 row in set (0.00 sec)

For the meaning of each column in the result, see SHOW EXPORT.

4. Cancel an export job (optional)​

Replace <database-name> with the job's database and <export-label> with its label from SHOW EXPORT. Before the job reaches a final state, cancel it with CANCEL EXPORT command:

CANCEL EXPORT FROM <database-name> WHERE LABEL = '<export-label>';

Advanced examples​

Export to a high-availability HDFS cluster​

If HDFS has high availability (HA) enabled, you must provide additional HA-related parameters:

EXPORT TABLE tbl
TO "hdfs://hacluster/path/to/export_"
PROPERTIES
(
"column_separator" = ","
)
WITH HDFS (
"fs.defaultFS" = "hdfs://hacluster",
"hadoop.username" = "<hdfs-user>",
"dfs.nameservices" = "hacluster",
"dfs.ha.namenodes.hacluster" = "nn1,nn2",
"dfs.namenode.rpc-address.hacluster.nn1" = "<namenode-1-host>:<port>",
"dfs.namenode.rpc-address.hacluster.nn2" = "<namenode-2-host>:<port>",
"dfs.client.failover.proxy.provider.hacluster" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"
);

Export to an HDFS cluster with HA and Kerberos authentication​

Before exporting to Kerberos-authenticated HDFS, ask VeloDB Cloud support to confirm that your deployment can reach the service and that its principal and keytab are provisioned for the warehouse. The keytab path below refers to a service-side file, not a file on your client.

If the HDFS cluster also uses HA, include the nameservice properties:

EXPORT TABLE tbl
TO "hdfs://hacluster/path/to/export_"
PROPERTIES
(
"column_separator" = ","
)
WITH HDFS (
"fs.defaultFS"="hdfs://hacluster/",
"hadoop.username" = "<hdfs-user>",
"dfs.nameservices"="hacluster",
"dfs.ha.namenodes.hacluster"="n1,n2",
"dfs.namenode.rpc-address.hacluster.n1"="<namenode-1-host>:8020",
"dfs.namenode.rpc-address.hacluster.n2"="<namenode-2-host>: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"="<service-principal>",
"hadoop.kerberos.keytab"="<provisioned-keytab-path>"
);

Export specified partitions​

To export only the p1 and p2 partitions of an existing internal table test, which has columns k1 and k2:

EXPORT TABLE test
PARTITION (p1,p2)
TO "s3://<bucket>/export/export_"
PROPERTIES (
"columns" = "k1,k2"
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

Export with predicate filtering​

Use a WHERE clause to filter data and export only the rows that match the condition. For example, export only rows where k1 < 50:

EXPORT TABLE test
WHERE k1 < 50
TO "s3://<bucket>/export/export_"
PROPERTIES (
"columns" = "k1,k2",
"column_separator"=","
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

Export data from an external catalog​

EXPORT can export tables in an external catalog, such as Hive. Ensure the warehouse can access both the catalog and its underlying files. Views and external tables use one OUTFILE statement per job rather than internal-table task splitting:

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

-- Export the Hive table
EXPORT TABLE hive_catalog.sf1.lineitem TO "s3://<bucket>/export/export_"
PROPERTIES(
"format" = "csv",
"max_file_size" = "1024MB"
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

Clear the target directory before export​

The delete_existing_files option requires the managed enable_delete_existing_files setting. Its source default is false. Before using this example, ask VeloDB Cloud support to confirm whether it is enabled for your warehouse. Use a fresh output prefix when it is disabled.

Warning:

This option deletes all files and subdirectories under the parent export directory, including files from other jobs. Use only a dedicated, disposable prefix and confirm its contents before running the export.

If the setting is enabled, use the following example:

EXPORT TABLE test TO "s3://<bucket>/export/export_"
PROPERTIES (
"format" = "parquet",
"max_file_size" = "512MB",
"delete_existing_files" = "true"
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

Control the size of a single export file​

Use max_file_size to control the size of a single export file. Files exceeding the configured value are split automatically:

EXPORT TABLE test TO "s3://<bucket>/export/export_"
PROPERTIES (
"format" = "parquet",
"max_file_size" = "512MB"
) WITH s3 (
"s3.endpoint" = "https://s3.<region>.amazonaws.com",
"s3.region" = "<region>",
"s3.secret_key" = "<secret-key>",
"s3.access_key" = "<access-key>"
);

For Core 26.1.3, max_file_size defaults to 1GB (1 GiB) and has a minimum of 5MB (5 MiB). The validator does not impose the historical 2 GB upper limit. The property is a rollover threshold, not an exact size guarantee. Buffered blocks and format row groups can cause files to exceed it, and parallel writers can each produce files. Destination storage limits still apply.

Notes and best practices​

ConcernRecommendations and Notes
Per-job data volumeFor large tables, export partitions in batches to limit retry work and leftover files. Choose batch sizes based on your workload and observed export time.
System resource impactExport jobs scan data and consume IO resources, which may affect query latency
Failed file managementWhen a job fails, the files already generated are not deleted automatically and must be cleaned up manually
Export timeoutVery large data volumes may trigger timeouts. You can extend the timeout with the timeout parameter in the Export command and retry
FE restart or master switchAn unfinished job can be cancelled during frontend restart or leader failover. Check SHOW EXPORT and resubmit to a fresh prefix if necessary.
Partition count limitThe source default for maximum_number_of_export_partitions is 2,000. Ask VeloDB Cloud support to confirm your warehouse setting. Export partitions in smaller batches if the job exceeds it.
Data integrity checkAfter the export completes, verify the row count and correctness of the data to ensure data quality

Appendix​

How export works​

EXPORT tasks are executed under the hood based on the SELECT INTO OUTFILE SQL statement. The overall flow is:

  1. The user submits an EXPORT task.
  2. Based on the table to be exported, the query engine constructs one or more SELECT INTO OUTFILE execution plans.
  3. The statements are submitted to the export task scheduler.
  4. The scheduler executes the tasks and records their output file information.

Server-local files​

Warehouse users do not have access to the service's local filesystem. The Apache Doris file:/// debugging workflow and enable_outfile_to_local configuration are not Cloud download procedures. Export to object storage and download the files with your storage provider's tools instead.

Common errors​

SymptomWhat to check
Access denied or destination write failureCheck SQL SELECT permissions, bucket policy, credentials, endpoint, and region.
HDFS connection or Kerberos failureCheck NameNode and DataNode reachability. Ask support to confirm service-side authentication setup.
Deleting existing files is not allowedUse a new prefix, or ask support to confirm the managed setting.
Job is CANCELLEDRead ErrorMsg in SHOW EXPORT, correct the cause, and retry with a fresh prefix. Remove partial output only after identifying the failed run's objects.

See also​