in src/main/java/com/aliyun/odps/jdbc/OdpsDatabaseMetaData.java [781:878]
public ResultSet getTables(
String catalog,
String schemaPattern,
String tableNamePattern,
String[] types) throws SQLException {
long begin = System.currentTimeMillis();
List<Object[]> rows = new ArrayList<>();
try {
if (!conn.getTables().isEmpty()) {
for (Entry<String, Map<String, List<String>>> entry: conn.getTables().entrySet()) {
String projectName = entry.getKey();
if (!catalogMatches(catalog, projectName)) {
continue;
}
for (Entry<String, List<String>> tableEntry: entry.getValue().entrySet()) {
LinkedList<String> tables = new LinkedList<>();
String schemaName = tableEntry.getKey();
if (!schemaMatches(schemaPattern, schemaName)) {
continue;
}
for (String tableName : tableEntry.getValue()) {
if (Utils.matchPattern(tableName, tableNamePattern)
&& conn.getOdps().tables().exists(projectName, tableName)) {
tables.add(tableName);
}
}
if (tables.size() > 0) {
convertTableNamesToRows(types, rows, projectName, schemaName, tables);
}
}
}
} else {
ResultSet schemas = getSchemas(catalog, schemaPattern);
List<Table> tables = new LinkedList<>();
// Iterate through all the available catalog & schemas
while (schemas.next()) {
if (catalogMatches(catalog, schemas.getString(COL_NAME_TABLE_CATALOG))
&& schemaMatches(schemaPattern, schemas.getString(COL_NAME_TABLE_SCHEM))) {
// Enable the argument 'extended' so that the returned table objects contains all the
// information needed by JDBC, like comment and type.
Iterator<Table> iter = conn.getOdps().tables().iterator(
schemas.getString(COL_NAME_TABLE_CATALOG), schemas.getString(COL_NAME_TABLE_SCHEM),
null, true);
while (iter.hasNext()) {
Table t = iter.next();
String tableName = t.getName();
if (!Utils.matchPattern(tableName, tableNamePattern)) {
continue;
}
tables.add(t);
if (tables.size() == 100) {
convertTablesToRows(types, rows, tables);
}
}
}
}
if (tables.size() > 0) {
convertTablesToRows(types, rows, tables);
}
schemas.close();
}
} catch (Exception e) {
throw new SQLException(e.getMessage(), e);
}
long end = System.currentTimeMillis();
log.info("It took me " + (end - begin) + " ms to get " + rows.size() + " Tables");
OdpsResultSetMetaData meta =
new OdpsResultSetMetaData(
Arrays.asList(
COL_NAME_TABLE_CAT,
COL_NAME_TABLE_SCHEM,
COL_NAME_TABLE_NAME,
COL_NAME_TABLE_TYPE,
COL_NAME_REMARKS,
COL_NAME_TYPE_CAT,
COL_NAME_TYPE_SCHEM,
COL_NAME_TYPE_NAME,
COL_NAME_SELF_REFERENCING_COL_NAME,
COL_NAME_REF_GENERATION),
Arrays.asList(
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING,
TypeInfoFactory.STRING));
sortRows(rows, new int[]{3, 0, 1, 2});
return new OdpsStaticResultSet(getConnection(), meta, rows.iterator());
}