Skip to content

Commit 141df72

Browse files
authored
Hide system tables from listTables result (#141)
2 parents 9ef574f + 19fe962 commit 141df72

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

jdbc/src/main/java/tech/ydb/jdbc/impl/YdbDatabaseMetaDataImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
716716
FixedResultSetFactory.ResultSetBuilder rs = MetaDataTables.TABLES.createResultSet();
717717
listTables(tableNamePattern).stream()
718718
.map(TableRecord::new)
719+
.filter(tr -> !tr.isHidden)
719720
.filter(tr -> (matchTables && !tr.isSystem) || (matchSystemTables && tr.isSystem))
720721
.sorted()
721722
.forEach(tr -> {
@@ -730,21 +731,28 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
730731

731732
private class TableRecord implements Comparable<TableRecord> {
732733
private final boolean isSystem;
734+
private final boolean isHidden;
733735
private final String name;
734736

735737
TableRecord(String name) {
736738
this.name = name;
739+
// https://github.com/ydb-platform/ydb/blob/main/ydb/core/tx/schemeshard/schemeshard_system_names.cpp#L16
737740
this.isSystem = name.startsWith(".sys/")
738741
|| name.startsWith(".sys_health/")
739-
|| name.startsWith(".sys_health_dev/")
740-
|| name.startsWith(".metadata/");
742+
|| name.startsWith(".sys_health_dev/");
743+
this.isHidden = name.startsWith(".metadata/")
744+
|| name.startsWith(".tmp/")
745+
|| name.startsWith(".backups/");
741746
}
742747

743748
@Override
744749
public int compareTo(TableRecord o) {
745750
if (isSystem != o.isSystem) {
746751
return isSystem ? 1 : -1;
747752
}
753+
if (isHidden != o.isHidden) {
754+
return isHidden ? 1 : -1;
755+
}
748756
return name.compareTo(o.name);
749757
}
750758
}
@@ -1385,7 +1393,8 @@ private TableDescription describeTable(String table) throws SQLException {
13851393
.describeTable(databaseWithSuffix + table, settings)
13861394
.thenApply(result -> {
13871395
// ignore scheme errors like path not found
1388-
if (result.getStatus().getCode() == StatusCode.SCHEME_ERROR) {
1396+
StatusCode code = result.getStatus().getCode();
1397+
if (code == StatusCode.SCHEME_ERROR || code == StatusCode.UNAUTHORIZED) {
13891398
LOGGER.log(Level.WARNING, "Cannot describe table {0} -> {1}",
13901399
new Object[]{table, result.getStatus()}
13911400
);

0 commit comments

Comments
 (0)