DownloadSession

更新时间:
复制 MD 格式

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:

  1. Creates a session and generates a unique DownloadId. Retrieve it by calling getId().

  2. Builds indexes for the data files. This has high overhead and can take a long time when many files exist.

  3. 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 >= 0

  • count: the number of records to read; must be > 0

Check download status (synchronous)

Call getStatus() to get the current TableTunnel.DownloadStatus.

Methods

MethodReturn typeDescription
getId()StringReturns the unique DownloadId assigned by the server when the session is created
getRecordCount()longReturns the total number of records available for download
getSchema()TableSchemaReturns the table schema
getStatus()TableTunnel.DownloadStatusReturns the current download status
openRecordReader(long start, long count)RecordReaderOpens a record reader starting at start, reading count records; start >= 0, count > 0
openRecordReader(long start, long count, boolean compress)RecordReaderSame as above, with optional compression; set compress to true to enable compression

Download status

StatusMeaning
UNKNOWNInitial value when the server creates a session
NORMALDownload object created successfully; download can proceed
CLOSEDDownload is complete
EXPIREDSession 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.