xtern commented on code in PR #5203:
URL: https://github.com/apache/ignite-3/pull/5203#discussion_r1954241504
##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogSchemaTest.java:
##########
@@ -170,6 +176,138 @@ public void testDropNonEmpty() {
}
}
+ @Test
+ public void testSameTableNameInDifferentSchemas() {
+ // Create table1 in schema1
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S1").build();
+ CatalogCommand newTableCmd = newTableCommand("S1", "T1");
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd), true,
true);
+ }
+
+ // Create table1 in schema2
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S2").build();
+ CatalogCommand newTableCmd = newTableCommand("S2", "T1");
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd), true,
true);
+ }
+
+ {
+ CatalogSchemaDescriptor schema1 = latestCatalog().schema("S1");
+ assertNotNull(schema1);
+
+ CatalogSchemaDescriptor schema2 = latestCatalog().schema("S2");
+ assertNotNull(schema2);
+
+ CatalogTableDescriptor schema1table1 = schema1.table("T1");
+ assertNotNull(schema1table1);
+
+ CatalogTableDescriptor schema2table1 = schema2.table("T1");
+ assertNotNull(schema2table1);
+ assertNotEquals(schema1table1.id(), schema2table1.id(), "Table ids
should differ");
+ }
+ }
+
+ @Test
+ public void testSameIndexNameInDifferentSchemas() {
+ // Create table1 in schema1
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S1").build();
+ CatalogCommand newTableCmd = newTableCommand("S1", "T1");
+ CatalogCommand newIndexCmd = CreateHashIndexCommand.builder()
+ .schemaName("S1")
+ .tableName("T1")
+ .indexName("MY_INDEX")
+ .columns(List.of("key2"))
+ .build();
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd,
newIndexCmd), true, true, true);
+ }
+
+ // Create table1 in schema2
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S2").build();
+ CatalogCommand newTableCmd = newTableCommand("S2", "T2");
+ CatalogCommand newIndexCmd = CreateHashIndexCommand.builder()
+ .schemaName("S2")
+ .tableName("T2")
+ .indexName("MY_INDEX")
+ .columns(List.of("key2"))
+ .build();
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd,
newIndexCmd), true, true, true);
+ }
+
+ {
+ CatalogSchemaDescriptor schema1 = latestCatalog().schema("S1");
+ assertNotNull(schema1);
+
+ CatalogSchemaDescriptor schema2 = latestCatalog().schema("S2");
+ assertNotNull(schema2);
+
+ CatalogIndexDescriptor schema1index =
Arrays.stream(schema1.indexes())
+ .filter(i -> "MY_INDEX".equals(i.name()))
+ .findAny()
+ .orElseThrow();
+
+ CatalogIndexDescriptor schema2index =
Arrays.stream(schema2.indexes())
+ .filter(i -> "MY_INDEX".equals(i.name()))
+ .findAny()
+ .orElseThrow();
+
+ assertNotEquals(schema1index.id(), schema2index.id(), "Index ids
should differ");
+ }
+ }
+
+ @Test
+ public void testEmptyPublicSchema() {
Review Comment:
There is already present `testDropDefaultSchemaIsAllowed`.
I guess it can be removed, but the current test should not use the
hard-coded name "PUBLIC" (use a constant instead), and I suggest renaming this
test t accordingly (`testDropCreateEmptyDefaultSchema`)
And may be add similar check here
```
assertThat(latestCatalog().schema(SqlCommon.DEFAULT_SCHEMA_NAME),
nullValue());
```
##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogSchemaTest.java:
##########
@@ -170,6 +176,138 @@ public void testDropNonEmpty() {
}
}
+ @Test
+ public void testSameTableNameInDifferentSchemas() {
+ // Create table1 in schema1
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S1").build();
+ CatalogCommand newTableCmd = newTableCommand("S1", "T1");
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd), true,
true);
+ }
+
+ // Create table1 in schema2
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S2").build();
+ CatalogCommand newTableCmd = newTableCommand("S2", "T1");
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd), true,
true);
+ }
+
+ {
+ CatalogSchemaDescriptor schema1 = latestCatalog().schema("S1");
+ assertNotNull(schema1);
+
+ CatalogSchemaDescriptor schema2 = latestCatalog().schema("S2");
+ assertNotNull(schema2);
+
+ CatalogTableDescriptor schema1table1 = schema1.table("T1");
+ assertNotNull(schema1table1);
+
+ CatalogTableDescriptor schema2table1 = schema2.table("T1");
+ assertNotNull(schema2table1);
+ assertNotEquals(schema1table1.id(), schema2table1.id(), "Table ids
should differ");
+ }
+ }
+
+ @Test
+ public void testSameIndexNameInDifferentSchemas() {
+ // Create table1 in schema1
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S1").build();
+ CatalogCommand newTableCmd = newTableCommand("S1", "T1");
+ CatalogCommand newIndexCmd = CreateHashIndexCommand.builder()
+ .schemaName("S1")
+ .tableName("T1")
+ .indexName("MY_INDEX")
+ .columns(List.of("key2"))
+ .build();
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd,
newIndexCmd), true, true, true);
+ }
+
+ // Create table1 in schema2
+ {
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("S2").build();
+ CatalogCommand newTableCmd = newTableCommand("S2", "T2");
+ CatalogCommand newIndexCmd = CreateHashIndexCommand.builder()
+ .schemaName("S2")
+ .tableName("T2")
+ .indexName("MY_INDEX")
+ .columns(List.of("key2"))
+ .build();
+
+ tryApplyAndCheckExpect(List.of(newSchemaCmd, newTableCmd,
newIndexCmd), true, true, true);
+ }
+
+ {
+ CatalogSchemaDescriptor schema1 = latestCatalog().schema("S1");
+ assertNotNull(schema1);
+
+ CatalogSchemaDescriptor schema2 = latestCatalog().schema("S2");
+ assertNotNull(schema2);
+
+ CatalogIndexDescriptor schema1index =
Arrays.stream(schema1.indexes())
+ .filter(i -> "MY_INDEX".equals(i.name()))
+ .findAny()
+ .orElseThrow();
+
+ CatalogIndexDescriptor schema2index =
Arrays.stream(schema2.indexes())
+ .filter(i -> "MY_INDEX".equals(i.name()))
+ .findAny()
+ .orElseThrow();
+
+ assertNotEquals(schema1index.id(), schema2index.id(), "Index ids
should differ");
+ }
+ }
+
+ @Test
+ public void testEmptyPublicSchema() {
+ CatalogSchemaDescriptor publicSchema1 =
latestCatalog().schema("PUBLIC");
+ assertNotNull(publicSchema1);
+
+ // Drop public schema
+ CatalogCommand dropSchemaCmd =
DropSchemaCommand.builder().name("PUBLIC").build();
+ tryApplyAndExpectApplied(dropSchemaCmd);
+ assertNull(latestCatalog().schema("PUBLIC"));
+
+ // Create public schema
+ CatalogCommand newSchemaCmd =
CreateSchemaCommand.builder().name("PUBLIC").build();
+ tryApplyAndExpectApplied(newSchemaCmd);
+
+ CatalogSchemaDescriptor publicSchema2 =
latestCatalog().schema("PUBLIC");
+ assertNotNull(publicSchema2);
+ assertNotEquals(publicSchema1.id(), publicSchema2.id());
+ }
+
+ @Test
+ public void testNonEmptyPublicSchema() {
Review Comment:
:thinking: I'm not sure we need specific test for this.
We already have `testDropNonEmpty` what is the difference?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]