All Products
Search
Document Center

MaxCompute:DownloadSession

Last Updated:Nov 26, 2025

This topic describes the DownloadSession interface, which is used to download MaxCompute table data.

Definition

public class DownloadSession {
    DownloadSession(Configuration conf, String projectName, String tableName,
                    String partitionSpec) throws TunnelException
    DownloadSession(Configuration conf, String projectName, String tableName,
                    String partitionSpec, String downloadId) throws TunnelException
    public String getId()
    public long getRecordCount()
    public TableSchema getSchema()
    public TableTunnel.DownloadStatus getStatus()
    public RecordReader openRecordReader(long start, long count)
    public RecordReader openRecordReader(long start, long count, boolean compress)
}

Descriptions

  • Lifecycle: The period from the creation of a Download instance until the download is complete.

  • Create a Download instance: You can create a Download instance using the constructor method and TableTunnel.

    • Request mode: sync.

    • The server creates a session for the download and generates a unique DownloadId to identify the download. The client can obtain the DownloadId by calling the getId method.

    • The server creates indexes for data files. This operation has a high overhead and can take a long time if many files exist.

    • The server returns the total number of records. You can start multiple concurrent downloads.

  • Download data:

    • Request mode: asynchronous.

    • Call the openRecordReader method to create a RecordReader instance. The start parameter specifies the start position, and its value must be greater than or equal to 0. The count parameter specifies the number of records, and its value must be greater than 0.

  • View the download status:

    • Request mode: sync.

    • Call the getStatus method to obtain the current download status.

  • The four statuses are described as follows:

    • UNKNOWN: The initial value set when the server creates a session.

    • NORMAL: The Download object is created successfully.

    • CLOSED: The download is complete.

    • EXPIRED: The download has timed out.

Best practices

Properly control the lifecycle of a RecordReader

To achieve optimal load balancing, we recommend that you control the continuous read duration of a single RecordReader instance within a reasonable range. MaxCompute automatically assigns a suitable service node to each RecordReader instance based on the load of each service node. If a single RecordReader instance reads data for an extended period, the load balancing capability cannot be fully utilized, which may decrease read performance. We recommend that you release and recreate a RecordReader instance after a certain period, such as 5 minutes, to achieve optimal performance.