public class MaxStorageClient extends Object implements AutoCloseable
This client provides high-performance read and write operations for MaxCompute tables using the Storage API. It supports both table and volume operations with features like compression, retry handling, and connection management.
Example usage for reading from a table:
MaxStorageClient client = MaxStorageClient.builder()
.endpoint("https://service.cn-hangzhou.maxcompute.aliyun.com/api")
.credentialsProvider(credentialsProvider)
.build();
TableIdentifier tableId = TableIdentifier.of("my_project", "my_table");
try (TableReadSession session = client.createReadSessionBuilder(tableId).build()) {
List<InputSplit> splits = session.getSplits();
for (InputSplit split : splits) {
try (ArrowReader reader = session.createArrowReaderBuilder(split).build()) {
// Process data from reader
}
}
}
Example usage for writing to a table:
MaxStorageClient client = MaxStorageClient.builder()
.endpoint("https://service.cn-hangzhou.maxcompute.aliyun.com/api")
.credentialsProvider(credentialsProvider)
.build();
TableIdentifier tableId = TableIdentifier.of("my_project", "my_table");
try (TableWriteSession session = client.createWriteSessionBuilder(tableId).build()) {
TableArrowWriter writer = session.newArrowWriterBuilder().build();
// Write data using writer
writer.close();
session.commit();
}
| Modifier and Type | Class and Description |
|---|---|
static class |
MaxStorageClient.Builder
Builder class for constructing MaxStorageClient instances.
|
| Constructor and Description |
|---|
MaxStorageClient(MaxStorageClient.Builder builder)
Constructs a new MaxStorageClient with the provided builder configuration.
|
| Modifier and Type | Method and Description |
|---|---|
static MaxStorageClient.Builder |
builder()
Creates a new builder for constructing MaxStorageClient instances.
|
void |
close()
Closes the client and releases all associated resources.
|
InstanceReadSessionBuilder |
createInstanceReadSessionBuilder(InstanceIdentifier instance)
Creates a new builder for an instance read session.
|
TableReadSessionBuilder |
createTableReadSessionBuilder(TableIdentifier table)
Creates a new builder for a table read session.
|
TableWriteSessionBuilder |
createTableWriteSessionBuilder(TableIdentifier table)
Creates a new builder for a table write session.
|
BlobManager |
openBlobManager() |
ArrowReader |
previewTable(TableIdentifier table,
PartitionSpec partition,
List<String> columns,
Integer limit)
Previews data from a table with the specified filters and limit.
|
public MaxStorageClient(MaxStorageClient.Builder builder)
builder - The builder containing client configuration parameterspublic static MaxStorageClient.Builder builder()
This is the recommended way to create MaxStorageClient instances, allowing configuration of various client settings such as endpoint, credentials, retry policies, and HTTP settings.
public BlobManager openBlobManager()
public ArrowReader previewTable(TableIdentifier table, PartitionSpec partition, List<String> columns, Integer limit)
This method returns an ArrowReader that must be closed by the caller to release resources. It is recommended to use try-with-resources to ensure the reader is properly closed.
Example usage:
TableIdentifier tableId = TableIdentifier.of("my_project", "my_table");
PartitionSpec partition = new PartitionSpec("pt='20250101'");
List<String> columns = Arrays.asList("col1", "col2");
try (ArrowReader reader = client.previewTable(tableId, partition, columns, 100)) {
while (reader.loadNextBatch()) {
VectorSchemaRoot root = reader.getVectorSchemaRoot();
// Process data
}
}
table - The identifier of the table to previewpartition - The partition specification to filter data (can be null for all partitions)columns - The list of column names to read (can be null for all columns)limit - The maximum number of rows to read (can be null for no limit)MaxStorageException - if the table does not exist or access is deniedClientException - if there is a client-side errorpublic TableWriteSessionBuilder createTableWriteSessionBuilder(TableIdentifier table)
This method initializes a write session builder that can be configured with various options before creating the actual write session. The write session allows writing data to a MaxCompute table using the Arrow format.
table - The identifier of the target table for writing datapublic TableReadSessionBuilder createTableReadSessionBuilder(TableIdentifier table)
This method initializes a read session builder that can be configured with various options before creating the actual read session. The read session allows reading data from a MaxCompute table using the Arrow format.
table - The identifier of the source table for reading datapublic InstanceReadSessionBuilder createInstanceReadSessionBuilder(InstanceIdentifier instance)
This method initializes a read session builder that can be configured with various options before creating the actual read session. The read session allows reading data from a MaxCompute instance using the Arrow format.
instance - The identifier of the source instance for reading datapublic void close()
This method closes the underlying buffer allocator and storage stub, releasing any resources such as network connections, thread pools, and memory buffers. It should be called when the client is no longer needed to prevent resource leaks.
close in interface AutoCloseableCopyright © 2026 Alibaba Cloud Computing. All rights reserved.