1. IDEA中新建模块
2. 编写ReadDDL类,用于连接ODPS,读取对应的表结构
package com.op.ddlutil;
import com.aliyun.odps.*;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.simpleframework.xml.Element;
import java.util.Arrays;
import java.util.List;
public class ReadDDL {
private static final String accessId = "填入accessId...";
private static final String accessKey = "填入accessKey...";
private static final String endPoint = "http://service.cn-hongkong.maxcompute.aliyun.com/api";
private static final String project = "填入工作空间名称...";
// 初始化连接odps
public static Odps initODPS(){
Account account = new AliyunAccount(accessId,accessKey);
Odps odps = new Odps(account);
odps.setEndpoint(endPoint);
odps.setDefaultProject(project);
return odps;
}
// 获取表结构
public String getTableSchema(String tablename){
// 初始化odps
Odps odps = initODPS();
// 获取表
Table table = odps.tables().get(tablename);
// 建表语句
StringBuilder mssqlDDL=new StringBuilder();
// 获取表结构
TableSchema tableSchema = table.getSchema();
// System.out.println(tableSchema.getColumn(1).getName());
// 获取表名表注释
String tableName = table.getName();
String tableComment = table.getComment();
//获取列名列注释
List<Column> columns = tableSchema.getColumns()