All Products
Search
Document Center

MaxCompute:UNLOAD

Last Updated:Mar 26, 2026

Use UNLOAD statements to export data from a MaxCompute table to Object Storage Service (OSS) or Hologres, making it available to other compute engines such as Amazon Redshift and BigQuery.

Run UNLOAD statements on any of the following platforms:

How it works

UNLOAD reads data from a MaxCompute table (or a subquery result) and writes it to an OSS path or a Hologres table. MaxCompute automatically splits the output into multiple files and generates file names — you cannot specify custom file names.

Each UNLOAD run generates new files. Existing files at the target location are never overwritten.

Prerequisites

Before you begin, ensure that you have:

  • The SELECT permission on the MaxCompute source table. For more information, see MaxCompute permissions.

  • Write access to the target OSS bucket or Hologres table, authorized through MaxCompute.

Authorize MaxCompute to access OSS

One-click authorization provides higher security. For details, see STS authorization.

The examples in this topic use one-click authorization with the default role AliyunODPSDefaultRole.

Authorize MaxCompute to access Hologres

Create a RAM role, grant it access to MaxCompute, and add it to the Hologres instance. For details, see Create a Hologres foreign table in STS mode.

Export to OSS using a built-in StorageHandler

Use a built-in StorageHandler to export data as CSV or TSV. When you use this method, the .csv or .tsv extension is automatically added to the exported file name.

Syntax

UNLOAD FROM {<select_statement> | <table_name> [PARTITION (<pt_spec>)]}
INTO
LOCATION <external_location>
STORED BY <StorageHandler>
[WITH SERDEPROPERTIES ('<property_name>'='<property_value>', ...)];

Parameters

ParameterRequiredDescription
select_statementNoA SELECT clause that queries data from a partitioned or non-partitioned source table. For syntax details, see SELECT syntax.
table_name, pt_specNoThe table name, or the table and partition name combination. This method does not generate a query statement, so no query fee is incurred. The pt_spec format is (partition_col1=partition_col_value1, partition_col2=partition_col_value2, ...).
external_locationYesThe target OSS path in the format 'oss://<oss_endpoint>/<object>'. For more information, see Use an endpoint that supports IPv6 to access OSS.
StorageHandlerYesThe built-in storage handler. Valid values: com.aliyun.odps.CsvStorageHandler and com.aliyun.odps.TsvStorageHandler. The configuration is the same as for MaxCompute external tables. For more information, see Create an OSS external table.
property_name, property_valueNoSERDEPROPERTIES key-value pairs. Use these the same way as for MaxCompute external tables. For more information, see Create an OSS external table.

Key SERDEPROPERTIES for OSS:

PropertyDescription
'odps.properties.rolearn'='acs:ram::<uid>:role/AliyunODPSDefaultRole'The Alibaba Cloud Resource Name (ARN) of the RAM role used for Security Token Service (STS) authentication.
'odps.text.option.gzip.output.enabled'='true'Compresses the output file in GZIP format. Only GZIP is supported.

To control the number of output files, set the data size (in MB) that a single worker reads from the MaxCompute table before the export:

SET odps.stage.mapper.split.size=256;

The MaxCompute table is compressed before export. The exported data size is approximately four times the pre-export data size.

Examples

This example exports data from the sale_detail table:

+------------+-------------+-------------+------------+------------+
| shop_name  | customer_id | total_price | sale_date  | region     |
+------------+-------------+-------------+------------+------------+
| s1         | c1          | 100.1       | 2013       | china      |
| s2         | c2          | 100.2       | 2013       | china      |
| s3         | c3          | 100.3       | 2013       | china      |
| null       | c5          | NULL        | 2014       | shanghai   |
| s6         | c6          | 100.4       | 2014       | shanghai   |
| s7         | c7          | 100.5       | 2014       | shanghai   |
+------------+-------------+-------------+------------+------------+

Step 1: Log on to the OSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS console. Create the directory mc-unload/data_location/ in an OSS bucket in the oss-cn-hangzhou region. For more information, see Create buckets.Bucket

The OSS path for this bucket is:

oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location

Step 2: Log on to the MaxCompute client and run the UNLOAD statement.

Example 1: Export all data as CSV with GZIP compression

-- Control output file count: set the data size (MB) per worker.
SET odps.stage.mapper.split.size=256;
-- Export all data from sale_detail as a GZIP-compressed CSV file.
UNLOAD FROM
  (SELECT * FROM sale_detail)
INTO
  LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location'
  STORED BY 'com.aliyun.odps.CsvStorageHandler'
  WITH SERDEPROPERTIES (
    'odps.properties.rolearn'='acs:ram::<uid>:role/AliyunODPSDefaultRole',
    'odps.text.option.gzip.output.enabled'='true'
  );

The following statement is equivalent — it references the table directly, which does not generate a query statement and incurs no query fee:

SET odps.stage.mapper.split.size=256;
UNLOAD FROM sale_detail
INTO
  LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location'
  STORED BY 'com.aliyun.odps.CsvStorageHandler'
  WITH SERDEPROPERTIES (
    'odps.properties.rolearn'='acs:ram::<uid>:role/AliyunODPSDefaultRole',
    'odps.text.option.gzip.output.enabled'='true'
  );

Example 2: Export a partition as TSV with GZIP compression

SET odps.stage.mapper.split.size=256;
UNLOAD FROM sale_detail PARTITION (sale_date='2013', region='china')
INTO
  LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location'
  STORED BY 'com.aliyun.odps.TsvStorageHandler'
  WITH SERDEPROPERTIES (
    'odps.properties.rolearn'='acs:ram::139699392458****:role/AliyunODPSDefaultRole',
    'odps.text.option.gzip.output.enabled'='true'
  );

Step 3: Log on to the OSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS console to verify the exported files in the target directory.

  • Result for Example 1:导入结果

  • Result for Example 2:导入结果

Export to OSS in an open source format

Use this method to export data as ORC, Parquet, RCFILE, SEQUENCEFILE, TEXTFILE, or other open source formats.

Syntax

UNLOAD FROM {<select_statement> | <table_name> [PARTITION (<pt_spec>)]}
INTO
LOCATION <external_location>
[ROW FORMAT SERDE '<serde_class>'
  [WITH SERDEPROPERTIES ('<property_name>'='<property_value>', ...)]
]
STORED AS <file_format>
[PROPERTIES ('<tbproperty_name>'='<tbproperty_value>')];

Parameters

ParameterRequiredDescription
select_statementNoA SELECT clause that queries data from a partitioned or non-partitioned source table. For syntax details, see SELECT syntax.
table_name, pt_specNoThe table name, or the table and partition name combination. No query fee is incurred. The pt_spec format is (partition_col1=partition_col_value1, partition_col2=partition_col_value2, ...).
external_locationYesThe target OSS path in the format 'oss://<oss_endpoint>/<object>'.
serde_classNoThe SerDe class. Configuration is the same as for MaxCompute external tables. For more information, see Create an OSS external table.
property_name, property_valueNoSERDEPROPERTIES key-value pairs, used the same way as for MaxCompute external tables. For more information, see Create an OSS external table.
file_formatYesThe output file format: ORC, PARQUET, RCFILE, SEQUENCEFILE, or TEXTFILE. Configuration is the same as for MaxCompute external tables. For more information, see Create an OSS external table.
tbproperty_name, tbproperty_valueNoTable properties for compression or other settings. For example, 'mcfed.parquet.compression'='SNAPPY' or 'mcfed.parquet.compression'='LZO'.

Key PROPERTIES for open source formats:

PropertyDescription
'mcfed.parquet.compression'='SNAPPY'Compresses Parquet output with Snappy.
'mcfed.parquet.compression'='LZO'Compresses Parquet output with LZO.
If the output is compressed with Snappy or LZO, the file name extension (.snappy or .lzo) is not shown in the file name.

Examples

This example uses the same sale_detail table as the previous section.

Step 1: Log on to the OSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS console. Create the directory mc-unload/data_location/ in your OSS bucket. For more information, see Create buckets.Bucket

Step 2: Log on to the MaxCompute client and run the UNLOAD statement.

Example 1: Export all data as Parquet with Snappy compression

SET odps.stage.mapper.split.size=256;
UNLOAD FROM
  (SELECT * FROM sale_detail)
INTO
  LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location'
  ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
  WITH SERDEPROPERTIES ('odps.properties.rolearn'='acs:ram::<uid>:role/AliyunODPSDefaultRole')
  STORED AS PARQUET
  PROPERTIES ('mcfed.parquet.compression'='SNAPPY');

Example 2: Export a partition as Parquet with Snappy compression

SET odps.stage.mapper.split.size=256;
UNLOAD FROM sale_detail PARTITION (sale_date='2013', region='china')
INTO
  LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-unload/data_location'
  ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
  WITH SERDEPROPERTIES ('odps.properties.rolearn'='acs:ram::139699392458****:role/AliyunODPSDefaultRole')
  STORED AS PARQUET
  PROPERTIES ('mcfed.parquet.compression'='SNAPPY');

Step 3: Log on to the OSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS consoleOSS console to verify the exported files.

  • Result for Example 1:导入结果

  • Result for Example 2:导入结果

Export to Hologres

Use this method to export data from a MaxCompute table to a non-partitioned Hologres table via JDBC.

Syntax

UNLOAD FROM {<select_statement> | <table_name>}
INTO
LOCATION <external_location>
STORED BY 'com.aliyun.odps.jdbc.JdbcStorageHandler'
WITH SERDEPROPERTIES (
  'odps.properties.rolearn'='<ram_arn>',
  'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver',
  'odps.federation.jdbc.target.db.type'='holo'
);

Parameters

ParameterRequiredDescription
select_statementNoA SELECT clause that queries data from a non-partitioned source table. For syntax details, see SELECT syntax.
table_nameNoThe table name. No query fee is incurred.
external_locationYesThe Hologres JDBC connection URL in the format: 'jdbc:postgresql://<endpoint>:<port>/<database>?ApplicationName=MaxCompute&[currentSchema=<schema>&][useSSL={true|false}&]table=<holo_table_name>/'. For more information, see Create a Hologres external table.

Required SERDEPROPERTIES for Hologres:

PropertyDescription
'odps.properties.rolearn'='<ram_arn>'The ARN of the RAM role used for STS authentication. To get the ARN, go to the Roles page in the Resource Access Management (RAM) console, click the role name, and view the ARN in the Basic Information section.
'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver'The JDBC driver class for connecting to Hologres.
'odps.federation.jdbc.target.db.type'='holo'Specifies the target database type as Hologres.
The data types of fields in the Hologres destination table must match those in the MaxCompute source table. For the type mapping, see Data type mappings between MaxCompute and Hologres.

Example

This example exports data from the data_test table in MaxCompute to a Hologres table named mc_2_holo:

+------------+------+
| id         | name |
+------------+------+
| 3          | rgege |
| 4          | Gegegegr |
+------------+------+

Step 1: Create the Hologres table mc_2_holo in the test database. Run the following statement in HoloWeb. For more information, see Connect to HoloWeb and perform queries.

CREATE TABLE mc_2_holo (id INT, name TEXT);

Step 2: Log on to the MaxCompute client and run the UNLOAD statement:

UNLOAD FROM
  (SELECT * FROM data_test)
INTO
  LOCATION 'jdbc:postgresql://hgprecn-cn-5y**********-cn-hangzhou-internal.hologres.aliyuncs.com:80/test?ApplicationName=MaxCompute&currentSchema=public&useSSL=false&table=mc_2_holo/'
  STORED BY 'com.aliyun.odps.jdbc.JdbcStorageHandler'
  WITH SERDEPROPERTIES (
    'odps.properties.rolearn'='acs:ram::13**************:role/aliyunodpsholorole',
    'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver',
    'odps.federation.jdbc.target.db.type'='holo'
  );

Step 3: Query the exported data in Hologres to verify the result:

SELECT * FROM mc_2_holo;

Expected output:

id    name
4     Gegegegr
3     rgege

Control file naming

By default, MaxCompute generates file names automatically and does not show file name extensions (except for CSV and TSV output from built-in StorageHandlers). To add a custom prefix or display extensions, add the following properties to the PROPERTIES clause.

PropertyDescription
'odps.external.data.prefix'='<prefix>'A custom prefix for all exported file names. Maximum 10 characters.
'odps.external.data.enable.extension'='true'Displays the file name extension based on the file format and SerDe class.

File name extensions by format:

File formatSerDeExtension
SEQUENCEFILEorg.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.sequencefile
TEXTFILEorg.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.txt
RCFILEorg.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe.rcfile
ORCorg.apache.hadoop.hive.ql.io.orc.OrcSerde.orc
PARQUETorg.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe.parquet
AVROorg.apache.hadoop.hive.serde2.avro.AvroSerDe.avro
JSONorg.apache.hive.hcatalog.data.JsonSerDe.json
CSVorg.apache.hadoop.hive.serde2.OpenCSVSerde.csv

Example: Export as TEXTFILE with `mf_` prefix and `.txt` extension

SET odps.sql.hive.compatible=true;
SET odps.sql.split.hive.bridge=true;
UNLOAD FROM (SELECT col_tinyint, col_binary FROM mf_fun_datatype LIMIT 1)
INTO
  LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/mfosscostfee/demo6/'
  STORED AS textfile
  PROPERTIES (
    'odps.external.data.prefix'='mf_',
    'odps.external.data.enable.extension'='true'
  );

Example: Export as CSV with `mf_` prefix and `.csv` extension

SET odps.sql.hive.compatible=true;
SET odps.sql.split.hive.bridge=true;
UNLOAD FROM (SELECT col_tinyint, col_binary FROM mf_fun_datatype LIMIT 2)
INTO
  LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/mfosscostfee/demo6/'
  STORED BY 'com.aliyun.odps.CsvStorageHandler'
  PROPERTIES (
    'odps.external.data.prefix'='mf_',
    'odps.external.data.enable.extension'='true'
  );

Limits

  • MaxCompute automatically names all exported files. Custom file names are not supported. To add a prefix or show extensions, see Control file naming.

  • Dual-signature authentication is not supported when exporting to Hologres.

  • Exporting to a partitioned Hologres table is not supported.

  • File name extensions are not shown for open source format output by default. To enable them, set odps.external.data.enable.extension=true.

Billing

  • UNLOAD itself is free. Any subquery (SELECT clause) in the statement is charged as a standard SQL job.

  • If you specify a table name directly instead of a subquery, no query statement is generated and no query fee is incurred.

  • Storing structured data in OSS can reduce costs compared to MaxCompute storage in some scenarios. MaxCompute storage costs USD 0.018 per GB-month. The data compression ratio when data is imported into MaxCompute is approximately 5:1, and you are charged based on the compressed size. OSS Standard storage also costs USD 0.018 per GB-month. For OSS Infrequent Access (IA), Archive, and Cold Archive pricing, see Storage fees. Before migrating data for cost savings, estimate the actual compression ratio and access costs to avoid unexpected charges.

  • The MaxCompute table is compressed before export. The exported data size is approximately four times the pre-export data size.

What's next

To import data in CSV or open source formats from an external store into MaxCompute, see LOAD.