public class TableTunnel extends Object
UploadSession 和 DownloadSession 这两个会话来负责。示例代码(将一张表的数据导入到另一张表):
public class Sample {
private static String accessID = "";
private static String accessKey = "";
private static String odpsURL = "";
private static String tunnelURL = "";
private static String project = "";
private static String table1 = "";
private static String table2 = "";
public static void main(String args[]){
Account account = new AliyunAccount(accessID, accessKey);
Odps odps = new Odps(account);
odps.setEndpoint(odpsURL);
odps.setDefaultProject(project);
TableTunnel tunnel = new TableTunnel(odps);
tunnel.setEndpoint(tunnelURL);
try {
DownloadSession downloadSession = tunnel.createDownloadSession(project, table1);
long count = downloadSession.getRecordCount();
RecordReader recordReader = downloadSession.openRecordReader(0, count);
Record record;
UploadSession uploadSession = tunnel.createUploadSession(project, table2);
RecordWriter recordWriter = uploadSession.openRecordWriter(0);
while((record = recordReader.read()) != null){
recordWriter.write(record);
}
recordReader.close();
recordWriter.close();
uploadSession.commit(new Long[]{0L});
}catch (TunnelException e){
e.printStackTrace();
}catch (IOException e1) {
e1.printStackTrace();
}
}
}
UploadSession,
DownloadSession| 限定符和类型 | 类和说明 |
|---|---|
class |
TableTunnel.DownloadSession
DownloadSession 表示从 ODPS 表中下载数据的会话,一般通过
TableTunnel来创建。 |
static class |
TableTunnel.DownloadStatus
下载会话的状态
UNKNOWN 未知 NORMAL 正常 CLOSED 关闭 EXPIRED 过期 |
class |
TableTunnel.UploadSession
UploadSession 表示向ODPS表中上传数据的会话,一般通过
TableTunnel来创建。 |
static class |
TableTunnel.UploadStatus
UploadStatus表示当前Upload的状态
UNKNOWN 未知 NORMAL 正常 CLOSING 关闭中 CLOSED 已关闭 CANCELED 已取消 EXPIRED 已过期 CRITICAL 严重错误 |
| 构造器和说明 |
|---|
TableTunnel(Odps odps)
构造此类对象
|
| 限定符和类型 | 方法和说明 |
|---|---|
TableTunnel.DownloadSession |
createDownloadSession(String projectName,
String tableName)
在非分区表上创建下载会话
|
TableTunnel.DownloadSession |
createDownloadSession(String projectName,
String tableName,
long shardId)
在shard表上创建下载会话
|
TableTunnel.DownloadSession |
createDownloadSession(String projectName,
String tableName,
PartitionSpec partitionSpec)
在分区表上创建下载会话
|
TableTunnel.DownloadSession |
createDownloadSession(String projectName,
String tableName,
PartitionSpec partitionSpec,
long shardId)
在shard表上创建下载会话
|
StreamClient |
createStreamClient(String projectName,
String tableName)
创建Stream上传Client
|
TableTunnel.UploadSession |
createUploadSession(String projectName,
String tableName)
在非分区表上创建上传会话
|
TableTunnel.UploadSession |
createUploadSession(String projectName,
String tableName,
PartitionSpec partitionSpec)
在分区表上创建上传会话
注: 分区必须为最末级分区,如表有两级分区pt,ds, 则必须全部指定值, 不支持只指定其中一个值
|
TableTunnel.DownloadSession |
getDownloadSession(String projectName,
String tableName,
long shardId,
String id)
获得在非分区表上创建的下载会话
|
TableTunnel.DownloadSession |
getDownloadSession(String projectName,
String tableName,
PartitionSpec partitionSpec,
long shardId,
String id)
获得在shard表上创建的下载会话
|
TableTunnel.DownloadSession |
getDownloadSession(String projectName,
String tableName,
PartitionSpec partitionSpec,
String id)
获得在分区表上创建的下载会话
|
TableTunnel.DownloadSession |
getDownloadSession(String projectName,
String tableName,
String id)
获得在非分区表上创建的下载会话
|
TableTunnel.UploadSession |
getUploadSession(String projectName,
String tableName,
PartitionSpec partitionSpec,
String id)
获得在分区表上创建的上传会话
|
TableTunnel.UploadSession |
getUploadSession(String projectName,
String tableName,
String id)
获得在非分区表上创建的上传会话
|
void |
setEndpoint(String endpoint)
设置TunnelServer地址
没有设置TunnelServer地址的情况下, 自动选择
|
public TableTunnel.UploadSession createUploadSession(String projectName, String tableName) throws TunnelException
projectName - Project名称tableName - 表名,非视图TableTunnel.UploadSessionTunnelExceptionpublic TableTunnel.UploadSession createUploadSession(String projectName, String tableName, PartitionSpec partitionSpec) throws TunnelException
注: 分区必须为最末级分区,如表有两级分区pt,ds, 则必须全部指定值, 不支持只指定其中一个值
projectName - Project名tableName - 表名,非视图partitionSpec - 指定分区 PartitionSpecTableTunnel.UploadSessionTunnelExceptionpublic TableTunnel.UploadSession getUploadSession(String projectName, String tableName, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图id - 上传会话的ID TableTunnel.UploadSession.getId()TableTunnel.UploadSessionTunnelExceptionpublic TableTunnel.UploadSession getUploadSession(String projectName, String tableName, PartitionSpec partitionSpec, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图partitionSpec - 上传数据表的partition描述 PartitionSpecid - 上传会话ID TableTunnel.UploadSession.getId()TableTunnel.UploadSessionTunnelExceptionpublic TableTunnel.DownloadSession createDownloadSession(String projectName, String tableName) throws TunnelException
projectName - Project名称tableName - 表名,非视图TableTunnel.DownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession createDownloadSession(String projectName, String tableName, PartitionSpec partitionSpec) throws TunnelException
projectName - Project名tableName - 表名,非视图partitionSpec - 指定分区 PartitionSpecTableTunnel.DownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession createDownloadSession(String projectName, String tableName, long shardId) throws TunnelException
projectName - Project名tableName - 表名,非视图shardId - 指定shardIdDownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession createDownloadSession(String projectName, String tableName, PartitionSpec partitionSpec, long shardId) throws TunnelException
projectName - Project名tableName - 表名,非视图partitionSpec - 指定分区 PartitionSpecshardId - 指定shardIdDownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession getDownloadSession(String projectName, String tableName, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图id - 下载会话ID TableTunnel.DownloadSession.getId()TableTunnel.DownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession getDownloadSession(String projectName, String tableName, long shardId, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图id - 下载会话ID TableTunnel.DownloadSession.getId()TableTunnel.DownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession getDownloadSession(String projectName, String tableName, PartitionSpec partitionSpec, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图partitionSpec - 指定分区 PartitionSpecid - 下载会话ID TableTunnel.DownloadSession.getId()TableTunnel.DownloadSessionTunnelExceptionpublic TableTunnel.DownloadSession getDownloadSession(String projectName, String tableName, PartitionSpec partitionSpec, long shardId, String id) throws TunnelException
projectName - Project名tableName - 表名,非视图partitionSpec - 指定分区 PartitionSpecshardId - 指定shardIdid - 下载会话ID DownloadSession.getId()DownloadSessionTunnelExceptionpublic StreamClient createStreamClient(String projectName, String tableName) throws TunnelException
projectName - Project名称tableName - table名称StreamClientTunnelExceptionpublic void setEndpoint(String endpoint)
没有设置TunnelServer地址的情况下, 自动选择
endpoint - Copyright © 2015 Alibaba Cloud Computing. All rights reserved.