in src/main/java/com/aliyun/odps/jdbc/OdpsDatabaseMetaData.java [930:1004]
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
/** ResultSet Format:
* odpsnamespace=true
* TABLE_SCHEM TABLE_CATALOG
* ----------- -----------
* schemaName projectName
*
* odpsnamespace=false
* TABLE_SCHEM TABLE_CATALOG
* ----------- -----------
* projectName projectName
*/
OdpsResultSetMetaData meta = new OdpsResultSetMetaData(
Arrays.asList(COL_NAME_TABLE_SCHEM, COL_NAME_TABLE_CATALOG),
Arrays.asList(TypeInfoFactory.STRING, TypeInfoFactory.STRING));
List<Object[]> rows = new ArrayList<>();
// In MaxCompute, catalog == schema == project.
String schema = catalog;
// Project MAXCOMPUTE_PUBLIC_DATA includes MaxCompute public data sets. It is available in
// almost all the regions of every public MaxCompute service, but may not be available in
// private services.
try {
if (catalogMatches(catalog, PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA)
&& schemaMatches(schemaPattern, PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA)
&& conn.getOdps().projects().exists(PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA)) {
rows.add(new String[]{PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA, PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA});
}
} catch (OdpsException e) {
String errMsg = "Failed to access project: " + e.getMessage();
conn.log.debug(errMsg);
}
try {
if (!conn.isOdpsNamespaceSchema()) {
if (catalog == null) {
// The follow code block implements the actual interface DatabaseMetaData#getCatalogs. But
// since list projects is quite slow right now, this impl is commented out.
// for (Project p : conn.getOdps().projects().iterable(null)) {
// if (!PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA.equals(p.getName())
// && Utils.matchPattern(p.getName(), schemaPattern)) {
// rows.add(new String[]{p.getName(), p.getName()});
// }
// }
if (!PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA.equalsIgnoreCase(conn.getOdps().getDefaultProject())) {
rows.add(
new String[]{conn.getOdps().getDefaultProject(), conn.getOdps().getDefaultProject()});
}
} else {
if (!PRJ_NAME_MAXCOMPUTE_PUBLIC_DATA.equalsIgnoreCase(schema)
&& Utils.matchPattern(schema, schemaPattern)
&& conn.getOdps().projects().exists(schema)) {
rows.add(new String[]{schema, schema});
}
}
} else {
List<String> schemaList;
if (catalog == null) {
catalog = conn.getOdps().getDefaultProject();
}
schemaList = Utils.getSchemaList(conn.getOdps(), "show schemas in " + catalog + ";");
for (String schemaName: schemaList) {
if (schemaMatches(schemaPattern, schemaName)) {
rows.add(new String[]{schemaName, catalog});
}
}
}
} catch (OdpsException | RuntimeException e) {
throw new SQLException(e.getMessage(), e);
}
sortRows(rows, new int[]{1, 0});
return new OdpsStaticResultSet(getConnection(), meta, rows.iterator());
}