Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "ANCESTOR TABLE" table type(#3194) #3215

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1505,6 +1505,10 @@ public ResultSet getTables(@Nullable String catalog, @Nullable String schemaPatt
ht.put("SCHEMAS", "c.relkind = 'p' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'");
ht.put("NOSCHEMAS", "c.relkind = 'p' AND c.relname !~ '^pg_'");
ht = new HashMap<>();
tableTypeClauses.put("ANCESTOR TABLE", ht);
ht.put("SCHEMAS", "c.relkind in ('p', 'r') AND c.relispartition = 'f' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'");
ht.put("NOSCHEMAS", "c.relkind n ('p', 'r') AND c.relispartition = 'f' AND c.relname !~ '^pg_'");
ht = new HashMap<>();
tableTypeClauses.put("VIEW", ht);
ht.put("SCHEMAS",
"c.relkind = 'v' AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema'");
Expand Down
Expand Up @@ -945,7 +945,7 @@ void tableTypes(BinaryMode binaryMode) throws SQLException {
final List<String> expectedTableTypes = new ArrayList<>(Arrays.asList("FOREIGN TABLE", "INDEX", "PARTITIONED INDEX",
"MATERIALIZED VIEW", "PARTITIONED TABLE", "SEQUENCE", "SYSTEM INDEX", "SYSTEM TABLE", "SYSTEM TOAST INDEX",
"SYSTEM TOAST TABLE", "SYSTEM VIEW", "TABLE", "TEMPORARY INDEX", "TEMPORARY SEQUENCE", "TEMPORARY TABLE",
"TEMPORARY VIEW", "TYPE", "VIEW"));
"TEMPORARY VIEW", "TYPE", "VIEW", "ANCESTOR TABLE"));
final List<String> foundTableTypes = new ArrayList<>();

// Test that no exceptions are thrown
Expand Down Expand Up @@ -1568,6 +1568,33 @@ void partitionedTables(BinaryMode binaryMode) throws SQLException {
}
}

@MethodSource("data")
@ParameterizedTest(name = "binary = {0}")
void ancestorTables(BinaryMode binaryMode) throws SQLException {
initDatabaseMetaDataTest(binaryMode);
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v11)) {
Statement stmt = null;
try {
stmt = con.createStatement();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Us try with resources, please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I need to delete the test table in the finally code block, is it necessary to use try-with-resource here?

stmt.execute("CREATE TABLE ancestor (logdate date not null, peaktemp int) PARTITION BY RANGE (logdate);");
stmt.execute("CREATE TABLE ancestor_p202404 PARTITION OF ancestor FOR VALUES FROM ('20240401') TO ('20240501');");
stmt.execute("CREATE TABLE ancestor_p202405 PARTITION OF ancestor FOR VALUES FROM ('20240501') TO ('20240601');");
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
ResultSet rs = dbmd.getTables(con.getCatalog(), con.getSchema(), "ancestor%", new String[]{"ANCESTOR TABLE"});
assertTrue(rs.next());
assertEquals("ancestor", rs.getString("TABLE_NAME"));
rs.close();
} finally {
if (stmt != null) {
stmt.execute("DROP TABLE IF EXISTS ancestor");
stmt.close();
}
}
}

}

@MethodSource("data")
@ParameterizedTest(name = "binary = {0}")
void identityColumns(BinaryMode binaryMode) throws SQLException {
Expand Down