in odps-console-public/src/main/java/com/aliyun/openservices/odps/console/pub/ExportMetaCommand.java [65:126]
public void run() throws OdpsException, ODPSConsoleException {
if (getContext().isSchemaMode()) {
throw new ODPSConsoleException("ExportMetaCommand not support schema mode");
}
String project = getCurrentProject();
Odps odps = getCurrentOdps();
// 调用sdk得到相应的内容
if (SHOW_PARTITIONS.equals(commandMark)) {
Table table = odps.tables().get(project, tableName);
table.reload();
Iterator<Partition> partitionList = table.getPartitionIterator();
StringBuilder builder = new StringBuilder();
builder.append("[");
for (; partitionList.hasNext();) {
Partition partition = partitionList.next();
String partition_spec = partition.getPartitionSpec().toString();
builder.append(partition_spec.replace('\'', '"'));
if (partitionList.hasNext()) {
builder.append(",\n");
}
}
builder.append("]");
System.out.println(builder.toString());
} else if (SHOW_TABLES.equals(commandMark)) {
Iterator<Table> tableList = odps.tables().iterator(project);
StringBuilder builder = new StringBuilder();
builder.append("[");
for (; tableList.hasNext();) {
Table info = tableList.next();
builder.append("\"" + info.getOwner() + ":" + info.getName() + "\"");
if (tableList.hasNext()) {
builder.append(",\n");
}
}
builder.append("]");
System.out.println(builder.toString());
} else if (DESC_TABLES.equals(commandMark)) {
Coordinate coordinate = Coordinate.getCoordinateABC(tableName);
coordinate.interpretByCtx(getContext());
String projectName = coordinate.getProjectName();
if (projectName == null) {
projectName = project;
}
String realTableName = coordinate.getObjectName();
Table table = odps.tables().get(projectName, realTableName);
table.reload();
System.out.println(table.getJsonSchema());
}
}