Skip to content

Commit

Permalink
[apache#2086] Improvement(test) : Add wildcard test logic for schema-…
Browse files Browse the repository at this point in the history
…related scenarios.. (apache#2293)

### What changes were proposed in this pull request?

Add wildcard test logic for schema-related scenarios

### Why are the changes needed?
Fix: apache#2086 

### Does this PR introduce _any_ user-facing change?
NO

### How was this patch tested?
IT

Co-authored-by: Clearvive <[email protected]>
  • Loading branch information
Clearvive and Clearvive authored Feb 23, 2024
1 parent 15e8a4e commit 29b462c
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1225,4 +1225,68 @@ void testMySQLTableNameCaseSensitive() {
assertionsTableInfo(
"TABLENAME", table_comment, Arrays.asList(newColumns), properties, indexes, table);
}

@Test
void testMySQLSchemaNameCaseSensitive() {
Column col1 = Column.of("col_1", Types.LongType.get(), "id", false, false, null);
Column col2 = Column.of("col_2", Types.VarCharType.of(255), "code", false, false, null);
Column col3 = Column.of("col_3", Types.VarCharType.of(255), "config", false, false, null);
Column[] newColumns = new Column[] {col1, col2, col3};

Index[] indexes = new Index[] {Indexes.unique("u1_key", new String[][] {{"col_2"}, {"col_3"}})};

String[] schemas = {"db_", "db_1", "db_2", "db12"};
SupportsSchemas schemaSupport = catalog.asSchemas();

for (String schema : schemas) {
NameIdentifier schemaIdentifier = NameIdentifier.of(metalakeName, catalogName, schema);
schemaSupport.createSchema(schemaIdentifier, null, Collections.emptyMap());
Assertions.assertNotNull(schemaSupport.loadSchema(schemaIdentifier));
}

Set<String> schemaNames =
Arrays.stream(schemaSupport.listSchemas(Namespace.of(metalakeName, catalogName)))
.map(NameIdentifier::name)
.collect(Collectors.toSet());

Assertions.assertTrue(schemaNames.containsAll(Arrays.asList(schemas)));

String tableName = "test1";
Map<String, String> properties = createProperties();
TableCatalog tableCatalog = catalog.asTableCatalog();

for (String schema : schemas) {
tableCatalog.createTable(
NameIdentifier.of(metalakeName, catalogName, schema, tableName),
newColumns,
table_comment,
properties,
Transforms.EMPTY_TRANSFORM,
Distributions.NONE,
new SortOrder[0],
indexes);
tableCatalog.createTable(
NameIdentifier.of(
metalakeName, catalogName, schema, GravitinoITUtils.genRandomName("test2")),
newColumns,
table_comment,
properties,
Transforms.EMPTY_TRANSFORM,
Distributions.NONE,
new SortOrder[0],
Indexes.EMPTY_INDEXES);
}

for (String schema : schemas) {
NameIdentifier[] nameIdentifiers =
tableCatalog.listTables(Namespace.of(metalakeName, catalogName, schema));
Assertions.assertEquals(2, nameIdentifiers.length);
Assertions.assertTrue(
Arrays.stream(nameIdentifiers)
.map(NameIdentifier::name)
.collect(Collectors.toSet())
.stream()
.anyMatch(n -> n.equals(tableName)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1117,4 +1117,68 @@ void testPGListTable() {
Assertions.assertEquals(tables[i], tableNames[0].name());
}
}

@Test
void testPostgreSQLSchemaNameCaseSensitive() {
Column col1 = Column.of("col_1", Types.LongType.get(), "id", false, false, null);
Column col2 = Column.of("col_2", Types.VarCharType.of(255), "code", false, false, null);
Column col3 = Column.of("col_3", Types.VarCharType.of(255), "config", false, false, null);
Column[] newColumns = new Column[] {col1, col2, col3};

Index[] indexes = new Index[] {Indexes.unique("u1_key", new String[][] {{"col_2"}, {"col_3"}})};

String[] schemas = {"db_", "db_1", "db_2", "db12"};
SupportsSchemas schemaSupport = catalog.asSchemas();

for (String schema : schemas) {
NameIdentifier schemaIdentifier = NameIdentifier.of(metalakeName, catalogName, schema);
schemaSupport.createSchema(schemaIdentifier, null, Collections.emptyMap());
Assertions.assertNotNull(schemaSupport.loadSchema(schemaIdentifier));
}

Set<String> schemaNames =
Arrays.stream(schemaSupport.listSchemas(Namespace.of(metalakeName, catalogName)))
.map(NameIdentifier::name)
.collect(Collectors.toSet());

Assertions.assertTrue(schemaNames.containsAll(Arrays.asList(schemas)));

String tableName = "test1";
Map<String, String> properties = createProperties();
TableCatalog tableCatalog = catalog.asTableCatalog();

for (String schema : schemas) {
tableCatalog.createTable(
NameIdentifier.of(metalakeName, catalogName, schema, tableName),
newColumns,
table_comment,
properties,
Transforms.EMPTY_TRANSFORM,
Distributions.NONE,
new SortOrder[0],
indexes);
tableCatalog.createTable(
NameIdentifier.of(
metalakeName, catalogName, schema, GravitinoITUtils.genRandomName("test2")),
newColumns,
table_comment,
properties,
Transforms.EMPTY_TRANSFORM,
Distributions.NONE,
new SortOrder[0],
Indexes.EMPTY_INDEXES);
}

for (String schema : schemas) {
NameIdentifier[] nameIdentifiers =
tableCatalog.listTables(Namespace.of(metalakeName, catalogName, schema));
Assertions.assertEquals(2, nameIdentifiers.length);
Assertions.assertTrue(
Arrays.stream(nameIdentifiers)
.map(NameIdentifier::name)
.collect(Collectors.toSet())
.stream()
.anyMatch(n -> n.equals(tableName)));
}
}
}

0 comments on commit 29b462c

Please sign in to comment.