in odps-console-public/src/main/java/com/aliyun/openservices/odps/console/pub/DescribeTableCommand.java [193:340]
private String getBasicScreenDisplay(Table t, Partition meta) throws ODPSConsoleException {
StringWriter out = new StringWriter();
PrintWriter w = new PrintWriter(out);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
if (meta != null) { // partition meta
w.println("+------------------------------------------------------------------------------------+");
w.printf("| PartitionSize: %-67d |\n", meta.getSize());
w.println("+------------------------------------------------------------------------------------+");
w.printf("| CreateTime: %-56s |\n", df.format(meta.getCreatedTime()));
w.printf("| LastDDLTime: %-56s |\n", df.format(meta.getLastMetaModifiedTime()));
w.printf("| LastModifiedTime: %-56s |\n", df.format(meta.getLastDataModifiedTime()));
if (meta.getLastDataAccessTime() != null) {
w.printf("| LastAccessTime: %-56s |\n", df.format(meta.getLastDataAccessTime()));
}
w.println("+------------------------------------------------------------------------------------+");
} else { // table meta
w.println("+------------------------------------------------------------------------------------+");
w.printf("| Owner: %-56s |\n", t.getOwner());
w.printf("| Project: %-56s |\n", t.getProject());
if (getContext().isSchemaMode()) {
w.printf("| Schema: %-56s |\n", t.getSchemaName());
}
w.printf("| TableComment: %-68s |\n", t.getComment());
w.println("+------------------------------------------------------------------------------------+");
w.printf("| CreateTime: %-56s |\n", df.format(t.getCreatedTime()));
w.printf("| LastDDLTime: %-56s |\n", df.format(t.getLastMetaModifiedTime()));
w.printf("| LastModifiedTime: %-56s |\n", df.format(t.getLastDataModifiedTime()));
if (t.getLastDataAccessTime() != null) {
w.printf("| LastAccessTime: %-56s |\n", df.format(t.getLastDataAccessTime()));
}
// Lifecyle
if (t.getLife() != -1) {
w.printf("| Lifecycle: %-56d |\n", t.getLife());
}
// HubLifecyle
if (t.getHubLifecycle() != -1) {
w.printf("| HubLifecycle: %-56d |\n", t.getHubLifecycle());
}
w.println("+------------------------------------------------------------------------------------+");
// Label
if (!StringUtils.isNullOrEmpty(t.getMaxLabel())) {
w.printf("| TableLabel: %-56s |\n", t.getTableLabel());
w.printf("| MaxLabel: %-56s |\n", t.getMaxLabel());
w.println("+------------------------------------------------------------------------------------+");
}
if (isExtended && !StringUtils.isNullOrEmpty(t.getMaxExtendedLabel())) {
w.printf("| TableExtendedLabel: %-56s |\n",
CollectionUtils.isEmpty(t.getTableExtendedLabels()) ? " " : StringUtils
.join(t.getTableExtendedLabels().toArray(), ","));
w.printf("| MaxExtendedLabel: %-56s |\n", t.getMaxExtendedLabel());
w.println(
"+------------------------------------------------------------------------------------+");
}
if (t.isExternalTable()) {
w.println("| ExternalTable: YES |");
} else if (t.isVirtualView()) {
w.println("| VirtualView : YES |");
w.printf("| ViewText: %-72s |\n", t.getViewText());
} else if (t.isMaterializedView()) {
w.println("| MaterializedView: YES |");
w.printf("| ViewText: %-72s |\n", t.getViewText());
w.printf("| Rewrite Enabled: %-65s |\n", t.isMaterializedViewRewriteEnabled());
w.printf("| AutoRefresh Enabled: %-61s |\n", t.isAutoRefreshEnabled());
if (t.isAutoSubstituteEnabled() != null) {
w.printf("| AutoSubstitute Enabled: %-58s |\n", t.isAutoSubstituteEnabled());
}
if (t.getRefreshInterval() != null) {
w.printf("| Refresh Interval Minutes: %-56s |\n", t.getRefreshInterval());
}
if (t.getRefreshCron() != null) {
w.printf("| Refresh Cron: %-68s |\n", t.getRefreshCron());
}
} else {
w.printf("| InternalTable: YES | Size: %-50d |\n", t.getSize());
}
w.println("+------------------------------------------------------------------------------------+");
w.println("| Native Columns: |");
w.println("+------------------------------------------------------------------------------------+");
String columnFormat =
isExtended ? "| %-8s | %-6s | %-5s | %-13s | %-8s | %-12s | %-12s |\n"
: "| %-15s | %-10s | %-5s | %-43s |\n";
String columnHeader =
isExtended ? String
.format(columnFormat, "Field", "Type", "Label", "ExtendedLabel", "Nullable", "DefaultValue", "Comment")
: String.format(columnFormat, "Field", "Type", "Label", "Comment");
w.printf(columnHeader);
w.println(
"+------------------------------------------------------------------------------------+");
for (Column c : t.getSchema().getColumns()) {
String labelOutput = "";
if (c.getCategoryLabel() != null) {
labelOutput = c.getCategoryLabel();
}
if (isExtended) {
String extendedLabels = "";
if (!CollectionUtils.isEmpty(c.getExtendedlabels())) {
extendedLabels = StringUtils.join(c.getExtendedlabels().toArray(), ",");
}
String defaultValueStr = "NULL";
if (c.hasDefaultValue()) {
defaultValueStr = c.getDefaultValue();
}
w.printf(columnFormat, c.getName(),
c.getTypeInfo().getTypeName().toLowerCase(), labelOutput, extendedLabels,
c.isNullable(), defaultValueStr,
c.getComment());
} else {
w.printf(columnFormat, c.getName(),
c.getTypeInfo().getTypeName().toLowerCase(), labelOutput, c.getComment());
}
}
w.println("+------------------------------------------------------------------------------------+");
if (t.getSchema().getPartitionColumns().size() > 0) {
w.println("| Partition Columns: |");
w.println("+------------------------------------------------------------------------------------+");
for (Column c : t.getSchema().getPartitionColumns()) {
w.printf("| %-15s | %-10s | %-51s |\n", c.getName(),
c.getTypeInfo().getTypeName().toLowerCase(), c.getComment());
}
w.println("+------------------------------------------------------------------------------------+");
}
} // end else
} catch (Exception e) {
throw new ODPSConsoleException(ErrorCode.INVALID_RESPONSE + ": Invalid table schema.", e);
}
w.flush();
w.close();
return out.toString();
}