|
28 | 28 | import org.apache.iceberg.Table; |
29 | 29 | import org.apache.iceberg.catalog.Catalog; |
30 | 30 | import org.apache.iceberg.catalog.Namespace; |
| 31 | +import org.apache.iceberg.catalog.SupportsNamespaces; |
31 | 32 | import org.apache.iceberg.catalog.TableIdentifier; |
32 | 33 | import org.apache.iceberg.flink.sink.TestFlinkIcebergSinkBase; |
33 | 34 | import org.apache.iceberg.inmemory.InMemoryCatalog; |
@@ -211,4 +212,50 @@ void testDropUnusedColumns() { |
211 | 212 | assertThat(tableSchema.findField("data")).isNotNull(); |
212 | 213 | assertThat(tableSchema.findField("extra")).isNull(); |
213 | 214 | } |
| 215 | + |
| 216 | + @Test |
| 217 | + void testNamespaceAndTableCreation() { |
| 218 | + Catalog catalog = CATALOG_EXTENSION.catalog(); |
| 219 | + SupportsNamespaces namespaceCatalog = (SupportsNamespaces) catalog; |
| 220 | + TableIdentifier tableIdentifier = TableIdentifier.of("new_namespace", "myTable"); |
| 221 | + TableMetadataCache cache = new TableMetadataCache(catalog, 10, Long.MAX_VALUE, 10); |
| 222 | + TableUpdater tableUpdater = new TableUpdater(cache, catalog, false); |
| 223 | + |
| 224 | + assertThat(namespaceCatalog.namespaceExists(Namespace.of("new_namespace"))).isFalse(); |
| 225 | + assertThat(catalog.tableExists(tableIdentifier)).isFalse(); |
| 226 | + |
| 227 | + Tuple2<TableMetadataCache.ResolvedSchemaInfo, PartitionSpec> result = |
| 228 | + tableUpdater.update( |
| 229 | + tableIdentifier, "main", SCHEMA, PartitionSpec.unpartitioned(), TableCreator.DEFAULT); |
| 230 | + |
| 231 | + assertThat(namespaceCatalog.namespaceExists(Namespace.of("new_namespace"))).isTrue(); |
| 232 | + |
| 233 | + assertThat(catalog.tableExists(tableIdentifier)).isTrue(); |
| 234 | + assertThat(result.f0.resolvedTableSchema().sameSchema(SCHEMA)).isTrue(); |
| 235 | + assertThat(result.f0.compareResult()).isEqualTo(CompareSchemasVisitor.Result.SAME); |
| 236 | + } |
| 237 | + |
| 238 | + @Test |
| 239 | + void testTableCreationWithExistingNamespace() { |
| 240 | + Catalog catalog = CATALOG_EXTENSION.catalog(); |
| 241 | + SupportsNamespaces namespaceCatalog = (SupportsNamespaces) catalog; |
| 242 | + Namespace namespace = Namespace.of("existing_namespace"); |
| 243 | + namespaceCatalog.createNamespace(namespace); |
| 244 | + |
| 245 | + TableIdentifier tableIdentifier = TableIdentifier.of("existing_namespace", "myTable"); |
| 246 | + TableMetadataCache cache = new TableMetadataCache(catalog, 10, Long.MAX_VALUE, 10); |
| 247 | + TableUpdater tableUpdater = new TableUpdater(cache, catalog, false); |
| 248 | + |
| 249 | + assertThat(namespaceCatalog.namespaceExists(namespace)).isTrue(); |
| 250 | + assertThat(catalog.tableExists(tableIdentifier)).isFalse(); |
| 251 | + |
| 252 | + Tuple2<TableMetadataCache.ResolvedSchemaInfo, PartitionSpec> result = |
| 253 | + tableUpdater.update( |
| 254 | + tableIdentifier, "main", SCHEMA, PartitionSpec.unpartitioned(), TableCreator.DEFAULT); |
| 255 | + |
| 256 | + assertThat(namespaceCatalog.namespaceExists(namespace)).isTrue(); |
| 257 | + assertThat(catalog.tableExists(tableIdentifier)).isTrue(); |
| 258 | + assertThat(result.f0.resolvedTableSchema().sameSchema(SCHEMA)).isTrue(); |
| 259 | + assertThat(result.f0.compareResult()).isEqualTo(CompareSchemasVisitor.Result.SAME); |
| 260 | + } |
214 | 261 | } |
0 commit comments