DownloadSession is a Java class in the MaxCompute Tunnel SDK for downloading table data in bulk.
Class 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)
}How it works
The DownloadSession lifecycle spans from session creation to download completion.
Create a session (synchronous)
Call a constructor or use TableTunnel to create a DownloadSession. The server:
Creates a session and generates a unique
DownloadId. Retrieve it by callinggetId().Builds indexes for the data files. This has high overhead and can take a long time when many files exist.
Returns the total record count. Multiple concurrent downloads can start from this point.
Download data (asynchronous)
Call openRecordReader to create a RecordReader instance and stream records. Constraints:
start: the start position (zero-based); must be >= 0count: the number of records to read; must be > 0
Check download status (synchronous)
Call getStatus() to get the current TableTunnel.DownloadStatus.
Methods
| Method | Return type | Description |
|---|---|---|
getId() | String | Returns the unique DownloadId assigned by the server when the session is created |
getRecordCount() | long | Returns the total number of records available for download |
getSchema() | TableSchema | Returns the table schema |
getStatus() | TableTunnel.DownloadStatus | Returns the current download status |
openRecordReader(long start, long count) | RecordReader | Opens a record reader starting at start, reading count records; start >= 0, count > 0 |
openRecordReader(long start, long count, boolean compress) | RecordReader | Same as above, with optional compression; set compress to true to enable compression |
Download status
| Status | Meaning |
|---|---|
UNKNOWN | Initial value when the server creates a session |
NORMAL | Download object created successfully; download can proceed |
CLOSED | Download is complete |
EXPIRED | Session timed out before the download completed |
Best practices
Control RecordReader read duration
MaxCompute assigns each RecordReader instance to a service node based on current load. If a single RecordReader reads continuously for too long, the load balancer cannot redistribute work across nodes, which reduces read throughput.
Release and recreate a RecordReader instance at regular intervals—for example, every 5 minutes.