in src/main/java/software/amazon/documentdb/jdbc/DocumentDbDatabaseMetaData.java [479:532]
public ResultSet getPrimaryKeys(final String catalog, final String schema,
final String table) throws SQLException {
// 1. TABLE_CAT String => table catalog (may be null)
// 2. TABLE_SCHEM String => table schema (may be null)
// 3. TABLE_NAME String => table name
// 4. COLUMN_NAME String => column name
// 5. KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
// 6. PK_NAME String => primary key name (may be null)
final List<List<Object>> metaData = new ArrayList<>();
if (schema == null || properties.getDatabase().matches(convertPatternToRegex(schema))) {
for (String tableName : databaseMetadata.getTableSchemaMap().keySet()) {
if (table == null ||
tableName.matches(convertPatternToRegex(table))) {
final DocumentDbSchemaTable metadataTable = databaseMetadata
.getTableSchemaMap().get(tableName);
if (metadataTable == null) {
// This will occur if the table schema is deleted after retrieving the
// database schema.
throw SqlError.createSQLException(
LOGGER,
SqlState.DATA_EXCEPTION,
SqlError.INCONSISTENT_SCHEMA,
tableName);
}
for (DocumentDbSchemaColumn column : metadataTable.getColumnMap().values()) {
// 1. TABLE_CAT String => table catalog (may be null)
// 2. TABLE_SCHEM String => table schema (may be null)
// 3. TABLE_NAME String => table name
// 4. COLUMN_NAME String => column name
// 5. KEY_SEQ short => sequence number within primary key
// (a value of 1 represents the first column of the primary key, a
// value of 2 would represent the second column within the primary key).
// 6. PK_NAME String => primary key name (may be null)
if (column.isPrimaryKey()) {
final List<Object> row = new ArrayList<>(Arrays.asList(
null, // TABLE_CAT
properties.getDatabase(), // TABLE_SCHEM
metadataTable.getSqlName(), // TABLE_NAME
column.getSqlName(), // COLUMN_NAME
column.getPrimaryKeyIndex(metadataTable).orElse(0), // KEY_SEQ
null // PK_NAME
));
metaData.add(row);
}
}
}
}
}
return new DocumentDbListResultSet(
null,
buildPrimaryKeysColumnMetaData(properties.getDatabase()),
metaData);
}